β‘ API Router β API Documentation
Intelligent AI Model Router Β· OpenAI-compatible REST API
Base URL: https://apirouter.coreinfra.eu/v1 Β·
Version: v1.0.1.3 Β·
API Version: v1
api.openai.com with apirouter.coreinfra.eu and your existing code works without changes.
π Quick Start
1. Get an API Key
Register at https://apirouter.coreinfra.eu/register, purchase a token package, then create an API key at /api-keys.
Your key format: ar-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2. Make your first request
curl -X POST https://apirouter.coreinfra.eu/v1/chat/completions \
-H "Authorization: Bearer ar-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "API Router Text",
"messages": [
{"role": "user", "content": "Hello! What can you do?"}
]
}'
3. Using with OpenAI SDK (drop-in replacement)
from openai import OpenAI
client = OpenAI(
api_key="ar-YOUR_KEY",
base_url="https://apirouter.coreinfra.eu/v1"
)
completion = client.chat.completions.create(
model="API Router Text",
messages=[{"role": "user", "content": "Hello!"}]
)
print(completion.choices[0].message.content)
π Authorization
All API endpoints require a Bearer token in the Authorization header:
Authorization: Bearer ar-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
API keys are created in the client dashboard at /api-keys. Multiple keys per account are supported with individual rate limits.
Admin API Authorization
The Admin API uses a separate token passed in the X-Admin-Key header:
X-Admin-Key: YOUR_ADMIN_TOKEN
The Admin Token is configured in config.php as DEBUG_PANEL_TOKEN.
β Error Codes
| HTTP Code | Error Type | Description |
|---|---|---|
| 400 | bad_request | Invalid JSON body or missing required field |
| 401 | unauthorized | Missing or invalid API key |
| 402 | tokens_exhausted | Token balance is zero β purchase a package |
| 403 | forbidden | Account suspended |
| 403 | prompt_injection | Safety: prompt injection detected |
| 403 | jailbreak | Safety: jailbreak attempt detected |
| 403 | pii | Safety: personal data (PII) detected in prompt |
| 404 | model_not_found | Requested model does not exist or is inactive |
| 429 | rate_limit_exceeded | Request rate limit exceeded. Check Retry-After header |
Error Response Format
{
"error": "rate_limit_exceeded",
"message": "Rate limit exceeded: 61/60 req/min. Retry after 12s."
}β± Rate Limiting
Rate limits are applied per API key, based on your subscription package. The default limit is 60 req/min.
| Response Header | Description |
|---|---|
Retry-After | Seconds to wait before retrying (only on 429) |
When a request is rate-limited, the API returns HTTP 429 with a Retry-After header.
POST /v1/chat/completions
Main API endpoint β sends a message to an AI model and returns a completion. Fully OpenAI-compatible.
Request Headers
| Header | Required | Value |
|---|---|---|
Authorization | required | Bearer <api_key> |
Content-Type | required | application/json |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
model | string | required | Virtual model name. Use GET /v1/models to list available models. |
messages | array | required | Array of message objects: [{"role":"user","content":"..."}] |
temperature | float | optional | Sampling temperature 0β2. Default: 0.7 |
max_tokens | integer | optional | Max completion tokens. Default: 1024 |
dry_run | boolean | optional | If true, returns routing info without calling the model. No token cost. |
Response β Normal
{
"object": "chat.completion",
"model": "GPT Smart",
"choices": [{
"index": 0,
"message": { "role": "assistant", "content": "Hello! I can help you with..." },
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 87,
"total_tokens": 111
},
"meta": {
"model_used": "gpt-4o-mini",
"latency_ms": 342,
"task_type": "text",
"cost_usd": 0.00001234,
"cached": false
},
"tokens_left": 48500
}Response β Cached
If an identical prompt was recently answered, the cached response is returned at 50% token cost:
{
"object": "chat.completion",
"cached": true,
"choices": [...],
"tokens_left": 48750
}Response β Queued
If all models are temporarily unavailable, the request is queued:
{
"object": "chat.completion",
"queued": true,
"queue_id": 42,
"message": "Request queued. Poll /v1/queue/42 for result.",
"tokens_left": 48500
}Response β Dry Run
{
"object": "chat.completion",
"dry_run": true,
"model": "GPT Smart",
"task_type": "code",
"would_use_model": "gpt-4o",
"predicted_latency_ms": 380,
"tokens_left": 48500
}Response β Decomposed
Complex prompts may be automatically split into subtasks (if enabled):
{
"object": "chat.completion",
"decomposed": true,
"subtasks": 3,
"choices": [{
"message": { "role": "assistant", "content": "## Content\n\n...\n\n---\n\n## Code\n\n..." }
}],
"usage": { "total_tokens": 890 }
}Examples
curl -X POST https://apirouter.coreinfra.eu/v1/chat/completions \
-H "Authorization: Bearer ar-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "API Router Text",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum computing in simple terms."}
],
"temperature": 0.7,
"max_tokens": 512
}'
GET /v1/models
Returns the list of available virtual AI models. Only virtual model names are exposed β underlying providers and real model IDs are hidden from clients.
Request Headers
| Header | Required | Value |
|---|---|---|
Authorization | required | Bearer <api_key> |
Response
{
"object": "list",
"data": [
{
"id": "API Router Text",
"object": "model",
"owned_by": "API Router",
"description": "inteligentny router modeli jΔzykowych zoptymalizowany pod kΔ
tem generowania, edycji oraz przetwarzania treΕci tekstowych. Platforma zapewnia jednolite API oraz automatyczny dobΓ³r modeli najlepiej dopasowanych do zadaΕ takich jak tworzenie artykuΕΓ³w, podsumowania, tΕumaczenia czy komunikacja konwersacyjna, maksymalizujΔ
c pΕynnoΕΔ jΔzykowΔ
i efektywnoΕΔ kosztowΔ
. CaΕym procesem rutingu, analizy typu zadania i wyboru optymalnego modelu zarzΔ
dza nasz autorski model CoreInfra MIKA 2.5",
"capabilities":["text"]
},
{
"id": "Mika 2.5",
"object": "model",
"owned_by": "API Router",
"description": "opis krΓ³tki",
"capabilities":["text"]
},
{
"id": "Mika Coder 2",
"object": "model",
"owned_by": "API Router",
"description": "Polski model jΔzykowy przeznaczony dla DEV",
"capabilities":["code"]
},
{
"id": "API Router Think",
"object": "model",
"owned_by": "API Router",
"description": "wyspecjalizowana warstwa orkiestracji modeli AI przeznaczonych do zadaΕ wymagajΔ
cych zaawansowanego rozumowania, analizy oraz rozwiΔ
zywania zΕoΕΌonych problemΓ³w. System dynamicznie dobiera modele oraz agentΓ³w o najwyΕΌszych zdolnoΕciach reasoningowych, zapewniajΔ
c optymalnΔ
jakoΕΔ odpowiedzi przy zachowaniu kontroli kosztΓ³w, wydajnoΕci i niezawodnoΕci. CaΕym procesem rutingu, analizy typu zadania i wyboru optymalnego modelu zarzΔ
dza nasz autorski model CoreInfra MIKA 2.5",
"capabilities":["text","code","translation","rag","analysis"]
},
{
"id": "ApiRouter CODE",
"object": "model",
"owned_by": "API Router",
"description": "wyspecjalizowana warstwa poΕrednia (gateway) dla modeli AI przeznaczonych do generowania i analizy kodu, ktΓ³ra dynamicznie kieruje zapytania do najlepiej dopasowanego modelu na podstawie typu zadania, zΕoΕΌonoΕci oraz kontekstu programistycznego. System zapewnia jednolite API, optymalizacjΔ kosztΓ³w i czasu odpowiedzi oraz mechanizmy fallback i monitoringu jakoΕci generowanego kodu. CaΕym procesem rutingu, analizy typu zadania i wyboru optymalnego modelu zarzΔ
dza nasz autorski model CoreInfra MIKA",
"capabilities":["code"]
}
],
"tokens_left": 48500
}Available Models
| Model ID | Description | Capabilities |
|---|---|---|
API Router Text |
inteligentny router modeli jΔzykowych zoptymalizowany pod kΔ tem generowania, edycji oraz przetwarzania treΕci tekstowych. Platforma zapewnia jednolite API oraz automatyczny dobΓ³r modeli najlepiej dopasowanych do zadaΕ takich jak tworzenie artykuΕΓ³w, podsumowania, tΕumaczenia czy komunikacja konwersacyjna, maksymalizujΔ c pΕynnoΕΔ jΔzykowΔ i efektywnoΕΔ kosztowΔ . CaΕym procesem rutingu, analizy typu zadania i wyboru optymalnego modelu zarzΔ dza nasz autorski model CoreInfra MIKA 2.5 | text |
Mika 2.5 |
opis krΓ³tki | text |
Mika Coder 2 |
Polski model jΔzykowy przeznaczony dla DEV | code |
API Router Think |
wyspecjalizowana warstwa orkiestracji modeli AI przeznaczonych do zadaΕ wymagajΔ cych zaawansowanego rozumowania, analizy oraz rozwiΔ zywania zΕoΕΌonych problemΓ³w. System dynamicznie dobiera modele oraz agentΓ³w o najwyΕΌszych zdolnoΕciach reasoningowych, zapewniajΔ c optymalnΔ jakoΕΔ odpowiedzi przy zachowaniu kontroli kosztΓ³w, wydajnoΕci i niezawodnoΕci. CaΕym procesem rutingu, analizy typu zadania i wyboru optymalnego modelu zarzΔ dza nasz autorski model CoreInfra MIKA 2.5 | text code translation rag analysis |
ApiRouter CODE |
wyspecjalizowana warstwa poΕrednia (gateway) dla modeli AI przeznaczonych do generowania i analizy kodu, ktΓ³ra dynamicznie kieruje zapytania do najlepiej dopasowanego modelu na podstawie typu zadania, zΕoΕΌonoΕci oraz kontekstu programistycznego. System zapewnia jednolite API, optymalizacjΔ kosztΓ³w i czasu odpowiedzi oraz mechanizmy fallback i monitoringu jakoΕci generowanego kodu. CaΕym procesem rutingu, analizy typu zadania i wyboru optymalnego modelu zarzΔ dza nasz autorski model CoreInfra MIKA | code |
GET /v1/tokens/balance
Returns the current token balance for the authenticated API key's account.
Response
{
"object": "token_balance",
"tokens_total": 50000,
"tokens_used": 1500,
"tokens_left": 48500,
"pct_used": 3.0,
"status": "ok"
}Example
curl https://apirouter.coreinfra.eu/v1/tokens/balance \ -H "Authorization: Bearer ar-YOUR_KEY"
POST /v1/tokens/estimate
Estimates the number of tokens and cost for a given prompt without sending it to a model. Useful for cost planning.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
messages | array | required | Message array (same format as /v1/chat/completions) |
model | string | optional | Model name to include pricing estimate |
Response
{
"object": "token_estimate",
"model": "API Router Text",
"estimated_prompt_tokens": 47,
"estimated_cost_usd": 0.00000094,
"tokens_left": 48500,
"can_afford": true,
"note": "Token count is approximate (~4 chars per token). Actual usage may differ by model."
}GET /admin-api-v1/stats
Returns system statistics for the last 24 hours. Admin only.
Request Headers
| Header | Value |
|---|---|
X-Admin-Key | Your admin token |
Response
{
"ok": true,
"total_requests_24h": 1234,
"tokens_24h": 456789,
"avg_latency_ms": 312,
"ok_count_24h": 1198,
"err_count_24h": 36,
"cost_usd_24h": 0.0042,
"queue": {
"pending": 0,
"processing": 0,
"done": 42,
"failed": 1,
"avg_wait_sec": 1.2,
"total_24h": 43
},
"cache": {
"enabled": true,
"total_entries": 89,
"total_hits": 234,
"total_kb": 124.5
},
"version": "v1.0.1.3",
"time": "2026-04-01T21:00:00+00:00"
}GET /admin-api-v1/users
Returns paginated list of client accounts with token balances. Admin only.
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
page | integer | 1 | Page number |
limit | integer | 50 | Results per page (max 100) |
Response
{
"ok": true,
"total": 48,
"page": 1,
"data": [{
"id": 12,
"first_name": "Jan",
"last_name": "Kowalski",
"email": "jan@example.com",
"status": "active",
"tokens_total": 50000,
"tokens_used": 1500,
"tokens_left": 48500,
"created_at": "2026-03-15T10:22:00"
}]
}GET /admin-api-v1/queue
Returns current queue status and pending items. Admin only.
Response
{
"ok": true,
"stats": {
"pending": 2,
"processing": 0,
"done": 41,
"failed": 0,
"total_24h": 43,
"avg_wait_sec": 1.2
},
"pending": [{
"id": 15,
"status": "pending",
"attempts": 0,
"queued_at": "2026-04-01T21:05:00",
"model": "API Router Text"
}]
}POST /admin-api-v1/users/{id}/tokens
Adds tokens to a user account. Admin only.
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | integer | User ID |
Request Body
{
"tokens": 10000,
"source": "manual_grant"
}Response
{
"ok": true,
"user_id": 12,
"tokens_added": 10000,
"new_balance": 58500
}Example
curl -X POST https://apirouter.coreinfra.eu/admin-api-v1/users/12/tokens \
-H "X-Admin-Key: YOUR_ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{"tokens": 10000, "source": "manual_grant"}'π‘ Safety Layer
All requests pass through an automatic safety filter before reaching the AI model:
- Prompt Injection detection β patterns like "ignore previous instructions", "new system message", etc.
- Jailbreak detection β patterns like "DAN mode", "developer mode", "bypass safety", etc.
- PII detection (configurable) β PESEL, IBAN, credit cards, NIP, phone numbers, email addresses.
When blocked, the API returns HTTP 403 with the reason (prompt_injection, jailbreak, or pii).
β‘ Response Cache
Identical prompts to the same virtual model are automatically cached (SHA-256 hash of normalized content). Cached responses cost 50% of normal token usage. Cache TTL is configurable (default: 24h).
Cached responses include "cached": true in the response body.
π¬ Request Queue
If all models for a virtual model are temporarily unavailable (β₯2 failures, 0 successes in 10s), requests are automatically queued. The response includes a queue_id for polling.
Queue processing is triggered by the job runner (/run?secret=TOKEN&job=queue) every 5 minutes via UptimeRobot or DirectAdmin cron.
π Task Decomposition
When enabled, complex prompts containing multiple task types (e.g., "write an article AND generate code") are automatically split into subtasks, each routed to the most suitable model. Results are merged into a single response with ## Section headers.
Indicated by "decomposed": true and "subtasks": N in the response.
π Data Models
Message Object
{
"role": "user" | "assistant" | "system",
"content": "string"
}Chat Completion Response
{
"object": "chat.completion",
"model": "string", // Virtual model name
"choices": [{
"index": 0,
"message": { "role": "assistant", "content": "string" },
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": integer,
"completion_tokens": integer,
"total_tokens": integer
},
"meta": {
"model_used": "string", // Real model ID (hidden from clients)
"latency_ms": integer,
"task_type": "text|code|analysis|translation|rag|image",
"cost_usd": float,
"cached": boolean
},
"tokens_left": integer,
"cached": boolean,
"queued": boolean,
"queue_id": integer | null,
"decomposed": boolean,
"subtasks": integer | null,
"dry_run": boolean
}Error Response
{
"error": "string", // Error type identifier
"message": "string" // Human-readable description
}π Changelog
| Version | Changes |
|---|---|
v1.0.1.3 | EUR currency support, AI translations, SEO generator, registration fixes |
v1.0.1.2 | Playground session auth, payment page, bulk model assignment, model pagination |
v1.0.1.1 | Orders panel, order number format ApiRouter/v1/XXXXXX |
v1.0.1.0 | Admin debug panel, request tracing, Ollama custom URL |
v1.0.0.17 | Initial public release β full feature set |