Docs
  1. ChatGPT (Completions)
Docs
  • Introduction
  • Quick Start Guide
  • Make a request
  • Chat Models
    • ChatGpt
      • ChatGPT (Audio)
        • Create a voice
        • Create a transcript
        • Create translation
      • ChatGPT (Chat)
        • Chat completion object
        • Create chat completion (streaming)
        • Create chat completion (non-streaming)
        • Create chat image recognition (streaming)
        • Create chat image recognition (streaming) base64
        • Create chat image recognition (non-streaming)
        • Function calling
        • N choices
        • Create chat function call (only non-streaming)
        • Create structured output
      • ChatGPT (Completions)
        • Completion object
        • Creation completed
          POST
      • ChatGPT(Embeddings)
        • Embedded Object
        • Create embed
    • Anthropic Claude
      • Create chat completion (streaming)
      • Create chat completion (non-streaming)
      • Create chat image recognition (streaming)
      • Create chat image recognition (non-streaming)
    • Gemini
      • Gemini Image creation interface (gemini-2.0-flash-exp-image-generation)
      • Chat interface
      • Image recognition interface
  • Image Models
    • MJ
      • Submit Imagine task (mj_imagine)
      • Submit Blend task (mj_blend)
      • Submit Describe task (mj_describe)
      • Submit Change task (mj_variation, mj_upscale,mj_reroll)
      • Query task status based on task ID
    • Ideogram
      • Generate with Ideogram 3.0
      • Edit with Ideogram 3.0
      • Remix with Ideogram 3.0
    • Kling Image
      • Submit Image Generation
      • Get Image by Task ID
      • Submit Kolors Virtual Try On
      • Get Kolors Virtual Try On by Task ID
    • DALL·E 3
      POST
    • Flux (OpenAI dall-e-3 format)
      POST
  • Video Models
    • Kling Video
      • Create Video by Text
      • Get Video by Task ID(text2video)
      • Create Video by Image
      • Get Video by Task ID(image2video)
    • Runway ML Video
      • Create Video by Runway
      • Get Video by Task ID
    • Luma Video
      • Create Video by Luma
      • Get Video by Task ID
    • Pika Video
      • Create Video by Pika
      • Get Video by Task ID
  • Music Model - Suno
    • Illustrate
    • Parameter
    • Task submission
      • Generate songs (inspiration, customization, continuation)
      • Generate lyrics
    • Query interface
      • Query a single task
  • Python Samples
    • python openai official library (using AutoGPT, langchain, etc.)
    • Python uses speech to text
    • Python uses text to speech
    • Python uses Embeddings
    • python calls DALL·E
    • python simple call openai function-calling demo
    • python langchain
    • python llama_index
    • Python uses gpt-4o to identify pictures-local pictures
    • python library streaming output
    • Python uses gpt-4o to identify images
  • Plug-in/software usage tutorials
    • Setting HTTP for Make.com with Yescale
    • Sample Code for gpt-4o-audio/gpt-4o-mini-audio
  • Help Center
    • HTTP status codes
  1. ChatGPT (Completions)

Creation completed

POST
/v1/completions
Given a hint, the model will return one or more predicted completions and can also return the probability of the surrogate marker for each position.
Complete creation for the provided prompts and parameters

Request

Header Params
Authorization
string 
optional
Example:
Bearer {{YOUR_API_KEY}}
Body Params application/json
model
string 
required
The ID of the model to use. You can use the List models API to view all available models, or view our Model Overview for their descriptions.
prompt
string 
required

Generates a completed prompt, encoded as a string, an array of strings, an array of tokens, or an array of token arrays. Note that <|endoftext|> is the document delimiter that the model sees during training, so if no hints are specified, the model will generate the beginning of a new document.

best_of
integer 
optional
Defaults to 1 Generate best_of completions on the server side and return the "best" completion (the one with the highest log probability for each token). Unable to stream results. When used with n, best_of controls the number of candidate completions, and n specifies the number to return – best_of must be greater than n. Note: Because this parameter generates many completions, it can drain your token quota quickly. Please use caution and make sure you have reasonable settings for max_tokens and stop.
echo
boolean 
optional
The default is false. In addition to completion, prompts are also echoed.
frequency_penalty
number 
optional
Defaults to 0 - a number between 2.0 and 2.0. Positive values ​​penalize new tokens based on the current existing frequency of the text, reducing the likelihood that the model will repeat the same line verbatim.
logit_bias
object 
optional

Defaults to null The probability of occurrence of the specified token in modification completion. Accepts a JSON object that maps a token (specified by the token ID in the GPT tokenizer) to an associated bias value, -100 to 100. You can use this tokenizer tool (available for GPT-2 and GPT-3) to convert text into token IDs. Mathematically speaking, the bias is added to the resulting logit before sampling the model. The exact effect varies from model to model, but values ​​between -1 and 1 should reduce or increase the likelihood of selection; values ​​like -100 or 100 should result in a ban or exclusive selection of the token in question. For example, you can pass {"50256": -100} to prevent the <|endoftext|> token from being generated.

logprobs
null 
optional
Default is null
Includes the log probabilities of the logprobs most likely tokens, as well as the selected token. For example, if logprobs is 5, the API will return a list of the 5 most likely tokens. The API always returns the logprob of the sampled token, so there may be at most logprobs+1 elements in the response.
The maximum value of logprobs is 5.
max_tokens
integer 
optional
Default is 16
The maximum number of tokens generated in completion.
The hint's token count plus max_tokens cannot exceed the model's context length. Python code example for counting tokens.
n
integer 
optional
Default is 1
The number of completions generated for each prompt.
Note: Because this parameter generates many completions, it can drain your token quota quickly. Please use caution and make sure you have reasonable settings for max_tokens and stop.
presence_penalty
number 
optional
Defaults to 0 - a number between 2.0 and 2.0. Positive values ​​penalize new tokens based on whether they appear in the current text, increasing the likelihood that the model discusses new topics. For more information on frequency and presence penalties, see .
seed
integer 
optional
If specified, our system will do its best to sample deterministically so that repeated requests with the same seed and parameters should return the same results. Determinism is not guaranteed and you should refer to the system_fingerprint response parameter to monitor your backend for changes.
stop
string 
optional
Defaults to null. Maximum of 4 sequences at which the API will stop generating more tokens. The text returned will not contain stop sequences.
stream
boolean 
optional
The default is false whether to flow back part of the progress. If set, the token will be sent as a data-only server-sent event when available, and the stream is terminated by a data: [DONE] message. Object message. Python code examples.
suffix
string 
optional
Defaults to null The suffix that appears after completion of inserted text.
temperature
integer 
optional
Defaults to 1 The sampling temperature to use, between 0 and 2. Higher values ​​(like 0.8) will make the output more random, while lower values ​​(like 0.2) will make it more focused and deterministic. We generally recommend changing this or top_p, not both.
user
string 
required
top_p
integer 
optional
Represents a unique identifier for the end user, which can help OpenAI monitor and detect abuse. learn more.
Example
{
    "model": "gpt-3.5-turbo-instruct",
    "prompt": "hi,",
    "max_tokens": 30,
    "temperature": 0
  }

Request samples

Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
Request Request Example
Shell
JavaScript
Java
Swift
curl --location --request POST '/v1/completions' \
--header 'Authorization: Bearer {{YOUR_API_KEY}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gpt-3.5-turbo-instruct",
    "prompt": "hi,",
    "max_tokens": 30,
    "temperature": 0
  }'

Responses

🟢200Ok
application/json
Body
id
string 
required
object
string 
required
created
integer 
required
model
string 
required
system_fingerprint
string 
required
choices
array [object {4}] 
required
text
string 
optional
index
integer 
optional
logprobs
null 
optional
finish_reason
string 
optional
usage
object 
required
prompt_tokens
integer 
required
completion_tokens
integer 
required
total_tokens
integer 
required
Example
{
  "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7",
  "object": "text_completion",
  "created": 1589478378,
  "model": "gpt-3.5-turbo-instruct",
  "system_fingerprint": "fp_44709d6fcb",
  "choices": [
    {
      "text": "\n\nThis is indeed a test",
      "index": 0,
      "logprobs": null,
      "finish_reason": "length"
    }
  ],
  "usage": {
    "prompt_tokens": 5,
    "completion_tokens": 7,
    "total_tokens": 12
  }
}
Previous
Completion object
Next
Embedded Object
Built with