- 前言(必读)
- OpenAI官方SDK使用教程
- 批量请求示例
- 聊天模型(Chat)
- 内容审查
- 向量嵌入
- 图片处理
- 音频模型(Audio)
- 绘画模型(Painting)
- 视频模型(Video)
- 音乐创作(suno)
- 文档处理
- 3D模型
- 更多接口开发中...
- 查询令牌用量GET
- 查询令牌限额GET
聊天接口(函数调用)
POST
/v1/chat/completions
请求参数
Authorization
在 Header 添加参数
Authorization
,其值为在 Bearer 之后拼接 Token示例:
Authorization: Bearer ********************
Header 参数
Content-Type
string
必需
示例值:
application/json
Body 参数application/json
model
string
模型
messages
array [object {2}]
消息列表
role
string
消息角色
content
string
消息内容
tools
array [object {2}]
工具列表
type
string
类型
function
function
object
函数
示例
{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "What is the weather like in Paris today?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current temperature for a given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and country e.g. Bogotá, Colombia"
}
},
"required": [
"location"
],
"additionalProperties": false
},
"strict": true
}
}
]
}
示例代码
Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://api.gpt.ge/v1/chat/completions' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "What is the weather like in Paris today?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current temperature for a given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and country e.g. Bogotá, Colombia"
}
},
"required": [
"location"
],
"additionalProperties": false
},
"strict": true
}
}
]
}'
返回响应
🟢200成功
application/json
Body
id
string
必需
object
string
必需
created
integer
必需
model
string
必需
choices
array [object {4}]
必需
index
integer
可选
message
object
可选
logprobs
null
可选
finish_reason
string
可选
usage
object
必需
prompt_tokens
integer
必需
completion_tokens
integer
必需
total_tokens
integer
必需
prompt_tokens_details
object
必需
completion_tokens_details
object
必需
system_fingerprint
string
必需
示例
{
"id": "chatcmpl-Ax2bU1RFE8P0Y9uqKcErQNLcx4dDe",
"object": "chat.completion",
"created": 1738634724,
"model": "gpt-4o-2024-08-06",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_FezxjoWuDV1CL3dITVFOjUzK",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\":\"Paris, France\"}"
}
}
],
"refusal": null
},
"logprobs": null,
"finish_reason": "tool_calls"
}
],
"usage": {
"prompt_tokens": 65,
"completion_tokens": 16,
"total_tokens": 81,
"prompt_tokens_details": {
"cached_tokens": 0,
"audio_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 0,
"audio_tokens": 0,
"accepted_prediction_tokens": 0,
"rejected_prediction_tokens": 0
}
},
"system_fingerprint": "fp_f3927aa00d"
}
修改于 2025-02-04 02:04:22