⚑ 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

βœ… This API is OpenAI-compatible β€” replace 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 CodeError TypeDescription
400bad_requestInvalid JSON body or missing required field
401unauthorizedMissing or invalid API key
402tokens_exhaustedToken balance is zero β€” purchase a package
403forbiddenAccount suspended
403prompt_injectionSafety: prompt injection detected
403jailbreakSafety: jailbreak attempt detected
403piiSafety: personal data (PII) detected in prompt
404model_not_foundRequested model does not exist or is inactive
429rate_limit_exceededRequest 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 HeaderDescription
Retry-AfterSeconds 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

HeaderRequiredValue
AuthorizationrequiredBearer <api_key>
Content-Typerequiredapplication/json

Request Body

FieldTypeRequiredDescription
modelstringrequiredVirtual model name. Use GET /v1/models to list available models.
messagesarrayrequiredArray of message objects: [{"role":"user","content":"..."}]
temperaturefloatoptionalSampling temperature 0–2. Default: 0.7
max_tokensintegeroptionalMax completion tokens. Default: 1024
dry_runbooleanoptionalIf 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

HeaderRequiredValue
AuthorizationrequiredBearer <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 IDDescriptionCapabilities
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.

⚠️ Token count is approximate (~4 characters per token). Actual usage may differ by model.

Request Body

FieldTypeRequiredDescription
messagesarrayrequiredMessage array (same format as /v1/chat/completions)
modelstringoptionalModel 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

HeaderValue
X-Admin-KeyYour 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

ParameterTypeDefaultDescription
pageinteger1Page number
limitinteger50Results 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

ParameterTypeDescription
idintegerUser 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:

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

VersionChanges
v1.0.1.3EUR currency support, AI translations, SEO generator, registration fixes
v1.0.1.2Playground session auth, payment page, bulk model assignment, model pagination
v1.0.1.1Orders panel, order number format ApiRouter/v1/XXXXXX
v1.0.1.0Admin debug panel, request tracing, Ollama custom URL
v1.0.0.17Initial public release β€” full feature set
API Router v1.0.1.3 Β· Powered by CoreInfra.eu Β· Back to Home