進階調用
在各模型已核驗的能力範圍內使用串流輸出、函式工具、結構化輸出、圖像輸入和快取。
先檢查模型能力
每個模型頁會公佈上下文、輸出上限、協定和支援參數。未核驗的參數會被拒絕,不會被靜默改寫。
串流輸出
僅在所選模型列出 stream 能力時設為 true。讀取伺服器推送事件直到 [DONE]。若輸出開始後收到錯誤事件,請把部分輸出視為未完成並核對請求紀錄。
函式工具
每個請求最多包含 64 個函式定義。函式名稱最多 100 個字元,描述最多 5,000 個字元。應用程式執行傳回的工具調用後,應使用相符的 tool_call_id 傳送 tool 訊息。
POST https://chuaone.si/v1/chat/completions
{
"model": "YOUR_ALLOWED_MODEL",
"messages": [
{
"role": "user",
"content": "What is the weather in Hong Kong?"
}
],
"max_tokens": 256,
"stream": false,
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Read current weather",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string"
}
},
"required": [
"city"
],
"additionalProperties": false
},
"strict": true
}
}
],
"tool_choice": "auto"
}結構化 JSON
僅在模型列出 response_format 時使用該參數。json_object 要求有效 JSON。部分相容協定也支援 json_schema,使用前請核對具體模型頁。
{
"model": "YOUR_ALLOWED_MODEL",
"messages": [
{
"role": "user",
"content": "Return one JSON object with a summary field."
}
],
"max_tokens": 128,
"stream": false,
"response_format": {
"type": "json_object"
}
}圖像輸入
- 僅為列出 vision 的模型傳送 image_url 內容。通用協定接受公共 HTTPS 位址,或有大小限制的 PNG、JPEG、WebP、GIF data URL。
- 完整 JSON 請求內容不得超過 2 MiB。圖像輸入會在派發前按完整上下文保守預留,完成後按已確認用量結算。
- Haiku 5.5 的已核驗線路接受 Base64 圖像,並要求省略 detail 或設為 auto。
快取用量
供應商確認快取讀取或寫入後,usage.prompt_tokens_details 會報告相應數量,並按該模型已公佈的快取價格組成計費。僅把已報告的快取明細視為確認用量。
查看用量與扣費