Referensi API lengkap untuk model bahasa besar Grok 4.7 dari xAI.
Varian Model
API ini mendukung satu varian model:
Perbandingan Singkat
Grok 4.7
Endpoint
POST /api/v1/chat/completions
Parameter Permintaan
Wajib
Konten Pesan yang Didukung
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: 'grok-4.7',
messages: [
{
role: 'user',
content: 'Explain how a browser caches an image in two sentences.'
}
],
stream: true,
max_tokens: 2048,
reasoning_effort: 'medium'
})
});
Grok 4.7 mengembalikan respons penyelesaian yang kompatibel dengan OpenAI. Jika stream: true, respons dikirim sebagai peristiwa dari server (SSE). Jika stream: false atau stream tidak disertakan, respons berupa satu objek JSON.
Respons Berhasil
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"grok-4.7","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"grok-4.7","choices":[{"index":0,"delta":{"reasoning_content":"Explain cache reuse."},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"grok-4.7","choices":[{"index":0,"delta":{"content":"The browser saves a copy of the image. It reuses the copy while it is fresh."},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"grok-4.7","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]
Respons Kesalahan
data: {"error":{"message":"API requests too frequent, exceeding rate limit","type":"rate_limit_error","code":"1302","param":null}}
Praktik Terbaik
- Gunakan pesan terstruktur untuk mengirim riwayat percakapan melalui
messages[].
- Lampirkan gambar dalam konten pesan dengan menambahkan blok
image_url ke messages[].content.
- Proses peristiwa SSE dengan menggabungkan isi
choices[0].delta.content secara berurutan dan menggunakan data: [DONE] sebagai penanda akhir aliran.