Note
The Chinese and English guides cover the same model capabilities and main workflows. Sample inputs, prompts, output fields, and validation details may differ; follow the code in the guide you are reading. The companion Python scripts and Notebooks follow the Chinese guide.
1. Understand the model and reasoning effort
Step 5 Preview is a multimodal model that accepts text, image, and video inputs and generates text. Applications provide messages, source material, and tools through the API for the model to interpret, reason over, and answer. Model overview
Reasoning effort is the level of reasoning computation you select for a task. Configure it with reasoning_effort in the Chat Completions API. It is separate from controls for response length and writing style. Choose a level by considering answer quality, waiting time, and token usage together. Reasoning parameters
This guide is for developers familiar with Python functions and JSON. You will start with one text request, then compare low, medium, and high while keeping the input and output requirements fixed. You can reuse the request function and comparison method with your own task set.
Workflow: Configure the client → Run a baseline request → Adjust reasoning effort → Read timing and usage → Replace the task.
2. Prerequisites and setup
2.1 Prerequisites
Required knowledge: Familiarity with Python functions, dictionaries, and JSON.
- Python 3.10 or later.
- A StepFun API key with access to step-5-preview.
2.2 Create a Python environment
For an existing project, you can use its current virtual environment. For a new project, create an environment in any working directory. Run the following in a macOS or Linux terminal:
In Windows PowerShell, run:
After activation, confirm the Python version with the following command. All subsequent python commands refer to this environment’s interpreter.
2.3 Dependencies
This example uses only the Python standard library.
2.4 Configure credentials and run the example
Set STEP_API_KEY in the terminal that will run the example. Replace YOUR_STEP_API_KEY with your API key.
macOS / Linux:
Windows PowerShell:
Run the Python commands below in the same terminal. For a Notebook, start Jupyter from that terminal so its kernel inherits the variable. If the variable is unset, the code prompts for the key with input hidden.
Set REGION = "cn" for the China region, which uses .com endpoints, or "global" for the international region, which uses .ai endpoints. Use a key issued for the selected region.
Create reasoning_demo.py in your project and copy this guide's Python code blocks into that file in order. Run the bash and powershell blocks only in a terminal. After adding the definitions and calls, run:
2.5 Initialize the connection and credentials
BASE_URLS stores the regional endpoints, and REGION selects the endpoint for this run. get_key() prompts only when the environment variable is missing, which suits terminal use. A service can read the key directly from its deployment environment.
2.6 Set the HTTP timeout and read responses
The following post() function is the shared request helper for this guide. HTTP_TIMEOUT_SECONDS is a client setting that limits the wait for a network operation; configure it separately from reasoning effort or output length. The function returns the response bytes, the elapsed time through the end of the response read, and the content type.
chat() parses a chat response into a dictionary, response_record() extracts the final content and usage, and save_json() saves the results. In an existing project, these can form part of your response-handling layer. They do not change the capability parameters sent to the model.
3. Make a minimal request
3.1 Prepare inputs and reference answers
The three inputs cover filtered summation, ordering under constraints, and set counting. The reference answer is used only for local checks and is not sent to the model. Each final response must be a JSON object containing only the answer field, so the program can read it consistently.
3.2 Configure request parameters and result handling
First define the parameters sent to the model, then implement local result handling. Keep them separate so either part can be replaced independently in your project.
Parameter group: reasoning effort and output budget. effort supplies reasoning_effort, and max_tokens sets the output limit. response_format is fixed to a JSON object, and the prompt specifies an answer field to support the comparison.
Keep max_tokens fixed when comparing effort levels. To study the output budget, run a separate comparison that changes only that limit. Use the response's finish_reason to determine whether generation completed normally.
Result handling. The following code checks the answer and records usage without adding model parameters. The reference value for answer stays local.
Inspect content, success, elapsed_seconds, and usage in the output. The reference result for this summation task is {"answer": 56}. A true success value means the final response completed normally and meets the specified field and answer requirements. The elapsed time runs from sending the HTTP request through reading the full response.
4. Compare three reasoning effort levels
reasoning_effort accepts low, medium, and high; see the Step 5 Preview model documentation. This comparison holds the model, inputs, prompt requirements, output format, and output limit constant and changes only reasoning effort.
With REPEATS = 1, the following code sends nine additional requests. This is enough to learn the workflow. To observe variability, increase the number of repetitions on your own task set. A fixed random seed shuffles the request order so that requests for one level are not all concentrated at the end of the experiment.
5. Interpret the results and choose a configuration
Start with the number of completed runs at each level, then consider answer quality, elapsed time, and usage together. These measurements describe performance on this input set only. For a project decision, use a representative task set and retain the underlying counts. If total_tokens is absent, record it as missing rather than zero.
First identify the levels that meet your quality requirements, then compare their latency and usage. Increasing reasoning effort does not guarantee greater accuracy or lower latency for every input. This guide fixes max_tokens at 4096. Test changes to that value separately and check finish_reason for normal completion.
Full-response time includes network and server processing time. This example does not measure time to first token. Estimate cost separately using the official pricing applicable on the request date, and retain usage fields for traceability.
6. Use your own tasks
Start with a small change: replace 12 with 14 in the first question, which changes the reference answer to 58. The following code runs that new input with the same request and checking methods.
To use project-specific tasks, update the inputs and reference answers in SAMPLES. If the target output is no longer a single-field JSON object, update both the prompt requirements and grade(). Run one input first, then compare effort levels, and choose a configuration against your quality and response-time requirements. The reusable outputs are the request, recording, and comparison methods, along with the result files produced by your run.
7. Companion code and starter project
This example includes a Jupyter Notebook, an editable Python script, and a starter project for running and adapting the code. Browse the example directory for all files, or see the setup and launch guide for instructions.
To use the launchers, obtain the complete example directory from the current repository and keep its relative paths intact. Initial setup requires an internet connection. The supplied Notebook, Python script, launch menu, and setup guide currently follow the Chinese version. To reproduce this guide's English prompts, sample inputs, and result fields, use the Python code blocks in this guide.
