Skip to content

智谱原生协议 ​

智谱原生入口兼容 Z.AI/智谱 Chat Completions 请求和响应格式。现有客户端只需替换 API 地址、令牌和平台模型 ID。

接口与模型 ​

text
POST https://api.ezmodel.cloud/api/paas/v4/chat/completions
http
Authorization: Bearer YOUR_API_TOKEN
Content-Type: application/json

当前平台模型 ID 为 glm-5-3,请求会映射到上游 glm-5.3,因此响应中的 model 为 glm-5.3。请以 GET /v1/models 返回的模型列表为准,不要直接把上游名称当作平台模型 ID。

glm-5-3 为强制思考模型,不支持 thinking.type=disabled。请使用 reasoning_effort: "low"、"high" 或 "max"。

普通请求 ​

bash
curl https://api.ezmodel.cloud/api/paas/v4/chat/completions \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "glm-5-3",
    "messages": [{"role": "user", "content": "你好"}],
    "reasoning_effort": "low",
    "max_tokens": 256,
    "stream": false
  }'

响应保留上游返回的智谱扩展字段,包括 request_id、reasoning_content、content_filter、web_search 和 token 用量明细。

流式响应 ​

设置 "stream": true 后返回 SSE:

text
data: {"object":"chat.completion.chunk", ...}

data: {"choices":[{"finish_reason":"stop", ...}],"usage":{...}}

data: [DONE]

最终数据块包含 token 用量,并以 data: [DONE] 结束。

Function Calling ​

Function Calling 采用标准两阶段流程。第一次请求声明函数:

json
{
  "model": "glm-5-3",
  "messages": [{"role": "user", "content": "查询北京天气"}],
  "reasoning_effort": "low",
  "tools": [{
    "type": "function",
    "function": {
      "name": "get_weather",
      "description": "查询指定城市天气",
      "parameters": {
        "type": "object",
        "properties": {"city": {"type": "string"}},
        "required": ["city"]
      }
    }
  }],
  "tool_choice": "auto"
}

模型返回 finish_reason: "tool_calls" 和 tool_calls[].id 后,客户端负责执行函数。第二次请求必须先放入模型返回的完整 assistant 消息,再追加使用相同 ID 的 tool 消息:

json
{
  "model": "glm-5-3",
  "messages": [
    {"role": "user", "content": "查询北京天气"},
    {
      "role": "assistant",
      "content": "",
      "tool_calls": [{
        "id": "call_xxx",
        "type": "function",
        "function": {
          "name": "get_weather",
          "arguments": "{\"city\":\"北京\"}"
        }
      }]
    },
    {
      "role": "tool",
      "tool_call_id": "call_xxx",
      "content": "{\"temperature\":\"20°C\",\"condition\":\"晴\"}"
    }
  ],
  "reasoning_effort": "low",
  "tools": [{
    "type": "function",
    "function": {
      "name": "get_weather",
      "description": "查询指定城市天气",
      "parameters": {
        "type": "object",
        "properties": {"city": {"type": "string"}},
        "required": ["city"]
      }
    }
  }]
}

这两个阶段是两次独立模型请求,分别计算输入、输出 token。EZModel 不对 Function Calling 额外收取工具附加费;外部函数本身的费用由函数服务提供方决定。

json
{
  "model": "glm-5-3",
  "messages": [{"role": "user", "content": "搜索 Z.AI 官方文档"}],
  "reasoning_effort": "low",
  "tools": [{
    "type": "web_search",
    "web_search": {
      "enable": true,
      "search_engine": "search_std",
      "search_query": "Z.AI 官方文档",
      "search_result": true,
      "count": 3
    }
  }]
}

搜索执行成功时,响应顶层包含 web_search 数组。EZModel 以该字段作为实际调用证据:每个完成请求最多计一次搜索,返回多条搜索结果不会重复计次;请求声明了工具但响应没有 web_search 时不收搜索附加费。

Web Search 按美元 $0.01/次 收费,并与模型 token 费用相加。价格变化以 Z.AI 官方定价 为准。

SDK 配置 ​

python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_TOKEN",
    base_url="https://api.ezmodel.cloud/api/paas/v4/",
)

response = client.chat.completions.create(
    model="glm-5-3",
    messages=[{"role": "user", "content": "你好"}],
    extra_body={"reasoning_effort": "low"},
)
print(response.choices[0].message.content)

范围与限制 ​

  • 原生入口当前覆盖同步和流式 Chat Completions。
  • 模型映射、渠道参数覆盖和可选系统提示可能调整请求;其他智谱扩展字段按原生 JSON 转发。
  • 本接口不提供智谱异步任务、独立 Web Search Broker、文件、知识库生命周期或视频接口。
  • retrieval、托管 MCP 等能力即使协议字段可转发,也不代表当前账号拥有对应资源或订阅;请勿使用其他租户或平台运营方创建的资源 ID。

智谱字段的完整定义参见 Z.AI Chat Completion API。

企业合作联系:service@ezmodel.cloud