> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.beatapi.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.beatapi.io/_mcp/server.

# GLM Chat Completions

POST https://direct.beatapi.io/v1/chat/completions
Content-Type: application/json

用一个 BeatAPI 密钥，通过同一个 OpenAI Chat Completions 端点调用 GLM 5.3、5.3 Flash 和 5.3 FlashX。- 一个端点 `POST /v1/chat/completions` 覆盖当前所有 GLM 模型，改 `model` 即可切换。
- 三个模型都支持流式输出，上下文 100 万 token，最大输出 128,000 token。
- 整个上下文窗口按统一的 token 单价计费，没有长上下文档位，也没有高峰时段加价。缓存输入按更低的费率计费。
- 兼容 OpenAI SDK：改 base URL，换成 BeatAPI 密钥即可。
- 同样的模型也可以用 [OpenAI Responses](/text-api/glm/responses) 和 [Anthropic Messages](/text-api/glm/messages) 调用。文本请求建议使用 `https://direct.beatapi.io` 作为 base URL：它不受 Cloudflare 100 秒限制，长时间的非流式请求不会被中途切断。`https://api.beatapi.io` 同样可用；如果你的网络访问不了 `direct.beatapi.io`，请改用它作为备用。两个域名的密钥、模型和价格完全一致。图片和视频 API 只使用 `https://api.beatapi.io`。POST/v1/chat/completions试一试在调试窗口里打开本接口，填入你的 BeatAPI API 密钥即可发送。调用是真实的，费用从你自己的余额中扣除。## 模型把下列 ID 之一作为 `model` 发送。它们是各自独立的模型，不是互相的别名。| 模型 ID            | 上下文（tokens） | 最大输出（tokens） | 定位                                | 输入，美元 / 100 万 tokens | 输出，美元 / 100 万 tokens | 说明                                                         |
| ---------------- | ----------- | ------------ | --------------------------------- | -------------------- | -------------------- | ---------------------------------------------------------- |
| `glm-5.3`        | 1,000,000   | 128,000      | GLM 旗舰模型，面向长程编程、智能体与复杂项目交付        | \$0.98               | \$3.08               | 旗舰模型，面向长程编程、智能体与复杂项目交付。上下文 100 万 token，最大输出 128,000 token。 |
| `glm-5.3-flash`  | 1,000,000   | 128,000      | 原生多模态 GLM 模型，面向高效编程与长程智能体任务       | \$0.105              | \$0.35               | 原生多模态版本，面向高效编程与长程智能体任务，是系列中价格最低的付费模型。                      |
| `glm-5.3-flashx` | 1,000,000   | 128,000      | GLM-5.3-Flash 的高速服务版本，面向编程与智能体工作流 | \$0.259              | \$0.875              | `glm-5.3-flash` 的高速服务版本，价格更高。免费额度账户不能调用。                   |- 价格为基础档，已计入折扣。长上下文档、缓存命中输入价和缓存写入价不在本表内，见[价格表](https://beatapi.io/pricing)。
- `—` 表示目录未公布该数字。## 快速开始在服务端安装 `openai` 包，把密钥放在 `BEATAPI_API_KEY`，不要把它写进浏览器代码。以下是请求示例，不是真实的模型输出记录。从 `choices[0].message.content` 读取答案，再检查 `finish_reason` 和 `usage`。HTTP 200 不能证明答案满足你的任务，请在应用里校验内容。文本请求直接返回，不要为它们轮询 `/v1/tasks`。```bash title="cURL"
curl --request POST \
  --url https://direct.beatapi.io/v1/chat/completions \
  --header "Authorization: Bearer $BEATAPI_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "glm-5.3",
  "max_tokens": 2000,
  "messages": [
    {
      "role": "user",
      "content": "Design a resilient webhook retry strategy for a payments API."
    }
  ]
}'
``````python title="Python"
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["BEATAPI_API_KEY"], base_url="https://direct.beatapi.io/v1")
completion = client.chat.completions.create(
    model="glm-5.3",
    max_tokens=2000,
    messages=[
      {
        "role": "user",
        "content": "Design a resilient webhook retry strategy for a payments API."
      }
    ],
)
print(completion.choices[0].message.content)
``````javascript title="JavaScript"
import OpenAI from "openai";

const client = new OpenAI({ apiKey: process.env.BEATAPI_API_KEY, baseURL: "https://direct.beatapi.io/v1" });
const completion = await client.chat.completions.create({
  "model": "glm-5.3",
  "max_tokens": 2000,
  "messages": [
    {
      "role": "user",
      "content": "Design a resilient webhook retry strategy for a payments API."
    }
  ]
});
console.log(completion.choices[0].message.content);
```## 免费版本这些模型有免费版本。免费版本不按 token 计费，用免费模型 ID 在同一个端点调用，并有单独的每分钟限额：首次充值前每个账号每分钟 1 次成功请求，充值后每分钟 10 次。它不保证稳定，随时可能被限流或下架。详见[免费模型](/free-models)。| 模型 ID                | 付费版             | 价格 |
| -------------------- | --------------- | -- |
| `glm-5.3-free`       | `glm-5.3`       | 免费 |
| `glm-5.3-flash-free` | `glm-5.3-flash` | 免费 |### `glm-5.3-free````bash title="cURL"
curl --request POST \
  --url https://direct.beatapi.io/v1/chat/completions \
  --header "Authorization: Bearer $BEATAPI_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "glm-5.3-free",
  "messages": [
    {
      "role": "user",
      "content": "Say hello in one sentence."
    }
  ]
}'
``````python title="Python"
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["BEATAPI_API_KEY"], base_url="https://direct.beatapi.io/v1")
completion = client.chat.completions.create(
    model="glm-5.3-free",
    messages=[
      {
        "role": "user",
        "content": "Say hello in one sentence."
      }
    ],
)
print(completion.choices[0].message.content)
``````javascript title="JavaScript"
import OpenAI from "openai";

const client = new OpenAI({ apiKey: process.env.BEATAPI_API_KEY, baseURL: "https://direct.beatapi.io/v1" });
const completion = await client.chat.completions.create({
  "model": "glm-5.3-free",
  "messages": [
    {
      "role": "user",
      "content": "Say hello in one sentence."
    }
  ]
});
console.log(completion.choices[0].message.content);
```### `glm-5.3-flash-free````bash title="cURL"
curl --request POST \
  --url https://direct.beatapi.io/v1/chat/completions \
  --header "Authorization: Bearer $BEATAPI_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "glm-5.3-flash-free",
  "messages": [
    {
      "role": "user",
      "content": "Say hello in one sentence."
    }
  ]
}'
``````python title="Python"
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["BEATAPI_API_KEY"], base_url="https://direct.beatapi.io/v1")
completion = client.chat.completions.create(
    model="glm-5.3-flash-free",
    messages=[
      {
        "role": "user",
        "content": "Say hello in one sentence."
      }
    ],
)
print(completion.choices[0].message.content)
``````javascript title="JavaScript"
import OpenAI from "openai";

const client = new OpenAI({ apiKey: process.env.BEATAPI_API_KEY, baseURL: "https://direct.beatapi.io/v1" });
const completion = await client.chat.completions.create({
  "model": "glm-5.3-flash-free",
  "messages": [
    {
      "role": "user",
      "content": "Say hello in one sentence."
    }
  ]
});
console.log(completion.choices[0].message.content);
```## 端点与鉴权`POST https://direct.beatapi.io/v1/chat/completions`Authorization
string
必需`Bearer <BEATAPI_API_KEY>`。密钥带不带 `sk-` 前缀都可以。## 请求参数接受标准的 OpenAI Chat Completions 字段。请求格式兼容，不代表每个模型都支持所有选项，请对你依赖的选项自行测试。model
string
必需准确的模型 ID。**可选值**：`glm-5.3`, `glm-5.3-flash`, `glm-5.3-flashx`- 每个 ID 都是独立的模型，不是其他模型的别名。
- 用你的密钥调用 `GET /v1/models`，确认该密钥已开通哪些模型。messages
object[]
必需对话内容，最早的消息在前。每条消息有 `role`（`system`、`user`、`assistant` 或 `tool`）和 `content`。max_tokens
integer
可选生成 token 数的上限，包含推理部分。- 网关不会拿你的值去和上面表格里的最大输出比较，请自己控制在该数字以内。
- `max_tokens` 也用来估算一次请求需要多少余额。值特别大时，即使实际输出很短，也可能被 `402 insufficient_credits` 拒绝。按实际需要设置即可。推理型号会先输出推理内容。`max_tokens` 太小时，推理可能把额度用完：`content` 为空，`finish_reason` 是 `length`。请给推理和正文都留出空间，看到 `length` 就调大。stream
boolean
可选默认值: false以服务端推送事件（SSE）返回答案。见下文「流式输出」。**默认值**：`false`temperature
number
可选采样温度。它和 `top_p` 调一个就行，不要两个一起改。top_p
number
可选核采样阈值。stop
string | string[]
可选一个或多个停止序列，生成到这些序列时停止。tools
object[]
可选模型可以调用的函数定义。模型会用 `tool_calls` 作答；把每个结果放进后续的 `tool` 消息，并带上对应的 `tool_call_id`。tool_choice
string | object
可选控制模型可以、必须或不得调用工具。请用你的模型测试你依赖的取值。## 响应非流式调用返回一个 JSON 对象。以下是精简后的示例。```json
{
  "id": "chatcmpl-example",
  "object": "chat.completion",
  "created": 1791993600,
  "model": "glm-5.3",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Retry with exponential backoff and jitter, and make every handler idempotent."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 19,
    "completion_tokens": 16,
    "total_tokens": 35
  }
}
```### 响应字段| 字段                                    | 类型         | 说明                                                              |
| ------------------------------------- | ---------- | --------------------------------------------------------------- |
| `id`                                  | `string`   | 补全 ID。请连同请求 ID 一起记录，方便售后和对账。                                    |
| `model`                               | `string`   | 实际作答的模型。                                                        |
| `choices[].message.content`           | `string`   | 答案文本。                                                           |
| `choices[].message.reasoning_content` | `string`   | 推理文本，仅推理型号会返回。按输出计费。                                            |
| `choices[].message.tool_calls`        | `object[]` | 模型要求你执行的函数调用。`finish_reason` 为 `tool_calls` 时出现。                |
| `choices[].finish_reason`             | `string`   | `stop` 表示完整作答，`tool_calls` 表示要调用工具，`length` 表示达到了 `max_tokens`。 |
| `usage`                               | `object`   | token 数量。调用按实际 token 用量计量。                                      |## 流式输出设置 `"stream": true`。答案以 `chat.completion.chunk` 事件逐段到达，最后以 `data: [DONE]` 结束。- 响应类型是 `text/event-stream`；不流式时是 `application/json`。
- 文本在 `choices[0].delta.content` 里。推理型号会先在 `delta.reasoning_content` 里发送推理内容。
- 调用模型之前就失败的请求，返回的是带 HTTP 状态码的普通 JSON 错误，而不是流事件。
- 请设置明确的超时，并安全地重连流式响应。```text
data: {"id":"chatcmpl-example","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":"Retry"},"finish_reason":null}]}

data: {"id":"chatcmpl-example","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" with backoff"},"finish_reason":null}]}

data: {"id":"chatcmpl-example","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]
```## 错误| 错误或现象                                   | 原因                                  | 处理                            |
| --------------------------------------- | ----------------------------------- | ----------------------------- |
| `content` 为空，`finish_reason` 是 `length` | 推理型号把整个 `max_tokens` 额度都用在了推理上。     | 调大 `max_tokens`，但不要超过模型的最大输出。 |
| `402 insufficient_credits`              | 余额低于这次请求的价格，常见原因是 `max_tokens` 特别大。 | 充值，或调小 `max_tokens`。          |
| `403 forbidden`                         | 账户只有免费额度而该模型不在免费列表里，或该模型不在密钥所属分组内。  | 充值、改用免费模型，或换一把分组能访问该模型的密钥。    |
| `404 not_found`                         | 模型 ID 不存在，或该密钥没有开通。                 | 用 `GET /v1/models` 列出已开通的模型。  |
| `429 rate_limit_exceeded`               | 达到账户或免费模型的频率限制。                     | 等待 `Retry-After` 指定的时间后重试。    |### HTTP 错误速查认证、路由、限速和未知模型这几类失败发生在调用模型之前，返回 BeatAPI 信封：`error.code`、`error.message`、`retryable`、`request_id`。其余失败保持 OpenAI SDK 格式 `{"error": {"message", "type", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾。详见[错误码](/errors#text-endpoints)。| HTTP 状态码 | 错误码                                                      | 怎么做                                             |
| -------- | -------------------------------------------------------- | ----------------------------------------------- |
| 400      | `bad_request`、`content_policy_violation`                 | 修正请求或输入，不要原样重发。                                 |
| 401      | `missing_api_key`、`invalid_api_key`                      | 检查密钥，不要重试。                                      |
| 402      | `insufficient_credits`                                   | 充值，或提高密钥额度。过大的 `max_tokens` 也可能触发。              |
| 403      | `forbidden`                                              | 模型不在该密钥的分组或 IP 白名单内，或免费额度不能调用该模型。               |
| 404      | `not_found`                                              | 模型不存在：用 `GET /v1/models` 查看已开通的模型。              |
| 429      | `rate_limit_exceeded`                                    | 等待 `Retry-After` 或 `retry_after_seconds` 后退避重试。 |
| 500      | `internal_error`、`temporary_error`                       | 退避后重试一两次。                                       |
| 503      | `model_unavailable`、`upstream_timeout`、`temporary_error` | 退避重试，或换用其他模型。                                   |完整的错误码表和重试策略见[错误码](/errors#text-endpoints)。## 注意事项- GLM 模型也可以用 [OpenAI Responses](/text-api/glm/responses) 和 [Anthropic Messages](/text-api/glm/messages) 调用。
- GLM 模型在实测中默认会返回推理内容。推理 token 按输出计费，所以 `max_tokens` 要同时为推理和答案留足空间。
- `glm-5.3-flashx` 不能用免费额度调用：从未充值的账户会收到 `403 forbidden`，充值后才能使用。
- `thinking`、`reasoning_effort` 这类推理开关在 GLM 上是否生效没有保证，请不要依赖它们。
- `glm-5.3-free` 和 `glm-5.3-flash-free` 是单独的免费模型 ID，在这个端点上用完整的 ID 调用。详见[免费模型](/free-models)。
- 密钥只放在可信的服务端，记录响应里的请求 ID，只对 `429`、`500` 和 `503` 重试。

Reference: https://docs.beatapi.io/api-reference/text-api/glm-chat-completions

## Authentication

- `Authorization` header (bearer token, required) — Send your API key as `Authorization: Bearer <BEATAPI_API_KEY>`.

## Servers

- `https://direct.beatapi.io` (Direct, default)
- `https://api.beatapi.io` (API)

## Request

### Body (application/json)

This endpoint expects an object.

- `model` (enum, required) — 准确的模型 ID。 每个 ID 都是独立的模型，不是其他模型的别名。 用你的密钥调用 `GET /v1/models`，确认该密钥已开通哪些模型。 `glm-5.3`, `glm-5.3-flash`, `glm-5.3-flashx`
  - Allowed values: `glm-5.3`, `glm-5.3-flash`, `glm-5.3-flashx`, `glm-5.3-free`, `glm-5.3-flash-free`
- `messages` (list of V1ChatCompletionsPostRequestBodyContentApplicationJsonSchemaMessagesItems, required) — 对话内容，最早的消息在前。每条消息有 `role`（`system`、`user`、`assistant` 或 `tool`）和 `content`。
- `max_tokens` (integer, optional) — 生成 token 数的上限，包含推理部分。 网关不会拿你的值去和上面表格里的最大输出比较，请自己控制在该数字以内。 `max_tokens` 也用来估算一次请求需要多少余额。值特别大时，即使实际输出很短，也可能被 `402 insufficient_credits` 拒绝。按实际需要设置即可。 推理型号会先输出推理内容。`max_tokens` 太小时，推理可能把额度用完：`content` 为空，`finish_reason` 是 `length`。请给推理和正文都留出空间，看到 `length` 就调大。
- `stream` (boolean, optional, default: false) — 以服务端推送事件（SSE）返回答案。见下文「流式输出」。
- `temperature` (double, optional) — 采样温度。它和 `top_p` 调一个就行，不要两个一起改。
- `top_p` (double, optional) — 核采样阈值。
- `stop` (V1ChatCompletionsPostRequestBodyContentApplicationJsonSchemaStop, optional) — 一个或多个停止序列，生成到这些序列时停止。
- `tools` (list of V1ChatCompletionsPostRequestBodyContentApplicationJsonSchemaToolsItems, optional) — 模型可以调用的函数定义。模型会用 `tool_calls` 作答；把每个结果放进后续的 `tool` 消息，并带上对应的 `tool_call_id`。
- `tool_choice` (V1ChatCompletionsPostRequestBodyContentApplicationJsonSchemaToolChoice, optional) — 控制模型可以、必须或不得调用工具。请用你的模型测试你依赖的取值。

## Response

### 200

非流式调用返回一个 JSON 对象。以下是精简后的示例。

- `id` (string, optional) — 补全 ID。请连同请求 ID 一起记录，方便售后和对账。
- `model` (string, optional) — 实际作答的模型。
- `choices` (list of V1ChatCompletionsPostResponsesContentApplicationJsonSchemaChoicesItems, optional)
- `usage` (V1ChatCompletionsPostResponsesContentApplicationJsonSchemaUsage, optional) — token 数量。调用按实际 token 用量计量。

## Errors

### 400 Bad Request Error

`bad_request`、`content_policy_violation` 修正请求或输入，不要原样重发。 认证、路由、限速和未知模型这几类失败发生在调用模型之前，返回 BeatAPI 信封：`error.code`、`error.message`、`retryable`、`request_id`。其余失败保持 OpenAI SDK 格式 `{"error": {"message", "type", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾。详见[错误码](/errors#text-endpoints)。

- `map from string to any`

### 401 Unauthorized Error

`missing_api_key`、`invalid_api_key` 检查密钥，不要重试。 认证、路由、限速和未知模型这几类失败发生在调用模型之前，返回 BeatAPI 信封：`error.code`、`error.message`、`retryable`、`request_id`。其余失败保持 OpenAI SDK 格式 `{"error": {"message", "type", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾。详见[错误码](/errors#text-endpoints)。

- `map from string to any`

### 402 Payment Required Error

`insufficient_credits` 充值，或提高密钥额度。过大的 `max_tokens` 也可能触发。 认证、路由、限速和未知模型这几类失败发生在调用模型之前，返回 BeatAPI 信封：`error.code`、`error.message`、`retryable`、`request_id`。其余失败保持 OpenAI SDK 格式 `{"error": {"message", "type", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾。详见[错误码](/errors#text-endpoints)。

- `map from string to any`

### 403 Forbidden Error

`forbidden` 模型不在该密钥的分组或 IP 白名单内，或免费额度不能调用该模型。 认证、路由、限速和未知模型这几类失败发生在调用模型之前，返回 BeatAPI 信封：`error.code`、`error.message`、`retryable`、`request_id`。其余失败保持 OpenAI SDK 格式 `{"error": {"message", "type", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾。详见[错误码](/errors#text-endpoints)。

- `map from string to any`

### 404 Not Found Error

`not_found` 模型不存在：用 `GET /v1/models` 查看已开通的模型。 认证、路由、限速和未知模型这几类失败发生在调用模型之前，返回 BeatAPI 信封：`error.code`、`error.message`、`retryable`、`request_id`。其余失败保持 OpenAI SDK 格式 `{"error": {"message", "type", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾。详见[错误码](/errors#text-endpoints)。

- `map from string to any`

### 429 Too Many Requests Error

`rate_limit_exceeded` 等待 `Retry-After` 或 `retry_after_seconds` 后退避重试。 认证、路由、限速和未知模型这几类失败发生在调用模型之前，返回 BeatAPI 信封：`error.code`、`error.message`、`retryable`、`request_id`。其余失败保持 OpenAI SDK 格式 `{"error": {"message", "type", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾。详见[错误码](/errors#text-endpoints)。

- `map from string to any`

### 500 Internal Server Error

`internal_error`、`temporary_error` 退避后重试一两次。 认证、路由、限速和未知模型这几类失败发生在调用模型之前，返回 BeatAPI 信封：`error.code`、`error.message`、`retryable`、`request_id`。其余失败保持 OpenAI SDK 格式 `{"error": {"message", "type", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾。详见[错误码](/errors#text-endpoints)。

- `map from string to any`

### 503 Service Unavailable Error

`model_unavailable`、`upstream_timeout`、`temporary_error` 退避重试，或换用其他模型。 认证、路由、限速和未知模型这几类失败发生在调用模型之前，返回 BeatAPI 信封：`error.code`、`error.message`、`retryable`、`request_id`。其余失败保持 OpenAI SDK 格式 `{"error": {"message", "type", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾。详见[错误码](/errors#text-endpoints)。

- `map from string to any`

## Types

### V1ChatCompletionsPostRequestBodyContentApplicationJsonSchemaMessagesItems

- `role` (string, required)
- `content` (V1ChatCompletionsPostRequestBodyContentApplicationJsonSchemaMessagesItemsContent, optional, nullable)
- `name` (string, optional)
- `tool_call_id` (string, optional)
- `tool_calls` (list of V1ChatCompletionsPostRequestBodyContentApplicationJsonSchemaMessagesItemsToolCallsItems, optional)

### V1ChatCompletionsPostRequestBodyContentApplicationJsonSchemaStop

一个或多个停止序列，生成到这些序列时停止。

### V1ChatCompletionsPostRequestBodyContentApplicationJsonSchemaToolsItems

### V1ChatCompletionsPostRequestBodyContentApplicationJsonSchemaToolChoice

控制模型可以、必须或不得调用工具。请用你的模型测试你依赖的取值。

### V1ChatCompletionsPostResponsesContentApplicationJsonSchemaChoicesItems

- `message` (V1ChatCompletionsPostResponsesContentApplicationJsonSchemaChoicesItemsMessage, optional)
- `finish_reason` (string, optional) — `stop` 表示完整作答，`tool_calls` 表示要调用工具，`length` 表示达到了 `max_tokens`。

### V1ChatCompletionsPostResponsesContentApplicationJsonSchemaUsage

token 数量。调用按实际 token 用量计量。

### V1ChatCompletionsPostRequestBodyContentApplicationJsonSchemaMessagesItemsContent

### V1ChatCompletionsPostRequestBodyContentApplicationJsonSchemaMessagesItemsToolCallsItems

### V1ChatCompletionsPostResponsesContentApplicationJsonSchemaChoicesItemsMessage

- `content` (string, optional) — 答案文本。
- `reasoning_content` (string, optional) — 推理文本，仅推理型号会返回。按输出计费。
- `tool_calls` (list of V1ChatCompletionsPostResponsesContentApplicationJsonSchemaChoicesItemsMessageToolCallsItems, optional) — 模型要求你执行的函数调用。`finish_reason` 为 `tool_calls` 时出现。

### V1ChatCompletionsPostResponsesContentApplicationJsonSchemaChoicesItemsMessageToolCallsItems

## Examples

**Request**

```json
{
  "model": "glm-5.3",
  "messages": [
    {
      "role": "user",
      "content": "Design a resilient webhook retry strategy for a payments API."
    }
  ],
  "max_tokens": 2000
}
```

**Response**

```json
{
  "id": "chatcmpl-example",
  "model": "glm-5.3",
  "choices": [
    {
      "message": {
        "content": "Retry with exponential backoff and jitter, and make every handler idempotent.",
        "role": "assistant"
      },
      "finish_reason": "stop",
      "index": 0
    }
  ],
  "usage": {
    "completion_tokens": 16,
    "prompt_tokens": 19,
    "total_tokens": 35
  },
  "created": 1791993600,
  "object": "chat.completion"
}
```

**SDK Code**

```python 快速开始
import requests

url = "https://direct.beatapi.io/v1/chat/completions"

payload = {
    "model": "glm-5.3",
    "messages": [
        {
            "role": "user",
            "content": "Design a resilient webhook retry strategy for a payments API."
        }
    ],
    "max_tokens": 2000
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript 快速开始
const url = 'https://direct.beatapi.io/v1/chat/completions';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"glm-5.3","messages":[{"role":"user","content":"Design a resilient webhook retry strategy for a payments API."}],"max_tokens":2000}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go 快速开始
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://direct.beatapi.io/v1/chat/completions"

	payload := strings.NewReader("{\n  \"model\": \"glm-5.3\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Design a resilient webhook retry strategy for a payments API.\"\n    }\n  ],\n  \"max_tokens\": 2000\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby 快速开始
require 'uri'
require 'net/http'

url = URI("https://direct.beatapi.io/v1/chat/completions")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model\": \"glm-5.3\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Design a resilient webhook retry strategy for a payments API.\"\n    }\n  ],\n  \"max_tokens\": 2000\n}"

response = http.request(request)
puts response.read_body
```

```java 快速开始
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://direct.beatapi.io/v1/chat/completions")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"glm-5.3\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Design a resilient webhook retry strategy for a payments API.\"\n    }\n  ],\n  \"max_tokens\": 2000\n}")
  .asString();
```

```php 快速开始
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://direct.beatapi.io/v1/chat/completions', [
  'body' => '{
  "model": "glm-5.3",
  "messages": [
    {
      "role": "user",
      "content": "Design a resilient webhook retry strategy for a payments API."
    }
  ],
  "max_tokens": 2000
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp 快速开始
using RestSharp;

var client = new RestClient("https://direct.beatapi.io/v1/chat/completions");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model\": \"glm-5.3\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Design a resilient webhook retry strategy for a payments API.\"\n    }\n  ],\n  \"max_tokens\": 2000\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 快速开始
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "glm-5.3",
  "messages": [
    [
      "role": "user",
      "content": "Design a resilient webhook retry strategy for a payments API."
    ]
  ],
  "max_tokens": 2000
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://direct.beatapi.io/v1/chat/completions")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```