API Reference
AIOrouter provides an OpenAI-compatible REST API. All requests use JSON and Bearer token authentication.
Base URL: https://api.aiorouter.ca/v1
Authentication
All requests require an API key passed as a Bearer token:
Authorization: Bearer aiorouter_<your-api-key>
API keys can be created and managed from the Dashboard.
Headers
| Header | Required | Description |
|---|---|---|
Authorization |
Yes | Bearer aiorouter_<key> |
Content-Type |
Yes | application/json |
API-Version |
No | API version date (default: 2026-06-01) |
X-Request-Id |
No | Unique request ID for tracing |
Endpoints
POST /v1/chat/completions
Create a chat completion. Supports streaming and non-streaming modes.
Request Body:
| Parameter | Type | Required | Description |
|---|---|---|---|
model |
string | Yes | Model ID (e.g., deepseek-v4-pro, qwen3-235b) |
messages |
array | Yes | Array of message objects with role and content |
temperature |
number | No | Sampling temperature (0–2, default: 1) |
max_tokens |
integer | No | Maximum tokens to generate |
top_p |
number | No | Nucleus sampling parameter (0–1) |
stream |
boolean | No | Enable SSE streaming (default: false) |
stop |
string/array | No | Stop sequences |
tools |
array | No | Function definitions for tool calling |
tool_choice |
string/object | No | Tool selection strategy |
response_format |
object | No | { "type": "json_object" } for JSON mode |
Example Response (non-streaming):
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1717545600,
"model": "deepseek-v4-pro",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 20,
"total_tokens": 30
}
}
Streaming (SSE):
Set "stream": true to receive Server-Sent Events:
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello"}}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"!"}]}}
data: [DONE]
Function Calling:
{
"model": "deepseek-v4-pro",
"messages": [{"role": "user", "content": "What's the weather in Montreal?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"}
},
"required": ["location"]
}
}
}]
}
GET /v1/models
List all available models.
Response:
{
"object": "list",
"data": [
{
"id": "deepseek-v4-pro",
"object": "model",
"created": 1717545600,
"owned_by": "deepseek"
}
]
}
GET /v1/models/:modelId
Get details for a specific model.
Response Headers
| Header | Description |
|---|---|
X-Provider |
The AI provider that served the request |
X-Automated-Decision |
Transparency header (Law 25 compliance) |
X-Request-Id |
Echo of the request ID |
API-Version |
API version used |
Error Codes
| Status | Code | Description |
|---|---|---|
| 400 | invalid_request |
Malformed request body or parameters |
| 401 | authentication_error |
Invalid or missing API key |
| 402 | insufficient_quota |
Quota exceeded or insufficient credits |
| 429 | rate_limit_exceeded |
Too many requests |
| 500 | api_error |
Internal server error |
| 503 | service_unavailable |
All providers temporarily unavailable |
Rate Limits
| Plan | Rate Limit |
|---|---|
| Developer | 60 requests/minute |
| Business | 300 requests/minute |
| Unverified | 10 requests/minute |
Rate limit headers are included in responses: X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset.
Streaming Best Practices
- Set a reasonable
max_tokensto avoid unbounded streams - Handle
[DONE]signal to properly close connections - Use exponential backoff with jitter for reconnection
- Monitor the
X-Providerheader for routing transparency