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

FieldTypeRequiredDescription
modelstringYesMimic name or "onnai" for default
messagestringYesUser message
contextstringNoAdditional context (e.g., code, documents)
conversation_idstringNoContinue a previous conversation
streambooleanNoStream 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

PlanRequests/minTokens/day
Trial20100,000
Pro601,000,000
EnterpriseCustomCustom

Errors

CodeMeaning
401Invalid or missing API key
402Insufficient credits
404Mimic not found
429Rate limit exceeded
500Server error