Documentation
Everything you need to integrate UnityAi into your application.
Quick Start
UnityAi provides a 100% OpenAI-compatible API. Simply replace the base URL and use your UnityAi API key — no code changes required.
Python
from openai import OpenAI
client = OpenAI(
api_key="sk-your-unirouter-key",
base_url="https://api.unirouter.ai/v1"
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)Authentication
All API requests must include your API key in the Authorization header:
Authorization: Bearer sk-your-api-keyKeep your API key secure. Never expose it in client-side code or public repositories. You can manage your keys in the API Keys.
Chat Completions
POST
/v1/chat/completionsCreates a model response for the given chat conversation. Fully compatible with the OpenAI Chat Completions API.
Request Body
| Parameter | Type | Description |
|---|---|---|
| model | string | ID of the model to use (e.g., gpt-4o, claude-3-5-sonnet) |
| messages | array | A list of messages comprising the conversation so far |
| stream | boolean | If true, partial message deltas will be sent as SSE events |
| temperature | number | Sampling temperature between 0 and 2 (default: 1) |
| max_tokens | integer | The maximum number of tokens to generate |
| top_p | number | Nucleus sampling parameter (default: 1) |
Streaming
Set stream: true:
const stream = await client.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Tell me a story" }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || "");
}Models
GET
/v1/modelsLists the currently available models.
| Model ID | Type | Description |
|---|---|---|
| gpt-4o | chat | OpenAI's flagship multimodal model |
| gpt-4o-mini | chat | Fast and affordable model for focused tasks |
| gpt-4-turbo | chat | GPT-4 with vision capabilities |
| o1-mini | reasoning | Reasoning model optimized for STEM tasks |
| claude-3-5-sonnet-20241022 | chat | Anthropic's most capable model |
| gemini-1.5-pro | chat | Google's multimodal model with 1M context |
| dall-e-3 | image | High-quality image generation model |
Rate Limits
Rate limits are applied per API key using a sliding window algorithm.
Free Tier
10 RPM
10 requests per minute
Paid Tier
60 RPM
60 requests per minute
Error Codes
| HTTP Code | Error | Description |
|---|---|---|
| 400 | Bad Request | Invalid request parameters |
| 401 | Unauthorized | Missing or invalid API key |
| 402 | Payment Required | Insufficient balance |
| 429 | Too Many Requests | Rate limit exceeded |
| 500 | Internal Server Error | Upstream API error or server fault |
| 503 | Service Unavailable | All upstream providers are unavailable |