ឯកសារយោង
API Reference
Gateway តែមួយ ត្រូវគ្នាទាំង OpenAI និង Anthropic — ប្តូរតែ base URL ដោយរក្សា code ដដែល។
Base URLs
https://api.anajakstore.site/v1https://api.anajakstore.siteOpenAI client ភ្ជាប់ path ទៅនឹង {base}/v1។ ចំណែក Anthropic base គ្មាន /v1 — SDK នឹងបន្ថែម /v1/messages ដោយស្វ័យប្រវត្តិ។
Authentication
ភ្ជាប់ gateway key តាម header មួយណាក៏បាន។ បើផ្ញើទាំងពីរ Authorization ត្រូវយកជាធំ។
Authorization: Bearer sk-xxxxxxxxxxxx
x-api-key: sk-xxxxxxxxxxxxគ្មាន key → 401 missing_api_key។ Key មិនត្រឹមត្រូវ/ផុតកំណត់/ត្រូវ revoke → 401 invalid_api_key។ credit អស់ → 402 quota_exhausted។
Endpoints
| Method | Path | Purpose |
|---|---|---|
| GET | /v1 | ពិនិត្យ health និងរាយ endpoint |
| GET | /v1/models | រាយ model ដែល key មានសិទ្ធិប្រើ |
| GET | /v1/usage | quota និង credit ដែលនៅសល់ |
| POST | /v1/chat/completions | Chat completions (OpenAI format) |
| POST | /v1/responses | Responses (OpenAI format) |
| POST | /v1/messages | Messages (Anthropic format) |
| POST | /v1/images/generations | បង្កើតរូបភាព (OpenAI format) |
Models
Model id ទាំងអស់រាយខាងក្រោម។ ចង់បានបញ្ជីបច្ចុប្បន្នដែល key អ្នកមានសិទ្ធិ សូមហៅ GET /v1/models។
| Model | Provider | Family | Input / Output |
|---|---|---|---|
| claude-opus-4-8 | anthropic | opus | textvision in |
| claude-opus-4-7 | anthropic | opus | textvision in |
| claude-sonnet-5 | anthropic | sonnet | textvision in |
| claude-sonnet-4-6 | anthropic | sonnet | textvision in |
| claude-haiku-4-5 | anthropic | haiku | textvision in |
| gpt-5.5 | openai | codex | textvision in |
| gpt-5.4 | openai | codex | textvision in |
| gpt-5.4-mini | openai | codex | textvision in |
| gpt-4o | openai | other | textvision in |
| gpt-4 | openai | other | text |
| gpt-image-1 | openai | image | textimage out |
| dall-e-3 | openai | image | textimage out |
Alias៖ auto → claude-opus-4-8; ទម្រង់ដាក់ចុច ដូចជា claude-opus-4.8 នឹង resolve ទៅ claude-opus-4-8។ ចំពោះ model មិនស្គាល់ → 404 invalid_model។
Requests
Chat completions · OpenAI
curl https://api.anajakstore.site/v1/chat/completions \
-H "Authorization: Bearer sk-xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-4-8",
"messages": [{ "role": "user", "content": "Hello" }]
}'Messages · Anthropic
curl https://api.anajakstore.site/v1/messages \
-H "x-api-key: sk-xxxxxxxxxxxx" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-4-8",
"max_tokens": 1024,
"messages": [{ "role": "user", "content": "Hello" }]
}'Image generation · OpenAI
curl https://api.anajakstore.site/v1/images/generations \
-H "Authorization: Bearer sk-xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-1",
"prompt": "a glowing node graph, neon yellow",
"size": "1024x1024"
}'Streaming
ដាក់ "stream": true — gateway នឹងផ្ញើ text/event-stream ដោយគ្មាន buffer (no-transform)។ បើ error កើតឡើង ក្រោយ stream ចាប់ផ្តើម (HTTP បាន 200 រួចហើយ) វានឹងមកជា frame៖
event: error
data: {"error":{"message":"...","type":"api_error","code":"upstream_error"}}Usage
GET /v1/usage ត្រឡប់ quota សម្រាប់ key ដែលអ្នកបានផ្ញើ៖
{
"label": "team-key",
"tokens_total": 1000000,
"tokens_used": 12480,
"tokens_remaining": 987520,
"expires_at": "2026-12-31T00:00:00.000Z",
"status": "active",
"rate": { "khr_per_usd": 4000 }
}Errors
រាល់ error ប្រើ envelope តែមួយបែប។ Code ក៏ភ្ជាប់មកជា header x-gateway-error-code ផងដែរ។ ចំណែក error text ពី provider មិន leak ចេញឡើយ។
{
"error": {
"message": "Missing API key. Add header: Authorization: Bearer <your-key>",
"type": "authentication_error",
"code": "missing_api_key"
}
}| Code | HTTP | Type | Meaning |
|---|---|---|---|
| missing_api_key | 401 | authentication_error | គ្មាន API key ក្នុង header |
| invalid_api_key | 401 | authentication_error | Key មិនត្រឹមត្រូវ / ផុតកំណត់ / ត្រូវ revoke |
| permission_denied | 403 | permission_error | Key គ្មានសិទ្ធិលើ model នេះ |
| quota_exhausted | 402 | invalid_request_error | credit អស់ហើយ |
| rate_limit_exceeded | 429 | rate_limit_error | សំណើលឿនពេក ស្ថិតលើ rate limit |
| context_length_exceeded | 400 | invalid_request_error | context លើសកម្រិតដែលអនុញ្ញាត |
| content_policy_violation | 400 | invalid_request_error | ខ្លឹមសារបំពាន policy |
| invalid_model | 404 | invalid_request_error | Model មិនមាន ឬ key គ្មានសិទ្ធិ |
| payload_too_large | 413 | invalid_request_error | Request body ធំពេក (default 25MB) |
| invalid_json | 400 | invalid_request_error | Body មិនមែនជា JSON ត្រឹមត្រូវ |
| service_unavailable | 503 | api_error | Service កំពុងមមាញឹក សូមព្យាយាមម្តងទៀត |
| gateway_timeout | 504 | api_error | ភ្ជាប់ provider លើសពេលកំណត់ |
| upstream_error | 502 | api_error | provider បញ្ជូន error ត្រឡប់មក |
| internal_error | 500 | api_error | Gateway មាន error ដែលមិនរំពឹងទុក |