API Reference
REST API for video games, mobile apps, and web applications. Same Mimics, programmatic access.
Authentication
Include your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEY
Get your API key from onnai --apikey or your account dashboard.
Base URL
https://onnai.ai/api
Endpoints
POST /chat
Send a message to a Mimic and get a response.
// Request
{
"model": "Coder",
"message": "Review this function for bugs",
"context": "def add(a, b): return a - b"
}
// Response
{
"response": "Bug found: The function is named 'add' but performs subtraction...",
"usage": {
"input_tokens": 24,
"output_tokens": 87
}
}
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Mimic name or "onnai" for default |
message | string | Yes | User message |
context | string | No | Additional context (e.g., code, documents) |
conversation_id | string | No | Continue a previous conversation |
stream | boolean | No | Stream response via SSE |
GET /mimics
List available Mimics.
// Response
{
"mimics": [
{ "name": "Coder", "description": "Senior developer..." },
{ "name": "Writer", "description": "Technical writer..." },
...
]
}
GET /usage
Get your current usage and limits.
// Response
{
"credits_remaining": 42.50,
"credits_used": 7.50,
"requests_today": 156
}
Example: Game NPC
curl -X POST https://onnai.ai/api/chat \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "Volcanara",
"message": "What wisdom do you share with travelers?"
}'
Rate Limits
| Plan | Requests/min | Tokens/day |
|---|---|---|
| Trial | 20 | 100,000 |
| Pro | 60 | 1,000,000 |
| Enterprise | Custom | Custom |
Errors
| Code | Meaning |
|---|---|
401 | Invalid or missing API key |
402 | Insufficient credits |
404 | Mimic not found |
429 | Rate limit exceeded |
500 | Server error |