Skip to content

Completions (Legacy)

POST /v1/completions

Generate a text completion for a given prompt. Compatible with the OpenAI Completions API.

ParameterTypeRequiredDescription
modelstringYesModel ID (see Models)
promptstring | string[]YesThe prompt(s) to generate completions for
streambooleanNoStream partial deltas as SSE. Default: false
stream_optionsobjectNo{ "include_usage": true } to include token counts in the final stream event
temperaturenumberNoSampling temperature, 0–2
top_pnumberNoNucleus sampling threshold, 0–1
nintegerNoNumber of completions to generate, 1–128
max_tokensintegerNoMaximum tokens to generate
stopstring | string[]NoUp to 4 stop sequences
frequency_penaltynumberNoFrequency penalty, -2 to 2
presence_penaltynumberNoPresence penalty, -2 to 2
logprobsintegerNoInclude log probabilities on the most likely tokens (0–5)
echobooleanNoEcho the prompt in addition to the completion
best_ofintegerNoGenerate best_of completions and return the best. Cannot be used with stream
suffixstringNoSuffix that comes after the completion
seedintegerNoSeed for deterministic sampling
userstringNoEnd-user identifier for abuse tracking
{
"id": "cmpl-abc123",
"object": "text_completion",
"created": 1700000000,
"model": "google/gemma-3-27b-it",
"choices": [
{
"text": "Hello! How can I help you?",
"index": 0,
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 5,
"completion_tokens": 7,
"total_tokens": 12
}
}
FieldTypeDescription
idstringUnique completion ID
objectstringAlways "text_completion"
createdintegerUnix timestamp
modelstringModel used
choicesarrayCompletion choices
choices[].textstringGenerated text
choices[].indexintegerChoice index
choices[].logprobsobject | nullLog probability info, if requested
choices[].finish_reasonstring"stop" or "length"
usageobjectToken usage statistics
Terminal window
curl https://api.aiand.com/v1/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemma-3-27b-it",
"prompt": "Write a haiku about programming:",
"max_tokens": 30
}'

Set stream: true to receive partial completions as server-sent events.

Terminal window
curl https://api.aiand.com/v1/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemma-3-27b-it",
"prompt": "Once upon a time",
"max_tokens": 50,
"stream": true
}'

Each event contains a data: line with a JSON chunk. The stream ends with data: [DONE].