Docs
Completions
Completions
Use the completions endpoint for text completion tasks.
The completions endpoint generates text completions given a prompt. For most use cases, we recommend using chat completions instead.
Endpoint
POST https://api.elyxir.ai/v1/completions
When to Use
Use this endpoint for:
- Legacy applications using the completions API
- Simple text completion without conversation context
- Compatibility with older OpenAI SDK versions
For new applications, prefer /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 |
| prompt | string/array | Yes | Text to complete |
| max_tokens | integer | No | Maximum tokens to generate |
| temperature | number | No | Randomness (0-2, default: 1) |
| top_p | number | No | Nucleus sampling (0-1) |
| stop | string/array | No | Stop sequences |
| echo | boolean | No | Echo prompt in response |
Example Request
curl -X POST https://api.elyxir.ai/v1/completions \
-H "Authorization: Bearer elyxir_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-3.5-turbo-instruct",
"prompt": "Write a haiku about programming:",
"max_tokens": 50,
"temperature": 0.7
}'Response
Success (200 OK)
{
"id": "cmpl-abc123",
"object": "text_completion",
"created": 1234567890,
"model": "gpt-3.5-turbo-instruct",
"choices": [
{
"text": "\nCode flows like water\nBugs emerge from the depths\nDebug, iterate",
"index": 0,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 6,
"completion_tokens": 20,
"total_tokens": 26
}
}Multiple Completions
Request multiple completions with the n parameter:
{
"model": "gpt-3.5-turbo-instruct",
"prompt": "Generate a product name for a coffee shop:",
"n": 3,
"max_tokens": 20
}Response includes multiple choices:
{
"choices": [
{"text": "Bean & Brew", "index": 0},
{"text": "Morning Roast", "index": 1},
{"text": "The Daily Grind", "index": 2}
]
}Available Models
Not all models support the completions endpoint. Compatible models:
| Model | Provider |
|---|---|
| gpt-3.5-turbo-instruct | OpenAI |
| davinci-002 | OpenAI |
| babbage-002 | OpenAI |
Most modern models only support chat completions. Check model documentation for compatibility.
Migrating to Chat Completions
Convert your prompt to a messages array:
Before (Completions):
{
"model": "gpt-3.5-turbo-instruct",
"prompt": "Write a haiku about programming:"
}After (Chat Completions):
{
"model": "gpt-4o-mini",
"messages": [
{"role": "user", "content": "Write a haiku about programming:"}
]
}Related
- Chat Completions - Recommended endpoint
- API Overview - Getting started
- Error Handling - Handle errors