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-key

Keep 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/completions

Creates a model response for the given chat conversation. Fully compatible with the OpenAI Chat Completions API.

Request Body

ParameterTypeDescription
modelstringID of the model to use (e.g., gpt-4o, claude-3-5-sonnet)
messagesarrayA list of messages comprising the conversation so far
streambooleanIf true, partial message deltas will be sent as SSE events
temperaturenumberSampling temperature between 0 and 2 (default: 1)
max_tokensintegerThe maximum number of tokens to generate
top_pnumberNucleus 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/models

Lists the currently available models.

Model IDTypeDescription
gpt-4ochatOpenAI's flagship multimodal model
gpt-4o-minichatFast and affordable model for focused tasks
gpt-4-turbochatGPT-4 with vision capabilities
o1-minireasoningReasoning model optimized for STEM tasks
claude-3-5-sonnet-20241022chatAnthropic's most capable model
gemini-1.5-prochatGoogle's multimodal model with 1M context
dall-e-3imageHigh-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 CodeErrorDescription
400Bad RequestInvalid request parameters
401UnauthorizedMissing or invalid API key
402Payment RequiredInsufficient balance
429Too Many RequestsRate limit exceeded
500Internal Server ErrorUpstream API error or server fault
503Service UnavailableAll upstream providers are unavailable