Claude Fable 5.1 API
由 Anthropic 提供的 Claude Fable 5.1 大型語言模型完整 API 參考文件。
模型類型
此 API 支援三種 Claude Fable 5.1 模型:
快速比較
Claude Fable 5.1 Text to Text
端點
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-fable-5.1-text-to-text',
messages: [
{
role: 'user',
content: 'Draft a technical decision memo for this architecture choice.'
}
],
stream: true,
max_tokens: 2048
})
});
Claude Fable 5.1 Web Search
端點
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-fable-5.1-web-search',
messages: [
{
role: 'user',
content: 'Find the latest public information about Claude Fable 5.1 and summarize it for a product brief.'
}
],
stream: true,
max_tokens: 2048
})
});
Claude Fable 5.1 File Analysis
端點
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-fable-5.1-file-analysis',
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'Summarize this file and extract the key risks.' },
{
type: 'file',
file: {
filename: 'demo.pdf',
file_data: 'https://example.com/demo.pdf'
}
}
]
}
],
stream: true,
max_tokens: 4096
})
});
回應格式
Claude Fable 5.1 大型語言模型傳回與 OpenAI 相容的生成回應。設定 stream: true 時,回應為伺服器傳送事件(SSE);設定 stream: false 時,回應為單一 JSON 物件。
成功回應
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-fable-5.1-file-analysis","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-fable-5.1-file-analysis","choices":[{"index":0,"delta":{"content":"Here is a concise summary"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-fable-5.1-file-analysis","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-fable-5.1-file-analysis","choices":[],"usage":{"prompt_tokens":12,"completion_tokens":8,"total_tokens":20}}
data: [DONE]
錯誤回應
event: error
data: {"error":{"message":"API requests too frequent, exceeding rate limit","type":"rate_limit_error","code":"1302","param":null}}
最佳實務
- 使用結構化訊息: 透過
messages[] 傳送對話歷程,不要將上下文合併成單一提示詞。
- 選擇適合的模型: 純文字推理使用 Text to Text,需要目前線上資訊時使用 Web Search,需要檔案或圖片時使用 File Analysis。
- 處理 SSE 事件: 附加
choices[0].delta.content 以串流顯示內容,並將 data: [DONE] 視為成功完成。
- 僅傳送支援的輸入: 不要向 Text to Text 或 Web Search 路由傳送檔案或圖片內容部分。