> ## Documentation Index
> Fetch the complete documentation index at: https://platform.stepfun.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat Completions API

Call the Chat Completions API to get the model-generated chat response data.

## Endpoint

`POST https://api.stepfun.ai/v1/chat/completions`

## Request Parameters

* `model` `string` ***required***<br />Name of the model to use

* `messages` `object array` ***required***<br />List of different categories of messages entered by the user or generated by the model so far
  <Expandable>
    * System message `object`
        <Expandable>
          * `role` `string`<br />Role name for system messages, always `system`
          * `content` `string`<br />Text content of the system message
        </Expandable>
    * User message `object`
        <Expandable>
          * `role` `string`<br />Role name for user messages, always `user`
          * `content` `string or object array`<br />User message content, either a `multipart` message list or a plain text message string
                <Expandable>
                  * Plain text message `string`
                  * `multipart` message list `object array`<br />Structured list of mixed image, video, audio, and text messages
                          <Expandable>
                            * Text message `object`
                                      <Expandable>
                                        * `type` `string`<br />Always `text`
                                        * `text` `string`<br />Message text content
                                      </Expandable>
                            * Image message `object`
                                      <Expandable>
                                        * `type` `string`<br />Always `image_url`
                                        * `image_url` `object`
                                                    <Expandable>
                                                      * `url` `string`<br />Image URL or base64-encoded image. Supported formats: jpg/jpeg, png, webp, static gif; only http and https are allowed.<br /> Example base64 format: `data:image/jpeg;base64,${base64_string}`. Replace the image format (jpeg) and the corresponding base64 string as needed.
                                                      * `detail` `string` ***optional***<br />Whether to enable detail mode: choose `low`/`high`, default is `low`.
                                                        <p> `low` mode scales the image to a fixed size with a token count around 400.<br />`high` mode provides more detailed and richer information. It performs better on large images, OCR, or extreme aspect ratios. Token count varies by the image.</p>
                                                    </Expandable>
                                      </Expandable>
                            * Video message `object`
                                      <Expandable>
                                        * `type` `string`<br />Always `video_url`
                                        * `video_url` `object`
                                                    <Expandable>
                                                      * `url` `string`<br />URL of the video. Format: video/mp4; only http and https are supported. Video must be under 128 MB and the duration is recommended to be under 5 minutes.
                                                    </Expandable>
                                      </Expandable>
                            * Audio message `object`
                                      <Expandable>
                                        * `type` `string`<br />Always `input_audio`
                                        * `input_audio` `object`
                                                    <Expandable>
                                                      * `data` `string`<br />Audio content, provided as a base64-encoded audio file.<br />Example base64 format: `data:audio/mpeg;base64,${base64_string}`. Replace the audio format (currently only mp3 and wav are supported) and its corresponding base64 string.
                                                    </Expandable>
                                      </Expandable>
                          </Expandable>
                </Expandable>
        </Expandable>
    * Tool function message `object`
        <Expandable>
          * `role` `string`<br />Role name for tool messages, always `tool`
          * `content` `string`<br />Content returned after executing the function
          * `tool_call_id` `string`<br />ID of the executed function, returned by the assistant in the previous turn.
        </Expandable>
    * Chat assistant message `object`
        <Expandable>
          * `role` `string`<br />Role name for assistant messages, always `assistant`
          * `content` `string | null`<br />Text content of the assistant message
        </Expandable>
  </Expandable>

* `tools` `object array` ***optional***<br />List of functions supported for Toolcall
  <Expandable>
    * `type` `string`<br />Tool type, always `function`
    * `function` `object`<br />Description of the function
        <Expandable>
          * `name` `string`<br />Function name. Only English letters, numbers, and \_- are allowed; recommended to keep it under 64 characters.
          * `description` `string`<br />Function description, supports Chinese and English. It tells the model what the function does so the model can judge and choose.
          * `parameters` `object`<br />Parameters of the function
                <Expandable>
                  * `type` `object`<br />Parameter description, usually object
                  * `properties` `object`<br />Function parameter definitions, with the key as the parameter name, and `type` and `description` describing the type and details.
                          <Expandable>
                            * `type` `string|number|integer|object|array|boolean`<br />Parameter type. See [json-schema](https://json-schema.org/understanding-json-schema/reference/type) for reference.
                            * `description` `string`<br />Parameter description, supports Chinese and English. It tells the model what each parameter means.
                          </Expandable>
                </Expandable>
        </Expandable>
  </Expandable>

* `max_tokens` `int` ***optional***<br />Maximum number of `tokens` to generate for the chat. Default is INF (no limit, determined automatically by the model). The total of input and generated `tokens` is limited by the specified model's maximum context length.

* `temperature` `float` ***optional***<br />Sampling temperature, a number between 0.0 and 2.0. Higher values (e.g., 0.8) make the output more random; lower values (e.g., 0.2) make it more focused and deterministic. Default is 0.5.

* `top_p` `float` ***optional***<br />Top-p sampling. The model generates `tokens` within the probability mass of top\_p and outputs them. Default is 0.9.

* `n` `int` ***optional***<br />Controls how many response messages the model generates for each input message. Default is 1; no hard max, but suggested up to 5.

* `stream` `bool` ***optional***<br />Whether to stream the response messages. Default is false.

* `stop` `string | string array` ***optional***<br />Stops generation when encountering any of the stop content. Empty by default.

* `frequency_penalty` `float` ***optional***<br />Default is 0. A number between 0.0 and 1.0. Higher values penalize tokens that have appeared frequently in the generated text, reducing repetition.

* `response_format` `object` ***optional***<br />Used to instruct the model to output in a specific format. Default is `{"type":"text"}`, meaning text output. Set `{ "type": "json_object" }` to [turn on JSON Mode](/en/guides/developer/json-mode) and output parseable JSON.

* `reasoning_format` `string` ***optional***<br />Used to instruct the model which reasoning field to use when outputting; default is `general`, meaning general reasoning that returns a `reasoning` field. Options are \[`general`,`deepseek-style`]. When set to `deepseek-style`, you can use the DeepSeek-compatible `reasoning_content` field to obtain the reasoning content.

* `reasoning_effort` `string` ***optional***<br />Controls how much reasoning the model performs. Models that support three reasoning tiers accept `low`, `medium`, `high`; `step-3.5-flash-2603` accepts `low` and `high` only. Higher values produce deeper reasoning but may take longer to respond.

## Response format

### Non-streaming response

When `stream=false` (default), the API returns a single Chat Completion object.

#### Attributes

* `id` `string`
  <br />
  Chat response ID.
* `object` `string`
  <br />
  Response object type, always `chat.completion`.
* `model` `string`
  <br />
  Model name.
* `created` `timestamp`
  <br />
  Unix timestamp (seconds) when the response was generated.
* `choices` `object array`

  <br />

  List of response choices.

  <Expandable>
    * `finish_reason` `string`<br />Why generation stopped.
    * `index` `int` <br /> Choice index.
    * `message` `object` <br /> Actual message content.

    <Expandable>
      - `role` `string`<br />Message role, always `assistant`.
      - `content` `string`<br />Message text.
      - `reasoning` `string`<br />Reasoning content (only for step reasoning models).
      - `tool_calls` `object array` ***optional***<br />Toolcall results.

      <Expandable>
        * `id` `string`<br />Function call ID generated by the model; unique in context.
        * `type` `string`<br />Toolcall type, always `function`.
        * `function` `object`<br />Function payload.

        <Expandable>
          - `name` `string` <br /> Function name, typically one from the tools list of the previous turn.
          - `arguments` `string` <br /> Function arguments as a JSON string.
        </Expandable>
      </Expandable>
    </Expandable>
  </Expandable>
* `usage` `object`
  <br />
  Token usage statistics.
  <Expandable>
    * `prompt_tokens` `int` <br /> Prompt tokens used.
    * `cached_tokens` `int` ***optional*** <br /> Prompt tokens served from cache.
    * `completion_tokens` `int` <br /> Completion tokens generated.
    * `total_tokens` `int`<br />Total tokens.
  </Expandable>

#### Example

```json theme={null}
{
  "id": "b7b56af0-52a6-483f-a589-948182676a1b",
  "object": "chat.completion",
  "created": 1709893411,
  "model": "step-3.5-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! StepFun specializes in artificial intelligence and provides AI solutions across NLP, computer vision, and machine learning to help customers improve efficiency and create value across industries."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": { "prompt_tokens": 83, "completion_tokens": 176, "total_tokens": 259 }
}
```

### Streaming response

When `stream=true`, the API streams a series of `chat.completion.chunk` events.

#### Attributes

* `id` `string`
  <br />
  Generated chat response ID.
* `object` `string`
  <br />
  Response object type, always `chat.completion.chunk`.
* `created` `timestamp`
  <br />
  Unix timestamp (seconds) when the chunk was generated.
* `model` `string`
  <br />
  Model name.
* `choices` `object array`

  <br />

  List of streamed response alternatives. Each `choice` object:

  <Expandable>
    * `finish_reason` `string`<br />Why generation stopped.
    * `index` `int`<br />Choice index.
    * `delta` object<br />Incremental response chunk.

    <Expandable>
      - `role` `string`<br />Message role, always `assistant`.
      - `content` `string`<br />Message text content.
      - `reasoning` `string`<br />Reasoning content (only for step reasoning models).
      - `tool_calls` `object array` ***optional***<br />Toolcall content.

      <Expandable>
        * `id` `string`<br />Function call ID generated by the model; unique in context.
        * `type` `string`<br />Toolcall type, always `function`.
        * `function` `object`<br />Function payload.

        <Expandable>
          - `name` `string` <br /> Function name, usually the name provided in the previous turn's tools list.
          - `arguments` `string` <br /> Function arguments as a JSON string.
        </Expandable>
      </Expandable>
    </Expandable>
  </Expandable>
* `usage` `object`
  <br />
  Token usage statistics.
  <Expandable>
    * `prompt_tokens` `int`<br />Prompt tokens used.
    * `cached_tokens` `int` ***optional***<br />Prompt tokens served from cache.
    * `completion_tokens` `int`<br />Completion tokens generated.
    * `total_tokens` `int`<br />Total tokens.
  </Expandable>

#### Example

```text theme={null}
data: {"id":"d7ae7c4a-1524-4fe5-9d58-e4d59b89d8f0","object":"chat.completion.chunk","created":1709899323,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":"Hello"},"finish_reason":""}],"usage":{"prompt_tokens":83,"completion_tokens":1,"total_tokens":84}}

...

data: {"id":"d7ae7c4a-1524-4fe5-9d58-e4d59b89d8f0","object":"chat.completion.chunk","created":1709899323,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":"value"},"finish_reason":""}],"usage":{"prompt_tokens":83,"completion_tokens":148,"total_tokens":231}}

data: {"id":"d7ae7c4a-1524-4fe5-9d58-e4d59b89d8f0","object":"chat.completion.chunk","created":1709899323,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":""},"finish_reason":"stop"}],"usage":{"prompt_tokens":83,"completion_tokens":150,"total_tokens":233}}

data: [DONE]
```

## Examples

> Note: The basic examples below use `step-3.5-flash` by default. To use the three reasoning tiers, see the `step-3.7-flash` call in the "Reasoning Effort" example.

<Tabs>
  <Tab title="Reasoning Effort">
    ```bash theme={null}
    curl https://api.stepfun.ai/v1/chat/completions \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $STEP_API_KEY" \
      -d '{
        "model": "step-3.7-flash",
        "messages": [
          {
            "role": "user",
            "content": "Explain what reinforcement learning is in three sentences."
          }
        ],
        "reasoning_effort": "medium",
        "max_tokens": 1024
      }'
    ```
  </Tab>

  <Tab title="Text Chat">
    <Tabs>
      <Tab title="python">
        ```python theme={null}
        from openai import OpenAI

        client = OpenAI(api_key="STEP_API_KEY", base_url="https://api.stepfun.ai/v1")

        completion = client.chat.completions.create(
            model="step-3.5-flash",
            messages=[
                {
                    "role": "system",
                    "content": "You are an AI chat assistant provided by StepFun. You are good at Chinese, English, and many other languages. While keeping user data safe, you can respond quickly and accurately to users' questions and requests. Your answers and suggestions should reject content related to pornography, gambling, drugs, violence, or terrorism.",
                },
                {
                    "role": "user",
                    "content": "Hello, please introduce StepFun's artificial intelligence!"
                },
            ],
        )

        print(completion)
        ```
      </Tab>

      <Tab title="js">
        ```js theme={null}
        import OpenAI from "openai";

        const openai = new OpenAI({
            apiKey: "STEP_API_KEY",
            baseURL: "https://api.stepfun.ai/v1"
        });

        async function main() {
            const completion = await openai.chat.completions.create({
                model: "step-3.5-flash",
                messages: [
                    {
                        role: "system",
                        content: "You are an AI chat assistant provided by StepFun. You are good at Chinese, English, and many other languages. While keeping user data safe, you can respond quickly and accurately to users' questions and requests. Your answers and suggestions should reject content related to pornography, gambling, drugs, violence, or terrorism."
                    },
                    {
                        role: "user",
                        content: "Hello, please introduce StepFun's artificial intelligence!"
                    }
                ]
            });

            console.log(JSON.stringify(completion));
        }

        main();
        ```
      </Tab>

      <Tab title="curl">
        ```bash theme={null}
        curl https://api.stepfun.ai/v1/chat/completions \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer $STEP_API_KEY" \
          -d '{
            "model": "step-3.5-flash",
            "messages": [
              {
                "role": "system",
                "content": "You are an AI chat assistant provided by StepFun. You are good at Chinese, English, and many other languages. While keeping user data safe, you can respond quickly and accurately to users'\'' questions and requests. Your answers and suggestions should reject content related to pornography, gambling, drugs, violence, or terrorism."
              },
              {
                "role": "user",
                "content": "Hello, please introduce StepFun'\''s artificial intelligence!"
              }
            ]
          }'
        ```
      </Tab>
    </Tabs>

    ```json filename="Response" theme={null}
    {
      "id": "b7b56af0-52a6-483f-a589-948182676a1b",
      "object": "chat.completion",
      "created": 1709893411,
      "model": "step-3.5-flash",
      "choices": [
        {
          "index": 0,
          "message": {
            "role": "assistant",
            "content": "Hello! StepFun is a company focused on artificial intelligence technology and is dedicated to developing and providing various AI solutions. Our AI capabilities cover natural language processing, computer vision, and machine learning to help users in many industries improve efficiency and create value.\n\nWe provide a variety of AI products and services, including intelligent customer service, virtual assistants, smart recommendations, and intelligent moderation. These products and services can be applied across industries such as finance, retail, education, and healthcare. By using our AI, users can better understand and analyze data, deliver personalized services and experiences, and improve the efficiency and accuracy of their decisions.\n\nWe value the security and privacy of user data and strictly follow relevant laws, regulations, and industry standards. We believe AI technology should create more benefits for people rather than negative impacts. We will continue to work hard to provide smarter, more efficient, and safer AI solutions."
          },
          "finish_reason": "stop"
        }
      ],
      "usage": {
        "prompt_tokens": 83,
        "completion_tokens": 176,
        "total_tokens": 259
      }
    }
    ```
  </Tab>

  <Tab title="Image Understanding">
    <Tabs>
      <Tab title="python">
        ```python theme={null}
        from openai import OpenAI

        client = OpenAI(api_key="STEP_API_KEY", base_url="https://api.stepfun.ai/v1")

        completion = client.chat.completions.create(
            model="step-3.7-flash",
            messages=[
                {
                    "role": "system",
                    "content": "You are an AI chat assistant provided by StepFun. In addition to being good at Chinese, English, and many other languages, you can also describe the content of user-provided images accurately. While keeping user data safe, you can respond quickly and precisely to users' questions and requests. Your answers and suggestions should reject content related to pornography, gambling, drugs, violence, or terrorism.",
                },
                {
                    "role": "user",
                    "content": [
                        {
                            "type": "text",
                            "text": "Describe this image with elegant language",
                        },
                        {
                            "type": "image_url",
                            "image_url": {
                                "url": "https://www.stepfun.com/assets/section-1-CTe4nZiO.webp"
                            },
                        },
                    ],
                },
            ],
        )

        print(completion)
        ```
      </Tab>

      <Tab title="js">
        ```js theme={null}
        import OpenAI from "openai";

        const openai = new OpenAI({
            apiKey: "STEP_API_KEY",
            baseURL: "https://api.stepfun.ai/v1"
        });

        async function main() {
            const completion = await openai.chat.completions.create({
                model: "step-3.7-flash",
                messages: [
                    {
                        role: "system",
                        content: "You are an AI chat assistant provided by StepFun. In addition to being good at Chinese, English, and many other languages, you can also describe the content of user-provided images accurately. While keeping user data safe, you can respond quickly and precisely to users' questions and requests. Your answers and suggestions should reject content related to pornography, gambling, drugs, violence, or terrorism."
                    },
                    {
                        role: "user",
                        content: [
                            {
                                type: "text",
                                text: "Describe this image with elegant language"
                            },
                            {
                                type: "image_url",
                                image_url: {
                                    url: "https://www.stepfun.com/assets/section-1-CTe4nZiO.webp"
                                }
                            }
                        ]
                    }
                ]
            });

            console.log(JSON.stringify(completion));
        }

        main();
        ```
      </Tab>

      <Tab title="curl">
        ```bash theme={null}
        curl https://api.stepfun.ai/v1/chat/completions \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer $STEP_API_KEY" \
          -d '{
            "model": "step-3.7-flash",
            "messages": [
              {
                "role": "system",
                "content": "You are an AI chat assistant provided by StepFun. In addition to being good at Chinese, English, and many other languages, you can also describe the content of user-provided images accurately. While keeping user data safe, you can respond quickly and precisely to users'\'' questions and requests. Your answers and suggestions should reject content related to pornography, gambling, drugs, violence, or terrorism."
              },
              {
                "role": "user",
                "content": [
                  {
                    "type": "text",
                    "text": "Describe this image with elegant language"
                  },
                  {
                    "type": "image_url",
                    "image_url": {
                      "url": "https://www.stepfun.com/assets/section-1-CTe4nZiO.webp"
                    }
                  }
                ]
              }
            ]
          }'
        ```
      </Tab>
    </Tabs>

    ```json filename="Response" theme={null}
    {
      "id": "298ad5e6-033a-41f8-9801-43be6e106f22",
      "object": "chat.completion",
      "created": 1710145618,
      "model": "step-3.7-flash",
      "choices": [
        {
          "index": 0,
          "message": {
            "role": "assistant",
            "content": "In the soft light of dusk, a modern building comes into view with a striking red exterior that contrasts with its surroundings. The ground floor features spacious glass windows that fill the interior with natural light. A prominent sign stands on one side of the building, and the neatly arranged windows along the top showcase a modern design.\n\nIn the open area in front of the building, a bare tree sways gently in the breeze. The ground beneath is covered with gravel, adding a touch of nature to the space. On one side of the plaza, small lights cast a warm glow that feels especially cozy at twilight.\n\nThe area around the building is tidy, and the road is free of vehicles, giving a very peaceful feeling. In the distance, you can see the outlines of other buildings and the sun about to set, adding depth to the scene. The whole setting conveys a calm and orderly sense of urban life."
          },
          "finish_reason": "stop"
        }
      ],
      "usage": {
        "prompt_tokens": 497,
        "completion_tokens": 169,
        "total_tokens": 666
      }
    }
    ```
  </Tab>

  <Tab title="Base64 Encoded Image">
    <Tabs>
      <Tab title="python">
        ```python theme={null}
        # -*- coding: utf8 -*-

        import base64
        import requests
        from openai import OpenAI

        client = OpenAI(api_key="STEP_API_KEY", base_url="https://api.stepfun.ai/v1")

        # Load the image into memory for demo purposes only. Change as needed, e.g., read from a file.
        r = requests.get("https://www.stepfun.com/assets/section-1-CTe4nZiO.webp")
        r.raise_for_status()
        image_str = base64.b64encode(r.content).decode("ascii")

        completion = client.chat.completions.create(
            model="step-3.7-flash",
            messages=[
                {
                    "role": "system",
                    "content": "You are an AI chat assistant provided by StepFun. In addition to being good at Chinese, English, and many other languages, you can also describe the content of user-provided images accurately. While keeping user data safe, you can respond quickly and precisely to users' questions and requests. Your answers and suggestions should reject content related to pornography, gambling, drugs, violence, or terrorism.",
                },
                {
                    "role": "user",
                    "content": [
                        {
                            "type": "text",
                            "text": "Describe this image with elegant language",
                        },
                        {
                            "type": "image_url",
                            "image_url": {
                                "url": "data:image/webp;base64,%s" % (image_str),
                            },
                        },
                    ],
                },
            ],
        )

        print(completion)
        ```
      </Tab>

      <Tab title="js">
        ```js theme={null}
        import OpenAI from "openai";

        const openai = new OpenAI({
            apiKey: "STEP_API_KEY",
            baseURL: "https://api.stepfun.ai/v1"
        });

        // Load the image into memory for demo purposes only. Change as needed, e.g., read from a file.
        async function load_image(url) {
            let response = await fetch(url);
            let blob = await response.blob();
            let buffer = Buffer.from(await blob.arrayBuffer());
            return "data:" + blob.type + ";base64," + buffer.toString("base64");
        }

        async function main() {
            const completion = await openai.chat.completions.create({
                model: "step-3.7-flash",
                messages: [
                    {
                        role: "system",
                        content: "You are an AI chat assistant provided by StepFun. In addition to being good at Chinese, English, and many other languages, you can also describe the content of user-provided images accurately. While keeping user data safe, you can respond quickly and precisely to users' questions and requests. Your answers and suggestions should reject content related to pornography, gambling, drugs, violence, or terrorism."
                    },
                    {
                        role: "user",
                        content: [
                            {
                                type: "text",
                                text: "Describe this image with elegant language"
                            },
                            {
                                type: "image_url",
                                image_url: {
                                    url: await load_image("https://www.stepfun.com/assets/section-1-CTe4nZiO.webp")
                                }
                            }
                        ]
                    }
                ]
            });

            console.log(JSON.stringify(completion));
        }

        main();
        ```
      </Tab>

      <Tab title="curl">
        ```bash theme={null}
        # Load the image into memory for demo purposes only. Change as needed, e.g., read from a file.
        image_base64="data:image/webp;base64,"$(curl -s "https://www.stepfun.com/assets/section-1-CTe4nZiO.webp" | base64)

        curl https://api.stepfun.ai/v1/chat/completions \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer $STEP_API_KEY" \
          -d "{
            \"model\": \"step-3.7-flash\",
            \"messages\": [
              {
                \"role\": \"system\",
                \"content\": \"You are an AI chat assistant provided by StepFun. In addition to being good at Chinese, English, and many other languages, you can also describe the content of user-provided images accurately. While keeping user data safe, you can respond quickly and precisely to users' questions and requests. Your answers and suggestions should reject content related to pornography, gambling, drugs, violence, or terrorism.\"
              },
              {
                \"role\": \"user\",
                \"content\": [
                  {
                    \"type\": \"text\",
                    \"text\": \"Describe this image with elegant language\"
                  },
                  {
                    \"type\": \"image_url\",
                    \"image_url\": {
                      \"url\": \"${image_base64}\"
                    }
                  }
                ]
              }
            ]
          }"
        ```
      </Tab>
    </Tabs>

    ```json filename="Response" theme={null}
    {
      "id": "018ec23da38c7e2cbbe2f669c7b62483",
      "object": "chat.completion",
      "created": 1710145618,
      "model": "step-3.7-flash",
      "choices": [
        {
          "index": 0,
          "message": {
            "role": "assistant",
            "content": "In the soft light of dusk, a modern building comes into view with a striking red exterior that contrasts with its surroundings. The ground floor features spacious glass windows that fill the interior with natural light. A prominent sign stands on one side of the building, and the neatly arranged windows along the top showcase a modern design.\n\nIn the open area in front of the building, a bare tree sways gently in the breeze. The ground beneath is covered with gravel, adding a touch of nature to the space. On one side of the plaza, small lights cast a warm glow that feels especially cozy at twilight.\n\nThe area around the building is tidy, and the road is free of vehicles, giving a very peaceful feeling. In the distance, you can see the outlines of other buildings and the sun about to set, adding depth to the scene. The whole setting conveys a calm and orderly sense of urban life."
          },
          "finish_reason": "stop"
        }
      ],
      "usage": {
        "prompt_tokens": 497,
        "completion_tokens": 169,
        "total_tokens": 666
      }
    }
    ```
  </Tab>

  <Tab title="Streaming Response">
    <Tabs>
      <Tab title="python">
        ```python theme={null}
        from openai import OpenAI

        client = OpenAI(api_key="STEP_API_KEY", base_url="https://api.stepfun.ai/v1")

        completion = client.chat.completions.create(
            model="step-3.5-flash",
            stream=True,
            messages=[
                {
                    "role": "system",
                    "content": "You are an AI chat assistant provided by StepFun. You are good at Chinese, English, and many other languages. While keeping user data safe, you can respond quickly and accurately to users' questions and requests. Your answers and suggestions should reject content related to pornography, gambling, drugs, violence, or terrorism.",
                },
                {"role": "user", "content": "Hello, please introduce StepFun's artificial intelligence within 64 characters!"},
            ],
        )

        for chunk in completion:
            print(chunk)
        ```
      </Tab>

      <Tab title="js">
        ```js theme={null}
        import OpenAI from "openai";

        const openai = new OpenAI({
            apiKey: "STEP_API_KEY",
            baseURL: "https://api.stepfun.ai/v1"
        });

        async function main() {
            const completion = await openai.chat.completions.create({
                model: "step-3.5-flash",
                stream: true,
                messages: [
                    {
                        role: "system",
                        content: "You are an AI chat assistant provided by StepFun. You are good at Chinese, English, and many other languages. While keeping user data safe, you can respond quickly and accurately to users' questions and requests. Your answers and suggestions should reject content related to pornography, gambling, drugs, violence, or terrorism."
                    },
                    {
                        role: "user",
                        content: "Hello, please introduce StepFun's artificial intelligence within 64 characters!"
                    }
                ]
            });

            for await (const chunk of completion) {
                console.log(JSON.stringify(chunk));
            }
        }

        main();
        ```
      </Tab>

      <Tab title="curl">
        ```bash theme={null}
        curl https://api.stepfun.ai/v1/chat/completions \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer $STEP_API_KEY" \
          -d '{
            "model": "step-3.5-flash",
            "stream": true,
            "messages": [
              {
                "role": "system",
                "content": "You are an AI chat assistant provided by StepFun. You are good at Chinese, English, and many other languages. While keeping user data safe, you can respond quickly and accurately to users'\'' questions and requests. Your answers and suggestions should reject content related to pornography, gambling, drugs, violence, or terrorism."
              },
              {
                "role": "user",
                "content": "Hello, please introduce StepFun'\''s artificial intelligence within 64 characters!"
              }
            ]
          }'
        ```
      </Tab>
    </Tabs>

    ```json filename="Response" theme={null}
    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":0,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":""}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":"StepFun"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":1,"total_tokens":91}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" AI"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":2,"total_tokens":92}}
    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":","},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":3,"total_tokens":93}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" intelligent"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":4,"total_tokens":94}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" and"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":5,"total_tokens":95}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" secure"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":6,"total_tokens":96}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":","},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":7,"total_tokens":97}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" multilingual"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":8,"total_tokens":98}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":","},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":9,"total_tokens":99}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" fast"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":10,"total_tokens":100}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" and"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":11,"total_tokens":101}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" accurate"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":12,"total_tokens":102}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":","},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":13,"total_tokens":103}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" rejects"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":14,"total_tokens":104}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" harmful"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":15,"total_tokens":105}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" content"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":16,"total_tokens":106}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":","},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":17,"total_tokens":107}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" using"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":18,"total_tokens":108}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" technology"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":19,"total_tokens":109}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" to"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":20,"total_tokens":110}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" create"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":21,"total_tokens":111}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" a"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":22,"total_tokens":112}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" better"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":23,"total_tokens":113}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":" future"},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":24,"total_tokens":114}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":"."},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":25,"total_tokens":115}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":""},"finish_reason":""}],"usage":{"prompt_tokens":90,"completion_tokens":25,"total_tokens":115}}

    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":1710146871,"model":"step-3.5-flash","choices":[{"index":0,"delta":{"role":"","content":""},"finish_reason":"stop"}],"usage":{"prompt_tokens":90,"completion_tokens":25,"total_tokens":115}}

    data: [DONE]

    ```
  </Tab>
</Tabs>
