Completions (Legacy)
POST /v1/completionsGenerate a text completion for a given prompt. Compatible with the OpenAI Completions API.
Request body
Section titled “Request body”| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID (see Models) |
prompt | string | string[] | Yes | The prompt(s) to generate completions for |
stream | boolean | No | Stream partial deltas as SSE. Default: false |
stream_options | object | No | { "include_usage": true } to include token counts in the final stream event |
temperature | number | No | Sampling temperature, 0–2 |
top_p | number | No | Nucleus sampling threshold, 0–1 |
n | integer | No | Number of completions to generate, 1–128 |
max_tokens | integer | No | Maximum tokens to generate |
stop | string | string[] | No | Up to 4 stop sequences |
frequency_penalty | number | No | Frequency penalty, -2 to 2 |
presence_penalty | number | No | Presence penalty, -2 to 2 |
logprobs | integer | No | Include log probabilities on the most likely tokens (0–5) |
echo | boolean | No | Echo the prompt in addition to the completion |
best_of | integer | No | Generate best_of completions and return the best. Cannot be used with stream |
suffix | string | No | Suffix that comes after the completion |
seed | integer | No | Seed for deterministic sampling |
user | string | No | End-user identifier for abuse tracking |
Response
Section titled “Response”{ "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 }}Fields
Section titled “Fields”| Field | Type | Description |
|---|---|---|
id | string | Unique completion ID |
object | string | Always "text_completion" |
created | integer | Unix timestamp |
model | string | Model used |
choices | array | Completion choices |
choices[].text | string | Generated text |
choices[].index | integer | Choice index |
choices[].logprobs | object | null | Log probability info, if requested |
choices[].finish_reason | string | "stop" or "length" |
usage | object | Token usage statistics |
Example
Section titled “Example”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 }'Streaming
Section titled “Streaming”Set stream: true to receive partial completions as server-sent events.
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].