Chat Completions
Use the chat completions endpoint to create conversational AI responses.
The chat completions endpoint creates AI responses for conversational messages. This is the primary endpoint for most applications.
Endpoint
POST https://api.elyxir.ai/v1/chat/completions
Request
Headers
| Header | Required | Description |
|---|---|---|
| Authorization | Yes | Bearer token: Bearer elyxir_xxx |
| Content-Type | Yes | Must be application/json |
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID, or alvin for auto-routing |
messages | array | Yes | Array of message objects |
temperature | number | No | Randomness (0-2, default: 1) |
max_tokens | integer | No | Maximum response tokens |
stream | boolean | No | Enable streaming (default: false) |
stream_options | object | No | e.g. {"include_usage": true} to get token counts on the final chunk |
top_p | number | No | Nucleus sampling (0-1) |
stop | string/array | No | Stop sequences |
presence_penalty | number | No | Penalize new topics (-2 to 2) |
frequency_penalty | number | No | Penalize repetition (-2 to 2) |
tools | array | No | Function tools the model may call |
tool_choice | string/object | No | auto, none, required, or a named tool |
response_format | object | No | e.g. {"type": "json_object"} for JSON output |
Not every model supports every parameter — tool calling and structured output in particular vary by provider. Check the model in the Model Hub if a parameter appears to be ignored.
Message Object
| Field | Type | Required | Description |
|---|---|---|---|
role | string | Yes | system, user, assistant, or tool |
content | string | array | Yes | Text, or an array of content parts for vision |
Vision
Pass an array of content parts to send images to a vision-capable model:
{
"model": "gpt-5.5",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}
]
}
]
}A base64 data URI works in place of an HTTPS URL.
Example Request
curl -X POST https://api.elyxir.ai/v1/chat/completions \
-H "Authorization: Bearer elyxir_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
],
"temperature": 0.7,
"max_tokens": 150
}'Response
Success (200 OK)
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1234567890,
"model": "gpt-4o-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of France is Paris."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 10,
"total_tokens": 35
}
}Response Fields
| Field | Description |
|---|---|
| id | Unique completion ID |
| object | Object type (chat.completion) |
| created | Unix timestamp |
| model | Model used for completion |
| choices | Array of completion choices |
| usage | Token usage statistics |
Finish Reasons
| Reason | Description |
|---|---|
| stop | Natural completion or stop sequence |
| length | Hit max_tokens limit |
| content_filter | Filtered by content moderation |
Multi-turn Conversations
Include previous messages for context:
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is Python?"},
{"role": "assistant", "content": "Python is a programming language..."},
{"role": "user", "content": "How do I install it?"}
]
response = requests.post(
"https://api.elyxir.ai/v1/chat/completions",
headers=headers,
json={"model": "gpt-4o-mini", "messages": messages}
)Streaming
Enable streaming for real-time responses:
curl -X POST https://api.elyxir.ai/v1/chat/completions \
-H "Authorization: Bearer elyxir_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Tell me a story"}],
"stream": true
}'Streaming returns Server-Sent Events (SSE):
data: {"id":"chatcmpl-abc","choices":[{"delta":{"content":"The"}}]}
data: {"id":"chatcmpl-abc","choices":[{"delta":{"content":" capital"}}]}
data: [DONE]
Add "stream_options": {"include_usage": true} to receive token counts on the final chunk — otherwise a streamed response carries no usage block.
Alvin auto-routing
Set model to alvin and Alvin picks the model per request. The response reports what it chose:
| Header | Description |
|---|---|
X-Alvin-Model | The model that handled the request |
X-Alvin-Task-Type | The task class assigned to the prompt |
X-Alvin-Confidence | Classification confidence, 0.00–1.00 |
The same information appears in a routing field in the response body. See Alvin routing.
alvin was called elyxir-alvin until August 2026. Both names route identically; existing integrations need no change.
Available Models
| Model | Provider | Best For |
|---|---|---|
alvin | Elyxir | Auto-routing — Alvin picks the model |
gpt-5.5 | OpenAI | Current flagship, complex reasoning |
gpt-5-mini | OpenAI | Balanced, cost-effective |
gpt-4o-mini | OpenAI | Cheapest general-purpose chat |
claude-opus-4.8 | Anthropic | Agentic coding, hardest tasks |
claude-sonnet-4.6 | Anthropic | Coding and agents |
claude-haiku-4.5 | Anthropic | Fast, affordable |
gemini-3.5-flash | Fast, long context | |
gemini-2.5-pro | Balanced, 1M context | |
grok-4.3 | xAI | Cost-efficient reasoning |
perplexity-sonar | Perplexity | Web-grounded answers |
This is a shortlist. Call GET /v1/models for the live catalog, or see Supported models for the full list with pricing.
Error Responses
| Status | Meaning |
|---|---|
| 400 | Bad request (invalid parameters) |
| 401 | Authentication failed |
| 402 | Insufficient credits |
| 429 | Rate limit exceeded |
| 500 | Server error |
See Error Handling for details.
Related
- API Overview - Getting started
- Authentication - API key setup
- Memory - Persistent user and project memory