Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content
接口 / OpenAI 兼容

Chat completions

POST/v1/chat/completions

通过 Lazu 发送 OpenAI 兼容的对话请求。本页直接包含 base URL、鉴权、请求字段、响应 usage、流式输出、工具调用和请求详情查询,不需要跳到单独的 OpenAPI Explorer 页面。

基础配置

SDK base_url

OpenAI SDK 使用 https://api.lazu.ai/v1

模型发现

生产代码应先读取 GET /api/models/catalog,筛选 supported_endpoint_types 包含 chat 的模型。

请求 Body

modelstring
required

模型 ID,来自 GET /api/models/catalog。后续也可以承载 auto 或 route policy 名称。

messagesobject[]
required

对话消息数组。role 使用 OpenAI 兼容格式: systemuserassistanttool

streamboolean
nullable

设置为 true 时返回 SSE 流式响应,结尾为 data: [DONE]

toolsobject[]
nullable

工具/函数定义。发送前建议检查模型目录里的 parameters.tools

response_formatobject
nullable

结构化输出控制,例如 {"type":"json_object"}

temperaturenumber
nullable

采样温度。不同 provider 的有效范围可能不同。

max_tokensinteger
nullable

最大输出 token,仍受模型上下文和输出限制约束。

消息格式

rolestring
required
systemuserassistanttool

消息角色。

contentstring | content_part[]
required

文本消息可直接传字符串;多模态请求可传 content parts。

tool_callsobject[]
nullable

assistant 消息里的工具调用。

tool_call_idstring
nullable

tool 消息需要带这个字段,用来对应上一轮 tool call。

图片输入

Vision input
json
{
"model": "gpt-4o",
"messages": [
  {
    "role": "user",
    "content": [
      {"type": "text", "text": "What's in this image?"},
      {
        "type": "image_url",
        "image_url": {"url": "data:image/png;base64,..."}
      }
    ]
  }
]
}

PDF 和大文件应该使用 Files + Responses。Chat completions 不会自动读取

file_id

响应 usage 和 cache 字段

usage.prompt_tokensinteger

输入 token。

usage.completion_tokensinteger

输出 token。

usage.prompt_tokens_details.cached_tokensinteger
nullable

cache read tokens。

usage.prompt_tokens_details.cache_write_tokensinteger
nullable

provider 上报时返回的 cache write tokens。

usage.prompt_tokens_details.cache_miss_tokensinteger
nullable

provider 明确上报 cache miss 时返回,例如 DeepSeek 兼容字段。

完整对账信息使用请求详情 API:

Request detail
bash
curl https://api.lazu.ai/api/usage/requests/req_lazu_01ABCDEF \
-H "Authorization: Bearer $LAZU_API_KEY"

相关页面