跳转到内容
中文

GLM-5.3 API

POST Base URL: https://api.hiapi.ai /v1/chat/completions

该模型使用兼容 OpenAI 的 Chat Completions 接口。同一个 HiAPI API Key 可调用账户分组内已开放模型;切换到图片、视频或音频模型时,需要改用 /v1/tasks 及对应请求结构。

模型概览

模型名称glm-5.3
提供方Zhipu AI
类型文本生成 · Chat Completions
输入 / 输出文本 / 文本
价格HiAPI 实时 Token 价格

GLM-5.3 是智谱面向 ZCode 发布的旗舰模型。HiAPI 当前通过兼容 OpenAI 的 Chat Completions 接口提供文本输入和文本输出。

生产建议

请求契约
  • 向 POST /v1/chat/completions 发送请求,model 填 glm-5.3,并使用 messages。同一个 HiAPI API Key 可调用已开放模型;媒体模型使用不同请求结构的 /v1/tasks。
  • 本页记录当前 HiAPI 请求契约。响应可能在 assistant 消息中包含 reasoning_content;当前不提供可选择的推理开关或 effort 映射。

适用场景

文本对话

使用兼容 OpenAI 的请求结构完成服务端文本生成。

messages
流式应用

客户端需要增量输出时设置 stream=true。

stream

请求参数

model string 必填

固定填写 glm-5.3。

示例 glm-5.3 可选值: glm-5.3
messages array 必填

按顺序传入对话消息。

role enum 必填

消息角色。

可选值: systemuserassistanttool
content string 必填

消息文本。

示例 Explain HTTP caching in three short paragraphs.
stream boolean 可选

设为 true 返回 Server-Sent Events。

默认 false
max_tokens integer 可选

可选的输出 Token 上限;请求总长度必须适合当前接入可用的上下文。

示例 1024
response_format object 可选

Use type=json_object for JSON Mode.

tools array 可选

OpenAI-compatible function definitions.

tool_choice string | object 可选

Use required to force a function call, or auto for optional calls.

API 接入示例

调用示例

流式响应

将 stream 设置为 true,持续处理 SSE chunk,直到 [DONE]。

请求体
{
  "model": "glm-5.3",
  "messages": [
    {
      "role": "system",
      "content": "You are a concise technical assistant."
    },
    {
      "role": "user",
      "content": "Explain HTTP caching in three short paragraphs."
    }
  ],
  "stream": true
}
JSON Mode

设置 response_format.type=json_object,并将返回的 message content 按 JSON 解析。

请求体
{
  "model": "glm-5.3",
  "messages": [
    {
      "role": "user",
      "content": "Return JSON with a single string field named answer. The value should be yes."
    }
  ],
  "stream": false,
  "response_format": {
    "type": "json_object"
  }
}
函数工具调用

声明函数、执行返回的工具调用,再带回 assistant 工具调用消息和对应的工具结果继续请求。

请求体
{
  "model": "glm-5.3",
  "messages": [
    {
      "role": "user",
      "content": "What is the weather in Shanghai? Use the function."
    }
  ],
  "stream": false,
  "tool_choice": "required",
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get weather for a city.",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {
              "type": "string"
            }
          },
          "required": [
            "city"
          ]
        }
      }
    }
  ]
}

响应结构

非流式响应遵循 Chat Completions 结构。思考模式会额外返回 reasoning_content;计费明细以 usage 为准。

{
  "id": "chatcmpl_example",
  "object": "chat.completion",
  "model": "glm-5.3",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "HTTP 缓存会保存可复用的响应。",
        "reasoning_content": "先判断问题范围,再给出简短回答。"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 24,
    "completion_tokens": 18,
    "total_tokens": 42
  }
}
  1. 从 choices[0].message.content 读取最终文本;响应中也可能包含 reasoning_content。
  2. 流式调用拼接 choices[0].delta.content,并处理 [DONE]。
  3. 从 usage 读取输入、输出和总 Token 数。

常见问题

应该使用哪个接口和模型 ID?

使用 POST /v1/chat/completions,并将 model 设置为 glm-5.3。

可以复用 OpenAI SDK 客户端吗?

可以。将 base_url 设置为 https://api.hiapi.ai/v1,使用 HiAPI API Key,通过 chat.completions.create 传入 messages。

支持 JSON Mode 和函数工具吗?

支持。JSON Mode 使用 response_format.type=json_object。函数调用使用兼容 OpenAI 的 tools;执行返回的工具调用后,带回原 assistant.tool_calls 和匹配的 role=tool 消息继续请求。

同一个 API Key 可以调用媒体模型吗?

可以,前提是账户已开放对应模型。媒体生成使用 POST /v1/tasks,端点和请求结构不同。

Token 如何计费?

请查看 HiAPI 实时定价页和请求返回的 usage 对象,不要把上游或第三方聚合站价格直接用于集成。 查看实时价格。

下一步