Referensi API
Dokumentasi API ZigaRouter
ZigaRouter kompatibel dengan pola OpenAI. Arahkan SDK yang sudah Anda pakai ke https://zigarouter.bond/api/v1 tanpa mengubah konfigurasi lain. Semua contoh di bawah memakai base URL produksi.
Mulai Cepat
- 1. Buat akun dan terbitkan API Key di Dashboard → API Keys. Secret hanya ditampilkan sekali.
- 2. Ganti base URL klien OpenAI Anda dengan URL gateway ZigaRouter.
- 3. Gunakan slug yang terdaftar di katalog model — lihat /models.
curl https://zigarouter.bond/api/v1/chat/completions \
-H "Authorization: Bearer zr_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"model": "zigalabs/zigal-chat",
"messages": [{"role": "user", "content": "Jelaskan apa itu API gateway dalam dua kalimat."}],
"stream": false,
"temperature": 0.7,
"max_tokens": 512,
"usage": {"include": true}
}'5 language examples available: javascript,python,go,php.
Lebih suka SDK? Gateway bekerja dengan SDK OpenAI resmi untuk JavaScript, Python, Go, dan PHP dengan mengatur base_url to the URL di atas dan API Key ZigaRouter Anda sebagai API key.
Autentikasi
Kirim API Key Anda sebagai bearer token:
Authorization: Bearer zr_live_...API Key memakai prefix zr_live_ or zr_test_. API Key yang hilang atau tidak valid gagal dengan invalid_api_key (HTTP 401). Never commit a secret to source control — revoke and recreate if you do.
Chat completions
POST /api/v1/chat/completions accepts the OpenAI chat schema:
{
"model": "anthropic/claude-sonnet-4.5",
"messages": [{"role": "user", "content": "Hello"}],
"stream": false,
"temperature": 0.7,
"top_p": 1,
"max_tokens": 512,
"stop": ["\n\n"],
"frequency_penalty": 0,
"presence_penalty": 0,
"tools": [],
"tool_choice": "auto",
"response_format": {"type": "json_object"},
"provider": {"sort": "balanced", "allow_fallbacks": true},
"usage": {"include": true}
}With usage.include the response carries prompt_tokens, completion_tokens, total_tokens and cost (USD string, 6 decimals), plus a request_id you can quote in support requests.
Streaming
Set stream: true to receive text/event-stream chunks shaped like OpenAI chat.completion.chunk, terminated by data: [DONE]. Chunks are forwarded as they arrive — no full buffering. Once the first chunk is delivered the request is never retried on another provider; a mid-stream failure closes the stream with a consistent error event instead of switching providers.
curl https://zigarouter.bond/api/v1/chat/completions \
-H "Authorization: Bearer zr_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o-mini",
"messages": [{"role": "user", "content": "Tulis haiku tentang failover."}],
"stream": true,
"temperature": 0.7,
"max_tokens": 256,
"usage": {"include": true}
}'5 language examples available: javascript,python,go,php.
Provider routing
Objek provider berikut bersifat khusus ZigaRouter:
- sort
- price | latency | throughput | balanced | order
- only
- array of provider slugs to allow exclusively
- ignore
- array of provider slugs to exclude
- allow_fallbacks
- retry on another endpoint before the stream starts (default true)
Routing memvalidasi request, model, saldo, dan rate limit, lalu membuang endpoint yang tidak sehat atau circuit-open, lalu mengurutkan kandidat dengan sort, lalu mengirim request. Kegagalan sebelum stream dimulai dicoba ulang pada fallback dengan exponential backoff dan jitter.
Models endpoint
GET /api/v1/models returns { object: 'list', data: [...] } with ZigaRouter extensions: slug, publisher, description, context_length, capabilities, modalities, pricing (input_per_million, output_per_million, currency), providers, status and updated_at.
Browse the same data in the model directory.
Errors
Every error response uses the same envelope, and the HTTP status always matches the error category:
{
"error": {
"message": "The selected model is temporarily unavailable.",
"type": "provider_error",
"code": "provider_unavailable",
"request_id": "req_01J..."
}
}| Kode | HTTP | Arti |
|---|---|---|
| invalid_api_key | 401 | missing, unknown or revoked key |
| email_not_verified | 403 | account pending verification |
| insufficient_credits | 402 | balance cannot cover the reservation |
| rate_limit_exceeded | 429 | key/user/IP rate limit or spend limit |
| model_not_found | 404 | slug not in the catalog |
| model_unavailable | 503 | no healthy provider endpoint |
| unsupported_parameter | 400 | parameter not supported by the target |
| invalid_request | 400 | schema validation failure |
| context_length_exceeded | 400 | prompt too long |
| provider_timeout | 504 | upstream timeout, no fallback left |
| provider_error | 502 | upstream failure, no fallback left |
| internal_error | 500 | unexpected |
Every response also carries an X-Request-Id header.
Usage & cost
Siklus billing per request: reservation hold → settlement sesuai pemakaian aktual → pelepasan sisa hold. Kegagalan tanpa usage yang dapat ditagih melepas hold. Saldo yang tidak cukup gagal lebih awal dengan insufficient_credits (HTTP 402) sebelum request di-routing.
Pantau pengeluaran di Credits & Billing dashboard or the Activity log, yang mencatat token, latensi, provider, status, dan biaya per request — tanpa isi prompt.
Langkah berikutnya
