Chat Completions
Full reference for the POST /api/v1/chat/completions endpoint.
POST /api/v1/chat/completions
Creates a chat completion. Accepts an array of messages and returns an OpenAI-format response with the model's answer.
Request
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer <token>. Any token is accepted. |
Content-Type | Yes | Must be application/json. |
HTTP-Referer | No | Site URL (OpenRouter compat). |
X-OpenRouter-Title | No | Site name (OpenRouter compat). |
Body
| Field | Type | Default | Description |
|---|---|---|---|
model | string | "puma/cheapest" | Model alias or Workers AI model name. |
messages | array | (required) | List of chat messages. |
temperature | number | — | Not forwarded yet. |
max_tokens | integer | — | Not forwarded yet. |
stream | boolean | — | Must be false or omitted. |
Each message in the messages array has:
| Field | Type | Description |
|---|---|---|
role | "system" | "user" | "assistant" | Who sent the message. |
content | string | The message text. |
Response
200 — Success
{
"id": "chatcmpl-550e8400-e29b-41d4-a716-446655440000",
"object": "chat.completion",
"created": 1712345678,
"model": "puma/cheapest",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The meaning of life is a philosophical question…"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
}
}Note:
usagetoken counts are currently0. Workers AI models can return usage data but it varies by model and is not yet surfaced.
400 — Bad Request
{
"error": {
"message": "messages array is required and must not be empty",
"code": "bad_request"
}
}401 — Unauthorized
{
"error": {
"message": "Missing or invalid Authorization header",
"code": "unauthorized"
}
}500 — Server Error
{
"error": {
"message": "AI binding not configured",
"code": "server_error"
}
}Examples
Minimal request
curl https://api.pumaai.com/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-test-123" \
-d '{
"messages": [
{"role": "user", "content": "What is the meaning of life?"}
]
}'With system prompt
curl https://api.pumaai.com/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-test-123" \
-H "HTTP-Referer: https://myapp.com" \
-H "X-OpenRouter-Title: My App" \
-d '{
"model": "puma/cheapest",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the meaning of life?"}
]
}'