跳转到主要内容
POST
/
v1
/
chat
/
completions
curl --request POST \
  --url https://api.powertokens.ai/v1/chat/completions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "glm-5-turbo",
  "messages": [
    {
      "role": "system",
      "content": "你是一个简洁专业的助手。"
    },
    {
      "role": "user",
      "content": "请用三句话介绍一下向量数据库。"
    }
  ],
  "temperature": 0.7,
  "max_tokens": 1024
}
'
{
  "id": "chatcmpl_zhipu_123",
  "object": "chat.completion",
  "created": 1775174400,
  "model": "glm-5",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "向量数据库是一种专门存储和检索向量表示的数据系统,常用于语义搜索、推荐和 RAG。",
        "reasoning_content": "先给出定义,再补充典型场景。"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 42,
    "completion_tokens": 31,
    "total_tokens": 73,
    "prompt_tokens_details": {
      "cached_tokens": 0
    }
  }
}

授权

Authorization
string
header
必填

在请求头中传入 Authorization: Bearer <token>

请求体

application/json

智谱 chat completions 请求体。

model
enum<string>
必填

模型名称。支持的模型包括 glm-5-turboglm-5glm-4.7glm-4.7-flashglm-4.5-air

可用选项:
glm-5-turbo,
glm-5,
glm-4.7,
glm-4.7-flash,
glm-4.5-air
示例:

"glm-5-turbo"

messages
object[]
必填

消息列表。支持纯文本消息,以及包含 image_url 分片的图像输入。请求中至少需要包含一条非 system、非 assistant 的消息;不能只传 system 消息或只传 assistant 消息。

Minimum array length: 1
stream
boolean
默认值:false

是否启用流式输出。为 true 时返回 text/event-stream

thinking
object

思考模式配置。适用于支持 thinking 参数的模型。

temperature
number
默认值:1

采样温度,取值范围为 [0, 1]

必填范围: 0 <= x <= 1
top_p
number
默认值:0.95

核采样概率阈值,取值范围为 [0.01, 1]

必填范围: 0.01 <= x <= 1
max_tokens
integer

最大输出 token 数。

必填范围: x >= 1
stop
string[]

停止词列表。当前仅支持单个停止词。

Maximum array length: 1
tools
object[]

工具定义列表。当前仅支持 function 工具形态。

Maximum array length: 128
tool_choice
enum<string>
默认值:auto

工具选择策略。智谱该接口当前仅公开 auto

可用选项:
auto

响应

调用成功。非流式模式返回 JSON;流式模式返回 SSE 事件流。

非流式对话补全响应。

id
string

响应 ID。

object
string

对象类型。

示例:

"chat.completion"

created
integer<int64>

Unix 时间戳(秒)。

model
string

实际使用的模型名称。

choices
object[]

模型返回的候选结果。

usage
object

Token 使用统计。