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

# Chat Completions API

调用 Chat Completions API，获取模型生成的对话响应数据。

## 请求地址

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

<Note>
  Step Plan 场景请使用 `POST https://api.stepfun.com/step_plan/v1/chat/completions`
</Note>

## 请求参数

* `model` `string` ***required***<br />需要使用的模型名称，例如 `step-3.7-flash`、`stepaudio-2.5-chat`、`step-3.5-flash` 或 `step-3.5-flash-2603`。`step-router-v1` 仅可通过 [Step Plan](/zh/step-plan/overview) 通道调用，详见本文「Step Plan 通道：DeepSeek 引擎字段差异」。

* `messages` `object array` ***required***<br />迄今为止用户输入或模型生成的不同类别消息列表

  <Expandable>
    * 系统消息 `object`
        <Expandable>
          * `role` `string`<br />系统类别名称，总是为 `system`
          * `content` `string`<br />系统消息的文本内容
        </Expandable>
    * 用户消息 `object`
        <Expandable>
          * `role` `string`<br />用户类别名称，总是 `user`
          * `content` `string or object array`<br />用户消息内容，类型为 `multipart` 消息列表或者普通文本消息字符串
                <Expandable>
                  * 普通文本消息 `string`
                  * `multipart` 消息列表 `object array`<br />结构化的图、视频、音频、文字混合消息
                          <Expandable>
                            * 文本消息 `object`
                                      <Expandable>
                                        * `type` `string`<br />总为 `text`
                                        * `text` `string`<br />消息文本内容
                                      </Expandable>
                            * 图片消息 `object`
                                      <Expandable>
                                        * `type` `string`<br />总为 `image_url`
                                        * `image_url` `object`
                                                    <Expandable>
                                                      * `url` `string`<br />图片地址或 base64 编码的图片，图片格式：jpg/jpeg、png、webp、静态 gif，仅支持 http 和 https 协议。base64 格式举例：`data:image/jpeg;base64,${base64_string}`。
                                                      * `detail` `string` ***optional***<br />图片细节级别：`low` / `high` 可选。`high` 按原图分辨率理解，在大图、OCR、极端长宽比等场景表现更好，token 随图片大小变化；`low` 将图片缩放到固定尺寸、更省 token，适合不要求高清细节、想省 token 或提速的场景。
                                                    </Expandable>
                                      </Expandable>
                            * 视频消息 `object`
                                      <Expandable>
                                        * `type` `string`<br />总为 `video_url`
                                        * `video_url` `object`
                                                    <Expandable>
                                                      * `url` `string`<br />视频的 URL 地址，视频格式：video/mp4，仅支持 http 和 https 协议，视频内容要小于 128M，时长建议小于 5 分钟。
                                                    </Expandable>
                                      </Expandable>
                            * 音频消息 `object`
                                      <Expandable>
                                        * `type` `string`<br />总为 `input_audio`
                                        * `input_audio` `object`
                                                    <Expandable>
                                                      * `data` `string`<br />音频内容，为音频的 base64 编码。base64 格式举例：`data:audio/mpeg;base64,${base64_string}`，请更换音频格式（当前仅支持 mp3 和 wav）及对应的 base64 编码后字符串。
                                                    </Expandable>
                                      </Expandable>
                          </Expandable>
                </Expandable>
        </Expandable>
    * 工具函数消息 `object`
        <Expandable>
          * `role` `string`<br />系统类别名称，总是为 `tool`
          * `content` `string`<br />函数执行得到的内容
          * `tool_call_id` `string`<br />执行函数的 ID，由 assistant 在上一轮对话中返回。
        </Expandable>
    * 聊天助手消息 `object`
        <Expandable>
          * `role` `string`<br />聊天助手类别名称，总是为 `assistant`
          * `content` `string | null`<br />聊天助手消息的文本内容
        </Expandable>
  </Expandable>

* `tools` `object array` ***optional***<br />Toolcall 支持的函数列表

  <Expandable>
    * `type` `string`<br />工具类型，总是为 `function`
    * `function` `object`<br />函数内容的描述
      * `name` `string`<br />函数名称，要求纯英文、数字和 \_- 符号，建议不要超过 64 个字符长度。
      * `description` `string`<br />函数描述，支持中英文，它用于告诉模型函数实现何种功能和目的，方便模型来判断和选择。
      * `parameters` `object`<br />函数的参数
        * `type` `object`<br />参数描述，一般为 object
        * `properties` `object`<br />函数参数内容，以 key 为参数的名称，然后通过 `type` 和 `description` 描述参数的类型和介绍。
          * `type` `string|number|integer|object|array|boolean`<br />参数类型，可以参考 [json-schema](https://json-schema.org/understanding-json-schema/reference/type) 介绍。
          * `description` `string`<br />函数参数描述，支持中英文，它用于告诉模型函数参数的含义。
  </Expandable>

* `audio` `object` ***optional***<br />用于控制音频输出的参数，只在支持端到端模型场景的模型下生效（`step-1o-audio`/`step-audio-2`/`step-audio-2-mini`/`step-audio-r1.1`）
  <Expandable>
    * `voice` `string` ***required***<br />指定生成音频的声音 ID，对于 `step-1o-audio` 可通过[获取声音列表接口](../audio/list-voice)查询可用的声音 ID，对于 `step-audio-2` 系列模型，可用 `wenrounansheng`（温柔男声）、`qingchunshaonv`（青春少女）、`livelybreezy-female`（活力少女）、`elegantgentle-female`（高雅女声）四种声音 ID。
    * `format` `string` ***required***<br />指定生成音频的格式，支持 `pcm` 和 `wav` 两种格式，在非流式场景下（stream=false）支持 wav 输出；在流式场景下（stream=true）时，只支持 pcm 输出（24khz, 单声道, 16bit）。
  </Expandable>

* `modalities` `string array` ***optional***<br />指定输出的模态类型，支持 `text`、`audio` 两种模态类型，只在端到端模型场景下必填。如果需要模型输出音频，则需要将 `audio` 添加到该参数中，建议设置为 `["text", "audio"]`。`stepaudio-2.5-chat` 仅支持 `text`，若选择 `audio` 会报错。

* `max_tokens` `int` ***optional***<br />聊天需要生成的 `标记` 最大数量，默认值为 INF（不作限制，由模型自动决定）。输入 `标记` 和生成 `标记` 的总数量受限于指定模型的最大上下文长度。

* `temperature` `float` ***optional***<br />采样温度，介于0.0和2.0之间的数字。较高值（如0.8）会使生成更随机，较低值（如0.2）会使其生成结果更集中且确定。默认值为0.5

* `top_p` `float` ***optional***<br />核心采样，该值会使模型生成具有 top\_p 概率质量的 `标记` 并输出到结果。默认值为0.9

* `n` `int` ***optional***<br />控制模型为每个输入消息生成的响应消息结果条数，默认值为1，最大不限，建议不超过5。

* `stream` `bool` ***optional***<br />是否流式生成响应消息，默认值为 false

* `stop` `string | string array` ***optional***<br />用于指导模型生成聊天响应过程中，是否遇到 stop 中的内容，进行生成中断，默认为空

* `frequency_penalty` `float` ***optional***<br />默认为0。介于0.0和1.0之间的数字。值较高会使模型生成某 `token` 时，根据其过往在生成文本中出现的频度，进行后续降频惩罚，从而降低模型重复生成相同内容的可能性

* `response_format` `object` ***optional***<br />用于指导模型输出特定格式的内容。默认为 `{"type":"text"}`，表示输出文本。
  <Expandable>
    * `type` `string`<br />输出格式类型，可选值为 `text`、`json_object`、`json_schema`。设置为 `json_object` 可以[开启 JSON Mode](../../guides/developer/json-mode)，输出可解析的 JSON 结构。设置为 `json_schema` 可以指定 JSON Schema 约束输出结构（仅 step-3.5-flash 及 step-3.5-flash-2603 支持）。
    * `json_schema` `object`<br />当 `type` 为 `json_schema` 时必填，定义输出的 JSON Schema。
        <Expandable>
          * `name` `string` ***required***<br />Schema 名称，用于标识该 schema。
          * `strict` `boolean` ***optional***<br />是否开启严格模式，开启后模型输出将严格遵循所定义的 schema。默认为 `false`。
          * `schema` `object` ***required***<br />JSON Schema 定义对象，描述期望的输出结构。遵循 [JSON Schema](https://json-schema.org/) 规范。
        </Expandable>
  </Expandable>

* `reasoning_format` `string` ***optional***<br />用于指导模型输出时使用的 reasoning 字段；默认为 `general`，表示通用推理，使用 `reasoning` 字段返回结果；可选项为
  \[`general`,`deepseek-style`]。当设置为 `deepseek-style` 时，可使用 DeepSeek 兼容的 `reasoning_content` 字段获取到
  reasoning 内容。

* `reasoning_effort` `string` ***optional***<br />控制模型的推理深度。支持三档推理强度的模型可选值为 `low`、`medium`、`high`；`step-3.5-flash-2603` 兼容 `low`、`high` 两档。值越高，模型会进行更深入的思考，但响应时间可能更长。

## Step Plan 通道：DeepSeek 引擎字段差异

`step-router-v1` 仅可通过 [Step Plan](/zh/step-plan/overview) 通道（`https://api.stepfun.com/step_plan/v1`）调用，系统会自动在 `deepseek-v4-pro` 与 `step-3.5-flash` 之间路由。该模型的字段约束与本文「请求参数」一致，下表列出的字段除外。

| 字段                      | Step Plan 通道下的行为                                              |
| ----------------------- | ------------------------------------------------------------- |
| `model`                 | 仅接受 `step-router-v1`，其他名称返回 HTTP 400 `request_params_invalid` |
| `max_tokens`            | 上限为 384K                                                      |
| `messages` 中的图像 / 文档输入  | 不支持，使用会返回 `unsupported_content_type`                          |
| `tools` 中的 `web_search` | 不支持，使用会返回 `unsupported_content_type`                          |

## 响应格式

### 非流式响应

当 `stream=false`（默认）时，返回单个 Chat Completion 响应对象。

#### 属性

* `id` `string`
  <br />
  生成的聊天响应 ID
* `object` `string`
  <br />
  模型生成聊天响应的模式，此模式下总为 `chat.completion`
* `model` `string`
  <br />
  模型名称
* `created` `timestamp`
  <br />
  生成聊天响应时的 Unix 时间戳，单位为秒
* `choices` `object array`

  <br />

  模型生成的聊天响应结果的可选路径列表。

  <Expandable>
    * `finish_reason` `string`<br />模型停止继续生成的原因
    * `index` `int` <br /> 当前可选路径序列号
    * `message` `object` <br /> 模型生成的聊天响应实际消息内容

    <Expandable>
      - `role` `string`<br />消息所属角色，这里总为 `assistant`
      - `content` `string`<br />消息文本内容
      - `reasoning` `string`<br />推理思考过程内容，仅在 step 推理模型下返回。
      - `tool_calls` `object array` ***optional***<br />toolcall 内容返回

      <Expandable>
        * `id` `string`<br />函数执行 ID，由模型生成，在 context 保持唯一。
        * `type` `string`<br />toolcall 的类型，默认为 `function`
        * `function` `object`<br />函数的消息体

        <Expandable>
          - `name` `string` <br /> 函数名称，通常纯英文、数字和\_-符号，一般是在上一轮对话提交的 tools 列表中
          - `arguments` `string` <br /> 函数执行的参数，一般为 json 结构化对象。
        </Expandable>
      </Expandable>
    </Expandable>
  </Expandable>
* `usage` `object`
  <br />
  模型聊天响应生成的 `标记` 统计信息
  <Expandable>
    * `prompt_tokens` `int` <br /> 生成过程中使用的提示信息总 `标记` 数量
    * `cached_tokens` `int` ***optional*** <br /> 生成过程中使用的提示信息被缓存的总 `标记` 数量
    * `completion_tokens` `int` <br /> 生成的响应消息内容总 `标记` 数量
    * `total_tokens` `int`<br />生成结束后统计的总的 `标记` 数量
  </Expandable>

#### 示例

```json theme={null}
{
  "id": "b7b56af0-52a6-483f-a589-948182676a1b",
  "object": "chat.completion",
  "created": 1709893411,
  "model": "step-3.7-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "你好！阶跃星辰是一家专注于人工智能技术的公司，致力于开发和提供各种AI解决方案。我们的人工智能技术涵盖了自然语言处理、计算机视觉、机器学习等领域，旨在帮助用户在各个行业和领域中提高效率和创造价值。"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": { "prompt_tokens": 83, "completion_tokens": 176, "total_tokens": 259 }
}
```

### 流式响应

当 `stream=true` 时，返回 Server-Sent Events (SSE) 格式的流式数据。每个事件包含一个 Chat Completion 响应对象块。

#### 属性

* `id` `string`
  <br />
  生成的聊天响应 ID
* `object` `string`
  <br />
  模型生成聊天响应的模式，此模式下总为 `chat.completion.chunk`
* `created` `timestamp`
  <br />
  聊天响应时的 Unix 时间戳，单位为秒
* `model` `string`
  <br />
  模型名称
* `choices` `object array`

  <br />

  模型流式生成的聊天响应结果的可选路径列表。单个 `choice` object 属性：

  <Expandable>
    * `finish_reason` `string`<br />模型停止继续生成的原因
    * `index` `int`<br />当前可选路径序列号
    * `delta` object<br />模型渐进生成的聊天响应块

    <Expandable>
      - `role` `string`<br />消息所属角色，此处总为 `assistant`
      - `content` `string`<br />消息文本内容
      - `reasoning` `string`<br />推理思考过程内容，仅在 step 推理模型下返回。
      - `tool_calls` `object array` ***optional***<br />toolcall 内容返回

      <Expandable>
        * `id` `string`<br />函数执行 ID，由模型生成，在 context 保持唯一。
        * `type` `string`<br />toolcall 的类型，默认为 `function`
        * `function` `object`<br />函数的消息体

        <Expandable>
          - `name` `string`<br />函数名称，通常纯英文、数字和\_-符号，一般是在上一轮对话提交的 tools 列表中
          - `arguments` `string`<br />函数执行的参数，一般为 json 结构化对象。
        </Expandable>
      </Expandable>
    </Expandable>
  </Expandable>
* `usage` `object`
  <br />
  模型聊天响应生成的 `标记` 统计信息
  <Expandable>
    * `prompt_tokens` `int`<br /> 生成过程中使用的提示信息总 `标记` 数量
    * `cached_tokens` `int` ***optional***<br /> 生成过程中使用的提示信息被缓存的总 `标记` 数量
    * `completion_tokens` `int`<br /> 生成的响应消息内容总 `标记` 数量
    * `total_tokens` `int`<br />生成结束后统计的总的 `标记` 数量
  </Expandable>

#### 示例

```text theme={null}
data: {"id":"d7ae7c4a-1524-4fe5-9d58-e4d59b89d8f0","object":"chat.completion.chunk","created":1709899323,"model":"step-3.7-flash","choices":[{"index":0,"delta":{"role":"","content":"您"},"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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"好"},"finish_reason":""}],"usage":{"prompt_tokens":83,"completion_tokens":2,"total_tokens":85}}

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

...

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

data: [DONE]
```

## 示例

> 说明：以下基础示例默认使用 `step-3.5-flash`。如需使用三档推理强度，可参考「推理强度」示例中的 `step-3.7-flash` 调用方式。

<Tabs>
  <Tab title="推理强度">
    ```bash theme={null}
    curl https://api.stepfun.com/v1/chat/completions \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $STEPFUN_API_KEY" \
      -d '{
        "model": "step-3.7-flash",
        "messages": [
          {
            "role": "user",
            "content": "请用三句话解释什么是强化学习。"
          }
        ],
        "reasoning_effort": "medium",
        "max_tokens": 1024
      }'
    ```
  </Tab>

  <Tab title="文字聊天">
    <Tabs>
      <Tab title="python">
        ```python theme={null}
        from openai import OpenAI

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

        completion = client.chat.completions.create(
            model="step-3.5-flash",
            messages=[
                {
                    "role": "system",
                    "content": "你是由阶跃星辰提供的AI聊天助手，你擅长中文，英文，以及多种其他语言的对话。在保证用户数据安全的前提下，你能对用户的问题和请求，作出快速和精准的回答。同时，你的回答和建议应该拒绝黄赌毒，暴力恐怖主义的内容",
                },
                {
                    "role": "user",
                    "content": "你好，请介绍一下阶跃星辰的人工智能!"
                }
            ],
        )

        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.com/v1"
        });

        async function main() {
            const completion = await openai.chat.completions.create({
                model: "step-3.5-flash",
                messages: [
                    {
                        role: "system",
                        content: "你是由阶跃星辰提供的AI聊天助手，你擅长中文，英文，以及多种其他语言的对话。在保证用户数据安全的前提下，你能对用户的问题和请求，作出快速和精准的回答。同时，你的回答和建议应该拒绝黄赌毒，暴力恐怖主义的内容"
                    },
                    {
                        role: "user",
                        content: "你好，请介绍一下阶跃星辰的人工智能!"
                    }
                ]
            });

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

        main();
        ```
      </Tab>

      <Tab title="curl">
        ```bash theme={null}
        curl https://api.stepfun.com/v1/chat/completions \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer $STEP_API_KEY" \
          -d '{
            "model": "step-3.5-flash",
            "messages": [
              {
                "role": "system",
                "content": "你是由阶跃星辰提供的AI聊天助手，你擅长中文，英文，以及多种其他语言的对话。在保证用户数据安全的前提下，你能对用户的问题和请求，作出快速和精准的回答。同时，你的回答和建议应该拒绝黄赌毒，暴力恐怖主义的内容。"
              },
              {
                "role": "user",
                "content": "你好，请介绍一下阶跃星辰的人工智能！"
              }
            ]
          }'
        ```
      </Tab>
    </Tabs>

    ```json filename="返回" theme={null}
    {
      "id": "e2eb4b00d2c226517de3882f17d9664b.ffead889783a0bcd8d2bd17ea4d4c2af",
      "object": "chat.completion",
      "created": 1772624997,
      "model": "step-3.5-flash",
      "choices": [
        {
          "index": 0,
          "message": {
            "role": "assistant",
            "content": "阶跃星辰（StepFun）是一家专注于**多模态人工智能技术研发与应用**的科技公司，致力于推动大模型（LLM）在文本、图像、逻辑推理等多领域的融合创新。其核心产品 **Step AI**（又称Step模型）具备以下特点：\n\n---\n\n### 🔍 **核心能力**\n1. **多模态融合**  \n   - 不仅能处理文本，还可理解图片、图表等视觉信息，实现跨模态推理（例如根据图片描述内容、解答视觉逻辑题）。\n2. **强大的逻辑与知识能力**  \n   - 在数理逻辑、代码生成、专业知识问答等场景表现突出，支持复杂任务拆解与精准分析。\n3. **多语言支持**  \n   - 覆盖中、英及多语种交流，适应全球化场景。\n4. **安全与合规**  \n   - 严格遵循内容安全规范，拒绝生成暴力、仇恨、虚假信息等有害内容，注重用户隐私保护。\n\n---\n\n### 🌟 **技术亮点**\n- **自主研发大模型架构**：针对多模态任务优化，提升视觉-语言对齐能力。\n- **高效推理与低能耗设计**：在保证性能的同时，兼顾部署效率。\n- **持续迭代能力**：通过数据与算法优化，动态提升模型的理解与生成质量。\n\n---\n\n### 🚀 **应用场景**\n- **教育科研**：辅助解题、文献分析、多学科知识问答。\n- **办公创作**：文档总结、代码辅助、创意文案生成。\n- **工业与商业**：数据分析报告生成、多模态信息检索、智能客服升级。\n- **日常生活**：跨语言交流、图像内容解读、个性化知识助手。\n\n---\n\n### 🌍 **价值观与愿景**\n阶跃星辰强调 **“技术向善”**，推动AI在安全、可靠、有益的方向发展，致力于成为多模态智能时代的引领者，让技术服务于社会创新与人类福祉。\n\n---\n\n如需了解具体技术细节或应用案例，可进一步探讨！ 🌟"
          },
          "finish_reason": "stop"
        }
      ],
      "usage": {
        "prompt_tokens": 85,
        "completion_tokens": 701,
        "total_tokens": 786
      }
    }
    ```
  </Tab>

  <Tab title="图片理解">
    <Tabs>
      <Tab title="python">
        ```python theme={null}
        from openai import OpenAI

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

        completion = client.chat.completions.create(
            model="step-3.7-flash",
            messages=[
                {
                    "role": "system",
                    "content": "你是由阶跃星辰提供的AI聊天助手，你除了擅长中文，英文，以及多种其他语言的对话以外，还能够根据用户提供的图片，对内容进行精准的内容文本描述。在保证用户数据安全的前提下，你能对用户的问题和请求，作出快速和精准的回答。同时，你的回答和建议应该拒绝黄赌毒，暴力恐怖主义的内容",
                },
                {
                    "role": "user",
                    "content": [
                        {
                            "type": "text",
                            "text": "用优雅的语言描述这张图片",
                        },
                        {
                            "type": "image_url",
                            "image_url": {
                                "url": "https://www.stepfun.com/assets/section-1-CTe4nZiO.webp",
                                "detail": "high"
                            },
                        },
                    ],
                },
            ],
        )

        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.com/v1"
        });

        async function main() {
            const completion = await openai.chat.completions.create({
                model: "step-3.7-flash",
                messages: [
                    {
                        role: "system",
                        content: "你是由阶跃星辰提供的AI聊天助手，你除了擅长中文，英文，以及多种其他语言的对话以外，还能够根据用户提供的图片，对内容进行精准的内容文本描述。在保证用户数据安全的前提下，你能对用户的问题和请求，作出快速和精准的回答。同时，你的回答和建议应该拒绝黄赌毒，暴力恐怖主义的内容"
                    },
                    {
                        role: "user",
                        content: [
                            {
                                type: "text",
                                text: "用优雅的语言描述这张图片"
                            },
                            {
                                type: "image_url",
                                image_url: {
                                    url: "https://www.stepfun.com/assets/section-1-CTe4nZiO.webp",
                                    detail: "high"
                                }
                            }
                        ]
                    }
                ]
            });

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

        main();
        ```
      </Tab>

      <Tab title="curl">
        ```bash theme={null}
        curl https://api.stepfun.com/v1/chat/completions \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer $STEP_API_KEY" \
          -d '{
            "model": "step-3.7-flash",
            "messages": [
              {
                "role": "system",
                "content": "你是由阶跃星辰提供的AI聊天助手，你除了擅长中文，英文，以及多种其他语言的对话以外，还能够根据用户提供的图片，对内容进行精准的内容文本描述。在保证用户数据安全的前提下，你能对用户的问题和请求，作出快速和精准的回答。同时，你的回答和建议应该拒绝黄赌毒，暴力恐怖主义的内容"
              },
              {
                "role": "user",
                "content": [
                  {
                    "type": "text",
                    "text": "用优雅的语言描述这张图片"
                  },
                  {
                    "type": "image_url",
                    "image_url": {
                      "url": "https://www.stepfun.com/assets/section-1-CTe4nZiO.webp",
                      "detail": "high"
                    }
                  }
                ]
              }
            ]
          }'
        ```
      </Tab>
    </Tabs>

    ```json filename="返回" 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": "在黄昏的柔和光线下，一座现代化的建筑映入眼帘，它拥有鲜明的红色外观，与周围环境形成鲜明对比。这座建筑的底层设有宽敞的玻璃窗，为室内提供了充足的自然光。建筑的一侧有醒目的标识，顶部的窗户排列整齐，展现了现代设计的风格。\n\n在建筑前的空地上，有一棵光秃的树，其枝条在微风中轻轻摇曳。树下是一片铺着碎石的土地，为这个空间增添了一丝自然的气息。在空地的一侧，还可以看到几个小巧的灯具，它们发出的温暖光线在傍晚显得格外温馨。\n\n建筑周围环境整洁，道路上没有车辆，显得非常宁静。远处可以看到其他建筑的轮廓，以及天空中即将落下的太阳，为这幅画面增添了丰富的层次感。整个场景透露出一种宁静而有序的都市生活氛围。"
                },
                "finish_reason": "stop"
            }
        ],
        "usage": {
            "prompt_tokens": 497,
            "completion_tokens": 169,
            "total_tokens": 666
        }
    }
    ```
  </Tab>

  <Tab title="语音输入输出">
    <Tabs>
      <Tab title="python">
        ```python theme={null}
        import base64
        from openai import OpenAI

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

        completion = client.chat.completions.create(
            model="step-audio-2",
            modalities=["text", "audio"],
            messages=[
                {
                    "role": "system",
                    "content": "你是一个老北京大爷，喜欢用京片子和用户聊天。",
                },
                {
                    "role": "user",
                    "content": "今儿个北京的天气咋样啊？",
                },
            ],
            audio={
                "voice": "wenrounansheng",
                "format": "wav",
            },
            stream=False,
        )

        # response transcript
        print(completion.choices[0].message.audio.transcript)
        # save response audio
        with open("response.wav", "wb") as f:
            f.write(base64.b64decode(completion.choices[0].message.audio.data))
        # 打开 response.wav 即可收听音频回复
        ```
      </Tab>

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

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

        const downloadAudioAsBase64 = async (url) => {
            const response = await fetch(url);
            const arrayBuffer = await response.arrayBuffer();
            const buffer = Buffer.from(arrayBuffer);
            return "data:audio/wav;base64," + buffer.toString("base64");
        };

        async function main() {
            const completion = await openai.chat.completions.create({
                model: "step-audio-2",
                modalities: ["text", "audio"],
                messages: [
                    {
                        role: "system",
                        content: "你是一个动物声音识别专家，请根据用户提供的动物声音进行识别。"
                    },
                    {
                        role: "user",
                        content: [
                            {
                                type: "text",
                                text: "听听这是什么声音"
                            },
                            {
                                type: "input_audio",
                                input_audio: {
                                    data: await downloadAudioAsBase64("https://stepchat-static.tos-cn-shanghai.volces.com/resource_tmp/cat-meow.wav")
                                }
                            }
                        ]
                    }
                ],
                audio: {
                    voice: "wenrounansheng",
                    format: "wav"
                },
                stream: false
            });
            // response transcript
            console.log(completion.choices[0].message.audio.transcript);
            // save response audio
            fs.writeFileSync("response.wav", Buffer.from(completion.choices[0].message.audio.data, "base64"));
            // 打开 response.wav 即可收听音频回复
        }

        main();
        ```
      </Tab>

      <Tab title="curl">
        ```bash theme={null}
        curl https://api.stepfun.com/v1/chat/completions \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer $STEP_API_KEY" \
          -d '{
            "model": "step-audio-2",
            "modalities": ["text", "audio"],
            "messages": [
              {
                "role": "system",
                "content": "你是一个老北京大爷，喜欢用京片子和用户聊天。"
              },
              {
                "role": "user",
                "content": "今儿个北京的天气咋样啊？"
              }
            ],
            "audio": {
              "voice": "wenrounansheng",
              "format": "wav"
            },
            "stream": false
          }'
        ```
      </Tab>
    </Tabs>

    语音示例返回（text+audio 模态，带 toolcall 字段），由于带有 audio，所以返回内容较大，audio 字段内容被截断显示：

    ```json theme={null}
    {
      "id": "019b55f32eb27db7a0cc933be0216686",
      "choices": [
        {
          "finish_reason": null,
          "index": 0,
          "logprobs": null,
          "message": {
            "role": "assistant",
            "audio": {
              "data": "[base64 wav, length=193940]",
              "transcript": "哎呀，现在是下午三点啦。"
            },
            "tool_calls": [
              {
                "id": "call-1766673564415832077",
                "function": {
                  "arguments": "{\"city\": \"北京\"}",
                  "name": "get_weather"
                },
                "type": "function",
                "index": 0
              }
            ]
          }
        }
      ],
      "created": 1766673565,
      "model": "step-audio-2",
      "object": "chat.completion",
      "usage": {
        "completion_tokens": 106,
        "prompt_tokens": 410,
        "total_tokens": 516,
        "completion_tokens_details": null,
        "prompt_tokens_details": null
      }
    }
    ```
  </Tab>

  <Tab title="Base64编码图片">
    <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.com/v1")

        # 加载图片到内存，仅演示。按需改成读文件等
        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": "你是由阶跃星辰提供的AI聊天助手，你除了擅长中文，英文，以及多种其他语言的对话以外，还能够根据用户提供的图片，对内容进行精准的内容文本描述。在保证用户数据安全的前提下，你能对用户的问题和请求，作出快速和精准的回答。同时，你的回答和建议应该拒绝黄赌毒，暴力恐怖主义的内容",
                },
                {
                    "role": "user",
                    "content": [
                        {
                            "type": "text",
                            "text": "用优雅的语言描述这张图片",
                        },
                        {
                            "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.com/v1"
        });

        // 加载图片到内存，仅演示。按需改成读文件等
        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: "你是由阶跃星辰提供的AI聊天助手，你除了擅长中文，英文，以及多种其他语言的对话以外，还能够根据用户提供的图片，对内容进行精准的内容文本描述。在保证用户数据安全的前提下，你能对用户的问题和请求，作出快速和精准的回答。同时，你的回答和建议应该拒绝黄赌毒，暴力恐怖主义的内容"
                    },
                    {
                        role: "user",
                        content: [
                            {
                                type: "text",
                                text: "用优雅的语言描述这张图片"
                            },
                            {
                                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}
        # 加载图片到内存，仅演示。按需改成读文件等
        image_base64="data:image/webp;base64,"$(curl -s "https://www.stepfun.com/assets/section-1-CTe4nZiO.webp" | base64)

        curl https://api.stepfun.com/v1/chat/completions \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer $STEP_API_KEY" \
          -d "{
            \"model\": \"step-3.7-flash\",
            \"messages\": [
              {
                \"role\": \"system\",
                \"content\": \"你是由阶跃星辰提供的AI聊天助手，你除了擅长中文，英文，以及多种其他语言的对话以外，还能够根据用户提供的图片，对内容进行精准的内容文本描述。在保证用户数据安全的前提下，你能对用户的问题和请求，作出快速和精准的回答。同时，你的回答和建议应该拒绝黄赌毒，暴力恐怖主义的内容\"
              },
              {
                \"role\": \"user\",
                \"content\": [
                  {
                    \"type\": \"text\",
                    \"text\": \"用优雅的语言描述这张图片\"
                  },
                  {
                    \"type\": \"image_url\",
                    \"image_url\": {
                      \"url\": \"${image_base64}\"
                    }
                  }
                ]
              }
            ]
          }"
        ```
      </Tab>
    </Tabs>

    ```json filename="返回" theme={null}
    {
        "id": "018ec23da38c7e2cbbe2f669c7b62483",
        "object": "chat.completion",
        "created": 1710145618,
        "model": "step-3.7-flash",
        "choices": [
            {
                "index": 0,
                "message": {
                    "role": "assistant",
                    "content": "在黄昏的柔和光线下，一座现代化的建筑映入眼帘，它拥有鲜明的红色外观，与周围环境形成鲜明对比。这座建筑的底层设有宽敞的玻璃窗，为室内提供了充足的自然光。建筑的一侧有醒目的标识，顶部的窗户排列整齐，展现了现代设计的风格。\n\n在建筑前的空地上，有一棵光秃的树，其枝条在微风中轻轻摇曳。树下是一片铺着碎石的土地，为这个空间增添了一丝自然的气息。在空地的一侧，还可以看到几个小巧的灯具，它们发出的温暖光线在傍晚显得格外温馨。\n\n建筑周围环境整洁，道路上没有车辆，显得非常宁静。远处可以看到其他建筑的轮廓，以及天空中即将落下的太阳，为这幅画面增添了丰富的层次感。整个场景透露出一种宁静而有序的都市生活氛围。"
                },
                "finish_reason": "stop"
            }
        ],
        "usage": {
            "prompt_tokens": 497,
            "completion_tokens": 169,
            "total_tokens": 666
        }
    }
    ```
  </Tab>

  <Tab title="流式响应">
    <Tabs>
      <Tab title="python">
        ```python theme={null}
        from openai import OpenAI

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

        completion = client.chat.completions.create(
            model="step-3.7-flash",
            stream=True,
            messages=[
                {
                    "role": "system",
                    "content": "你是由阶跃星辰提供的AI聊天助手，你擅长中文，英文，以及多种其他语言的对话。在保证用户数据安全的前提下，你能对用户的问题和请求，作出快速和精准的回答。同时，你的回答和建议应该拒绝黄赌毒，暴力恐怖主义的内容",
                },
                {"role": "user", "content": "你好，请在64字数以内介绍一下阶跃星辰的人工智能!"},
            ],
        )

        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.com/v1"
        });

        async function main() {
            const completion = await openai.chat.completions.create({
                model: "step-3.7-flash",
                stream: true,
                messages: [
                    {
                        role: "system",
                        content: "你是由阶跃星辰提供的AI聊天助手，你擅长中文，英文，以及多种其他语言的对话。在保证用户数据安全的前提下，你能对用户的问题和请求，作出快速和精准的回答。同时，你的回答和建议应该拒绝黄赌毒，暴力恐怖主义的内容"
                    },
                    {
                        role: "user",
                        content: "你好，请在64字数以内介绍一下阶跃星辰的人工智能!"
                    }
                ]
            });

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

        main();
        ```
      </Tab>

      <Tab title="curl">
        ```bash theme={null}
        curl https://api.stepfun.com/v1/chat/completions \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer $STEP_API_KEY" \
          -d '{
            "model": "step-3.7-flash",
            "stream": true,
            "messages": [
              {
                "role": "system",
                "content": "你是由阶跃星辰提供的AI聊天助手，你擅长中文，英文，以及多种其他语言的对话。在保证用户数据安全的前提下，你能对用户的问题和请求，作出快速和精准的回答。同时，你的回答和建议应该拒绝黄赌毒，暴力恐怖主义的内容"
              },
              {
                "role": "user",
                "content": "你好，请在64字数以内介绍一下阶跃星辰的人工智能!"
              }
            ]
          }'
        ```
      </Tab>
    </Tabs>

    ```json filename="返回" theme={null}
    data: {"id":"d4ca43cd-83a7-4012-9ee7-b8f143eb1f8f","object":"chat.completion.chunk","created":0,"model":"step-3.7-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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"阶"},"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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"跃"},"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.7-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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"AI"},"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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"，"},"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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"智能"},"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.7-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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"，"},"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.7-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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"语言"},"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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"，"},"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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"快速"},"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.7-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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"，"},"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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"拒绝"},"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.7-flash","choices":[{"index":0,"delta":{"role":"","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.7-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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"用"},"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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"科技"},"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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"创造"},"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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"美好"},"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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"未来"},"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.7-flash","choices":[{"index":0,"delta":{"role":"","content":"。"},"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.7-flash","choices":[{"index":0,"delta":{"role":"","content":""},"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.7-flash","choices":[{"index":0,"delta":{"role":"","content":""},"finish_reason":"stop"}],"usage":{"prompt_tokens":90,"completion_tokens":24,"total_tokens":114}}

    data: [DONE]

    ```
  </Tab>
</Tabs>
