Khi được cung cấp một prompt, mô hình sẽ trả về một hoặc nhiều đoạn văn hoàn thành được dự đoán, và cũng có thể trả về xác suất của các token thay thế tại từng vị trí. Tạo phần hoàn thành dựa trên prompt và các tham số đã cung cấp. Tài liệu chính thức: https://platform.openai.com/docs/guides/tools?api-mode=responses
Request
Authorization
Provide your bearer token in the
Authorization
header when making requests to protected resources.
Example:
Authorization: Bearer ********************
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":"claude-3-7-sonnet-20250219"}
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--request POST '/v1/chat/completions' \
--header'Accept: application/json' \
--header'Authorization: Bearer <token>' \
--header'Content-Type: application/json' \
--data-raw'{
"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": "claude-3-7-sonnet-20250219"
}'
Responses
🟢200OK
application/json
Body
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}}