API Reference
API Overview
Overview of TOKI OpenAI-compatible REST API endpoints and conventions.
Base URL
All API requests should be made to:
https://www.tokiai.ai/v1Request Format
- All requests must use HTTPS
- Request bodies should be JSON-encoded
- Include
Content-Type: application/jsonheader - Include
Authorization: Bearer YOUR_API_KEYheader
Response Format
Chat completion responses follow the common OpenAI Chat Completions structure:
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1714000000,
"model": "deepseek/deepseek-chat-v3",
"choices": [...],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 20,
"total_tokens": 30
}
}Error Handling
Errors generally return appropriate HTTP status codes with a JSON error body:
| Status Code | Description |
|---|---|
| 400 | Bad Request — Invalid parameters |
| 401 | Unauthorized — Invalid API key |
| 403 | Forbidden — Insufficient permissions |
| 429 | Too Many Requests — Rate limit exceeded |
| 500 | Internal Server Error |
{
"error": {
"code": "invalid_request",
"message": "The 'model' field is required.",
"type": "invalid_request_error"
}
}Different models, quota states, and API key states may return different messages. Clients should read error.message and handle it together with the HTTP status code.
Common Endpoints
| Method | Path | Description |
|---|---|---|
POST | /chat/completions | Create a chat completion. |
GET | /models | List currently available models; availability depends on the current server implementation. |
Streaming
TOKI supports server-sent events (SSE) for streaming responses. Set stream: true in your request:
const stream = await openai.chat.completions.create({
model: 'deepseek/deepseek-chat-v3',
messages: [{ role: 'user', content: 'Tell me a story' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}