Skip to main content
The /v1/completions endpoint takes a raw text prompt and returns one or more generated continuations. Unlike the chat endpoint, there is no message array or role structure — you supply a prompt string and the model completes it. This format is well-suited for single-turn tasks such as summarization, extraction, code generation, and template-based workflows.

Endpoint

Request Parameters

string
required
The ID of the model to use. Call GET /v1/models to retrieve the list of models available to your account.
string | array
required
The prompt(s) to complete. Pass a single string for one prompt or an array of strings to batch multiple prompts in a single request.
integer
The maximum number of tokens to generate per completion. Defaults to the model’s context limit. Use this to cap response length and manage costs.
number
Sampling temperature between 0 and 2. Higher values produce more varied output; lower values produce more deterministic output. Defaults to 1. Avoid combining with top_p.
number
Nucleus sampling threshold between 0 and 1. The model samples from the smallest token set whose cumulative probability exceeds this value. Defaults to 1. Avoid combining with temperature.
boolean
When true, the API streams token deltas as server-sent events and sends a final [DONE] message. Defaults to false.
string | array
One or more sequences at which generation stops. Pass a single string or an array of up to four strings.
integer
The number of independent completions to generate for each prompt. Defaults to 1. Note that generating multiple completions increases token usage proportionally.

Request Examples

Response Fields

string
A unique identifier for this completion, prefixed with cmpl-.
string
Always "text_completion".
integer
Unix timestamp (seconds) of when the completion was created.
string
The model ID that was used to generate this response.
array
An array of generated completion objects. Contains one element per prompt per n.
object
Token usage statistics for the request.

Example Response