POST
/
v1
/
completions
curl -X POST https://api.example.com/v1/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-3.5-turbo-instruct",
    "prompt": "Hello,",
    "max_tokens": 30,
    "temperature": 0
  }'
{
  "id": "cmpl-ByvHP6AWeB1L5vWZSPNHsB12sU9db",
  "object": "text_completion",
  "created": 1753859563,
  "model": "gpt-3.5-turbo-instruct",
  "choices": [
    {
      "index": 0,
      "logprobs": null,
      "finish_reason": "length",
      "text": "I am an AI assistant. How can I help you today?"
    }
  ],
  "usage": {
    "prompt_tokens": 3,
    "completion_tokens": 30,
    "total_tokens": 33
  }
}
Official documentation: https://platform.openai.com/docs/api-reference/completions
Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.

Request Parameters

model
string
required
ID of the model to use. You can use the List models API to see all available models.
prompt
string
required
The prompt to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays.
max_tokens
integer
default:"16"
The maximum number of tokens to generate in the completion.
temperature
number
default:"1"
Sampling temperature between 0 and 2. Higher values make output more random, lower values make it more focused.
top_p
number
default:"1"
Nucleus sampling parameter.
n
integer
default:"1"
Number of completions to generate for each prompt.
stream
boolean
default:"false"
Whether to stream back partial progress.
logprobs
integer
Include the log probabilities of the most likely tokens. Maximum value is 5.
echo
boolean
default:"false"
Echo back the prompt in addition to the completion.
stop
string | array
Up to 4 sequences where the API will stop generating further tokens.
presence_penalty
number
default:"0"
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far.
frequency_penalty
number
default:"0"
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text.
best_of
integer
default:"1"
Generates best_of completions server-side and returns the “best” one.

Response

id
string
Unique identifier for the completion.
object
string
Object type, which is text_completion.
created
integer
Unix timestamp of when the completion was created.
model
string
The model used for completion.
choices
array
List of completion choices.
usage
object
Usage statistics for the completion request.
curl -X POST https://api.example.com/v1/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-3.5-turbo-instruct",
    "prompt": "Hello,",
    "max_tokens": 30,
    "temperature": 0
  }'
{
  "id": "cmpl-ByvHP6AWeB1L5vWZSPNHsB12sU9db",
  "object": "text_completion",
  "created": 1753859563,
  "model": "gpt-3.5-turbo-instruct",
  "choices": [
    {
      "index": 0,
      "logprobs": null,
      "finish_reason": "length",
      "text": "I am an AI assistant. How can I help you today?"
    }
  ],
  "usage": {
    "prompt_tokens": 3,
    "completion_tokens": 30,
    "total_tokens": 33
  }
}