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-compatible

Chat completions

POST/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
required

模型 ID、route alias 或未來的 route policy 名稱。建議從 GET /api/models/catalog 讀取。

messagesobject[]
required

有序對話訊息。角色遵循 OpenAI shape。

rolestring
system、user、assistant 或 tool。
contentstring | content_part[]
純文字,或多模態 content parts。
tool_call_idstring
tool message 用於關聯先前的 tool call。
streamboolean
nullable

true 時返回 Server-Sent Events stream,最後以 data: [DONE] 結束。

toolsobject[]
nullable

Function/tool 定義。送出前先檢查模型 catalog 中的 parameters.tools

type"function"
目前支援 function tools。
function.namestring
模型可呼叫的工具名稱。
function.parametersobject
描述參數的 JSON Schema。
tool_choicestring | object
nullable

OpenAI-compatible tool choice 控制,例如 autonone 或指定工具物件。

response_formatobject
nullable

Structured output 控制,例如 {"type":"json_object"}

temperaturenumber
nullable

取樣溫度,多數模型接受 02

max_tokensinteger
nullable

產生 token 上限,仍受模型 context 和 output limit 限制。

Vision input

圖片輸入使用 OpenAI-compatible content parts。可以傳 HTTPS 圖片 URL 或 data URL:

Image 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

Response

idstring

Lazu 或 provider response ID。

choicesobject[]

Assistant output choices。Streaming response 會送出增量 delta

usage.prompt_tokensinteger

輸入 token 數。

usage.completion_tokensinteger

輸出 token 數。

usage.prompt_tokens_details.cached_tokensinteger
nullable

上游回報時的 cache read token。

完整對帳請使用 請求詳情

相關頁面