Claude Opus 5 API
由 Anthropic 提供支援的 Claude Opus 5 LLM 模型完整 API 參考。
模型變體
此 API 支援兩種 Claude Opus 5 模型變體:
快速比較
Claude Opus 5 文字轉文字
端點
POST /api/v1/chat/completions
請求參數
必填
訊息支援
選填
請求範例
const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Accept': 'text/event-stream',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'claude-opus-5-text-to-text',
messages: [
{
role: 'user',
content: '針對此架構選擇起草一份技術決策備忘錄。'
}
],
stream: true,
max_tokens: 2048
})
});
Claude Opus 5 檔案分析
端點
POST /api/v1/chat/completions
請求參數
必填
訊息支援
選填
請求範例
const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Accept': 'text/event-stream',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'claude-opus-5-file-analysis',
messages: [
{
role: 'user',
content: [
{ type: 'text', text: '摘要此檔案並擷取主要風險。' },
{
type: 'file',
file: {
filename: 'demo.pdf',
file_data: 'https://example.com/demo.pdf'
}
}
]
}
],
stream: true,
max_tokens: 4096
})
});
回應格式
Claude Opus 5 LLM 模型會傳回與 OpenAI 相容的補全回應。當 stream: true 時,回應為 Server-Sent Events;當 stream: false 時,回應為單一 JSON 物件。
成功回應
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-opus-5-file-analysis","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-opus-5-file-analysis","choices":[{"index":0,"delta":{"content":"以下是簡明摘要"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-opus-5-file-analysis","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-opus-5-file-analysis","choices":[],"usage":{"prompt_tokens":12,"completion_tokens":8,"total_tokens":20}}
data: [DONE]
錯誤回應
event: error
data: {"error":{"message":"API 請求過於頻繁,超出速率限制","type":"rate_limit_error","code":"1302","param":null}}
最佳實務
- 使用結構化訊息: 透過
messages[] 傳送對話歷史記錄,而不是將上下文合併為單一 prompt。
- 選擇正確的模型變體: 純文字推理與寫作使用文字轉文字,需要檔案或圖片時則使用檔案分析。
- 處理 SSE 事件: 附加
choices[0].delta.content 以進行串流顯示,並將 data: [DONE] 視為成功完成。
- 僅傳送支援的輸入: 目前用戶端中的文字模型會忽略不支援的檔案與圖片部分。