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

# ChatCompletions格式

> 根据对话历史创建模型响应。支持流式和非流式响应。兼容 OpenAI Chat Completions API。

将 `stream` 设为 `true` 时，接口会以 SSE 格式逐段返回生成内容。

## 请求头

**Authorization** `string` *required*

使用 Bearer Token 认证。格式：`Authorization: Bearer sk-xxxxxx`

## 请求体

格式：`application/json`

**model** `string` *required*

模型 ID

**messages** `object[]` *required*

对话消息列表

**属性**

**role** `string` *required*

消息角色，可选值：`system`、`user`、`assistant`、`tool`、`developer`

**content** `string | object[]` *required*

消息内容

**name** `string`

发送者名称

**tool\_calls** `object[]`

工具调用列表

**tool\_call\_id** `string`

工具调用 ID（用于 tool 角色消息）

**reasoning\_content** `string`

推理内容

**temperature** `number` (default: 1)

采样温度，范围 `0` 到 `2`

**top\_p** `number` (default: 1)

核采样参数，范围 `0` 到 `1`

**n** `integer` (default: 1)

生成数量，范围 `1` 以上

**stream** `boolean` (default: false)

是否流式响应

**stream\_options** `object`

流式响应选项

**属性**

**include\_usage** `boolean`

是否在流式响应中包含用量信息

**stop** `string | string[]`

停止序列

**max\_tokens** `integer`

最大生成 Token 数

**max\_completion\_tokens** `integer`

最大补全 Token 数

**presence\_penalty** `number` (default: 0)

存在惩罚，范围 `-2` 到 `2`

**frequency\_penalty** `number` (default: 0)

频率惩罚，范围 `-2` 到 `2`

**logit\_bias** `object`

对指定 Token 的采样偏置

**属性**

**\[key: string]** `number`

键为 Token ID，值为偏置数值

**user** `string`

用户标识

**tools** `object[]`

工具列表

**属性**

**type** `string`

工具类型

**function** `object`

函数定义

**tool\_choice** `string | object`

工具选择策略

**属性（object 形式）**

**type** `string`

工具类型

**function** `object`

指定要调用的函数

**response\_format** `object`

响应格式设置

**属性**

**type** `string`

格式类型，可选值：`text`、`json_object`、`json_schema`

**json\_schema** `object`

JSON Schema 定义

**seed** `integer`

随机种子

**reasoning\_effort** `string`

推理强度（用于支持推理的模型），可选值为 `"low"`、`"medium"`、`"high"`

**modalities** `string[]`

模态类型列表

**audio** `object`

音频参数

**属性**

**voice** `string`

音色

**format** `string`

音频格式

## 响应

### 200 成功创建响应

格式：`application/json`

**id** `string`

补全 ID

**object** `string`

对象类型，值为 `chat.completion`

**created** `integer`

创建时间戳

**model** `string`

模型 ID

**choices** `object[]`

生成结果列表

**属性**

**index** `integer`

结果索引

**message** `object`

消息对象

**属性**

**role** `string`

角色

**content** `string`

内容

**name** `string`

名称

**tool\_calls** `array[object]`

工具调用列表

**属性**

**id** `string`

调用 ID

**type** `string`

类型，值为 `function`

**function** `object`

函数信息

**属性**

**name** `string`

函数名

**arguments** `string`

函数参数

**tool\_call\_id** `string`

工具调用 ID

**reasoning\_content** `string`

推理内容

**finish\_reason** `string`

结束原因，例如 `stop`

**usage** `object`

Token 用量信息

**属性**

**prompt\_tokens** `integer`

提示 Token 数

**completion\_tokens** `integer`

补全 Token 数

**total\_tokens** `integer`

总 Token 数

**prompt\_tokens\_details** `object`

提示 Token 明细

**属性**

**cached\_tokens** `integer`

缓存 Token 数

**text\_tokens** `integer`

文本 Token 数

**audio\_tokens** `integer`

音频 Token 数

**image\_tokens** `integer`

图像 Token 数

**completion\_tokens\_details** `object`

补全 Token 明细

**属性**

**text\_tokens** `integer`

文本 Token 数

**audio\_tokens** `integer`

音频 Token 数

**reasoning\_tokens** `integer`

推理 Token 数

**system\_fingerprint** `string`

系统指纹

### 400 请求参数错误

格式：`application/json`

**error** `object`

错误信息

**属性**

**message** `string`

错误信息

**type** `string`

错误类型

**param** `string | null`

相关参数

**code** `string | null`

错误代码

### 429 请求频率限制

格式：`application/json`

**error** `object`

错误信息

**属性**

**message** `string`

错误信息

**type** `string`

错误类型

**param** `string | null`

相关参数

**code** `string | null`

错误代码

```bash cURL theme={"dark"}
curl -X POST "https://t.ato2.nodesms.com/v1/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4",
    "messages": [
      {
        "role": "system",
        "content": "string"
      }
    ]
  }'
```

```python Python theme={"dark"}
import openai

client = openai.OpenAI(
    api_key="sk-xxxxxx",
    base_url="https://t.ato2.nodesms.com/v1"
)

response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "system", "content": "string"}]
)
print(response.choices[0].message.content)
```

```json 200 theme={"dark"}
{
  "id": "string",
  "object": "chat.completion",
  "created": 0,
  "model": "string",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "system",
        "content": "string",
        "name": "string",
        "tool_calls": [
          {
            "id": "string",
            "type": "function",
            "function": {
              "name": "string",
              "arguments": "string"
            }
          }
        ],
        "tool_call_id": "string",
        "reasoning_content": "string"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 0,
    "completion_tokens": 0,
    "total_tokens": 0,
    "prompt_tokens_details": {
      "cached_tokens": 0,
      "text_tokens": 0,
      "audio_tokens": 0,
      "image_tokens": 0
    },
    "completion_tokens_details": {
      "text_tokens": 0,
      "audio_tokens": 0,
      "reasoning_tokens": 0
    }
  },
  "system_fingerprint": "string"
}
```

```json 400 theme={"dark"}
{
  "error": {
    "message": "string",
    "type": "string",
    "param": "string",
    "code": "string"
  }
}
```

```json 429 theme={"dark"}
{
  "error": {
    "message": "string",
    "type": "string",
    "param": "string",
    "code": "string"
  }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.