Claude Opus 4.8 API
Referensi API lengkap untuk model model bahasa besar Claude Opus 4.8 yang didukung oleh Anthropic.
Varian Model
API ini mendukung dua varian model Claude Opus 4.8:
Perbandingan Cepat
Claude Opus 4.8 Text to Text
Titik Akhir
POST /api/v1/chat/completions
Parameter Permintaan
Wajib
Dukungan Pesan
Opsional
Contoh Permintaan
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-4.8-text-to-text',
messages: [
{
role: 'user',
content: 'Draft a technical decision memo for this architecture choice.'
}
],
stream: true,
max_tokens: 2048
})
});
Claude Opus 4.8 File Analysis
Titik Akhir
POST /api/v1/chat/completions
Parameter Permintaan
Wajib
Dukungan Pesan
Opsional
Contoh Permintaan
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-4.8-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
})
});
Model LLM Claude Opus 4.8 mengembalikan respons completion yang kompatibel dengan OpenAI. Dengan stream: true, respons berupa Server-Sent Events; dengan stream: false, respons berupa satu objek JSON.
Respons Berhasil
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-opus-4.8-file-analysis","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-opus-4.8-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-opus-4.8-file-analysis","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-opus-4.8-file-analysis","choices":[],"usage":{"prompt_tokens":12,"completion_tokens":8,"total_tokens":20}}
data: [DONE]
Respons Error
event: error
data: {"error":{"message":"API requests too frequent, exceeding rate limit","type":"rate_limit_error","code":"1302","param":null}}
Praktik Terbaik
- Gunakan pesan terstruktur: Kirim riwayat percakapan melalui
messages[] alih-alih meratakan konteks menjadi satu prompt.
- Pilih varian model yang tepat: Gunakan Text to Text untuk reasoning dan penulisan teks saja, dan File Analysis saat file atau gambar diperlukan.
- Konsumsi event SSE: Tambahkan
choices[0].delta.content untuk tampilan streaming dan perlakukan data: [DONE] sebagai penyelesaian yang berhasil.
- Kirim hanya input yang didukung: Model teks mengabaikan bagian file dan gambar yang tidak didukung pada klien saat ini.