Given a prompt, the model will return one or more predicted completions and can also provide the probability of alternative tokens at each position. Create completions for the provided prompt and parameters Official documentation: https://platform.openai.com/docs/guides/tools?api-mode=responses
Request
Header Params
Body Params application/json
Example
{"stream":false,"messages":[{"role":"user","content":"What's the weather like in Beijing today?"}],"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"max_tokens":1000,"temperature":0.8,"model":"gpt-4o"}
Request Code 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'/v1/chat/completions' \
--header'Accept: application/json' \
--header'Authorization: {{Authorization}}' \
--header'Content-Type: application/json' \
--data'{
"stream": false,
"messages": [
{
"role": "user",
"content": "What'\''s the weather like in Beijing today?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
]
}
}
}
],
"max_tokens": 1000,
"temperature": 0.8,
"model": "gpt-4o"
}'
Responses
🟢200成功
application/json
Bodyapplication/json
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}}