Skip to main content

POST /v1/completions

Generates a text completion for a given prompt string. This is the legacy completions endpoint, distinct from the chat completions endpoint. It is maintained for compatibility with older OpenAI integrations and providers that expose a complete endpoint.
For most use cases, prefer chat completions. Modern models such as GPT-4o and Claude are optimized for the chat format.

Request headers

string
The provider to route the request to (e.g. openai). Required when not using a config.
string
Your provider API key.
string
A JSON config object or config ID that defines routing, fallbacks, retries, and more.
string
A virtual key ID from Portkey Cloud that maps to a stored provider credential.

Request body

string
required
The model to use for completion (e.g. gpt-3.5-turbo-instruct).
string | string[]
required
The prompt to generate a completion for. Accepts a string or an array of strings for batched input.
number
default:"1"
Sampling temperature between 0 and 2. Higher values produce more varied output.
integer
default:"100"
The maximum number of tokens to generate in the completion.
boolean
default:"false"
When true, partial results are streamed as server-sent events and the stream ends with data: [DONE].
number
default:"1"
Nucleus sampling threshold. Only tokens within the top top_p probability mass are considered.
number
default:"0"
Number between -2.0 and 2.0. Positive values reduce repeated tokens.
number
default:"0"
Number between -2.0 and 2.0. Positive values encourage new topics.
integer
default:"1"
The number of completions to generate for each prompt.
string | string[]
One or more sequences at which to stop generating. The stop sequence is not included in the output.
integer
Include the log probabilities of the logprobs most likely tokens at each position.
boolean
default:"false"
When true, echo the prompt back in the response along with the completion.
integer
default:"1"
Generate best_of completions server-side and return the best. Incurs higher token cost.
object
A map of token IDs to bias values from -100 to 100. Adjusts the likelihood of specific tokens appearing.
integer
A seed for deterministic sampling.
string
A unique identifier for the end user, used for monitoring.

Response

string
A unique identifier for this completion.
string
Always text_completion.
integer
Unix timestamp of when the completion was created.
string
The model used for the completion.
object[]
An array of completion choices.
object
Token usage for this request.

Code examples