Chat completions
/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模型 ID,来自 GET /api/models/catalog。后续也可以承载
auto 或 route policy 名称。
messagesobject[]对话消息数组。role 使用 OpenAI 兼容格式:
system、user、assistant、
tool。
streamboolean设置为 true 时返回 SSE 流式响应,结尾为
data: [DONE]。
toolsobject[]工具/函数定义。发送前建议检查模型目录里的
parameters.tools。
response_formatobject结构化输出控制,例如 {"type":"json_object"}。
temperaturenumber采样温度。不同 provider 的有效范围可能不同。
max_tokensinteger最大输出 token,仍受模型上下文和输出限制约束。
消息格式
rolestringsystemuserassistanttool消息角色。
contentstring | content_part[]文本消息可直接传字符串;多模态请求可传 content parts。
tool_callsobject[]assistant 消息里的工具调用。
tool_call_idstringtool 消息需要带这个字段,用来对应上一轮 tool call。
图片输入
{
"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_tokensintegercache read tokens。
usage.prompt_tokens_details.cache_write_tokensintegerprovider 上报时返回的 cache write tokens。
usage.prompt_tokens_details.cache_miss_tokensintegerprovider 明确上报 cache miss 时返回,例如 DeepSeek 兼容字段。
完整对账信息使用请求详情 API:
curl https://api.lazu.ai/api/usage/requests/req_lazu_01ABCDEF \
-H "Authorization: Bearer $LAZU_API_KEY"