Create chat completion
POST
https://api.openai.com/v1/chat/completions
Request Request Example
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://api.openai.com/v1/chat/completions' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer ' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Hello!"}]
}'
Response Response 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
}
}
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
Responses
Modified at 2025-01-17 03:35:09