Chat completions
/v1/chat/completions透過 Lazu 發送 OpenAI-compatible chat 請求。Base URL、認證、必要 body 欄位、stream、tools、response usage 和排障入口都在這一頁。
基本設定
Base URL
使用 https://api.lazu.ai/v1 搭配 OpenAI SDK,或直接呼叫完整
path https://api.lazu.ai/v1/chat/completions。
模型發現
執行時讀取 GET /api/models/catalog,並篩選
supported_endpoint_types 包含 chat 的模型。
請求 Body
modelstring模型 ID、route alias 或未來的 route policy 名稱。建議從
GET /api/models/catalog 讀取。
messagesobject[]有序對話訊息。角色遵循 OpenAI shape。
rolestringcontentstring | content_part[]tool_call_idstringstreamboolean為 true 時返回 Server-Sent Events stream,最後以
data: [DONE] 結束。
toolsobject[]Function/tool 定義。送出前先檢查模型 catalog 中的
parameters.tools。
type"function"function.namestringfunction.parametersobjecttool_choicestring | objectOpenAI-compatible tool choice 控制,例如 auto、
none
或指定工具物件。
response_formatobjectStructured output 控制,例如 {"type":"json_object"}。
temperaturenumber取樣溫度,多數模型接受 0 到 2。
max_tokensinteger產生 token 上限,仍受模型 context 和 output limit 限制。
Vision input
圖片輸入使用 OpenAI-compatible content parts。可以傳 HTTPS 圖片 URL 或 data URL:
{
"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。
Response
idstringLazu 或 provider response ID。
choicesobject[]Assistant output choices。Streaming response 會送出增量 delta。
usage.prompt_tokensinteger輸入 token 數。
usage.completion_tokensinteger輸出 token 數。
usage.prompt_tokens_details.cached_tokensinteger上游回報時的 cache read token。
完整對帳請使用 請求詳情。