- Introduction
- Quick Start Guide
- Make a request
- Chat Models
- ChatGpt
- ChatGPT (Audio)
- ChatGPT (Chat)
- Chat completion object
- Create chat completion (streaming)POST
- Create chat completion (non-streaming)POST
- Create chat image recognition (streaming)POST
- Create chat image recognition (streaming) base64POST
- Create chat image recognition (non-streaming)POST
- Function callingPOST
- N choices POST
- Create chat function call (only non-streaming)POST
- Create structured outputPOST
- ChatGPT (Completions)
- ChatGPT(Embeddings)
- Anthropic Claude
- Gemini
- Image Models
- MJ
- Ideogram
- Kling Image
- DALL·E 3POST
- Flux (OpenAI dall-e-3 format)POST
- Video Models
- Music Model - Suno
- 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
- Help Center
Create structured output
POST
/v1/chat/completions
Complete creation for the provided prompts and parameters
Request
Header Params
Content-Type
string
required
Example:
application/json
Accept
string
required
Example:
application/json
Authorization
string
optional
Example:
Bearer {{YOUR_API_KEY}}
Body Params application/json
model
string
required
messages
array [object {2}]
required
role
string
optional
content
string
optional
temperature
integer
optional
top_p
integer
optional
temperature
but not both.n
integer
optional
How many chat completion choices are generated for each input message.
stream
boolean
optional
stop
string
optional
max_tokens
integer
optional
The maximum number of tokens generated in chat completion.
presence_penalty
number
optional
frequency_penalty
number
optional
logit_bias
null
optional
user
string
optional
response_format
object
optional
seen
integer
optional
tools
array[string]
required
tool_choice
object
required
Example
{
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a helpful math tutor. Guide the user through the solution step by step."
},
{
"role": "user",
"content": "how can I solve 8x + 7 = -23"
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "math_reasoning",
"schema": {
"type": "object",
"properties": {
"steps": {
"type": "array",
"items": {
"type": "object",
"properties": {
"explanation": {
"type": "string"
},
"output": {
"type": "string"
}
},
"required": [
"explanation",
"output"
],
"additionalProperties": false
}
},
"final_answer": {
"type": "string"
}
},
"required": [
"steps",
"final_answer"
],
"additionalProperties": false
},
"strict": true
}
}
}
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/chat/completions' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {{YOUR_API_KEY}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a helpful math tutor. Guide the user through the solution step by step."
},
{
"role": "user",
"content": "how can I solve 8x + 7 = -23"
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "math_reasoning",
"schema": {
"type": "object",
"properties": {
"steps": {
"type": "array",
"items": {
"type": "object",
"properties": {
"explanation": {
"type": "string"
},
"output": {
"type": "string"
}
},
"required": [
"explanation",
"output"
],
"additionalProperties": false
}
},
"final_answer": {
"type": "string"
}
},
"required": [
"steps",
"final_answer"
],
"additionalProperties": false
},
"strict": true
}
}
}'
Responses
🟢200OK
application/json
Body
id
string
required
object
string
required
created
integer
required
choices
array [object {3}]
required
index
integer
optional
message
object
optional
finish_reason
string
optional
usage
object
required
prompt_tokens
integer
required
completion_tokens
integer
required
total_tokens
integer
required
Example
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "\n\nHello there, how may I assist you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}