ak46
  1. 聊天模型(Chat)
ak46
  • 一分钟,了解AK46.VIP !
  • 聊天模型(Chat)
    • 列出可用模型
      GET
    • 会话补全(通用)
      POST
    • 会话补全(图片分析)
      POST
    • 会话补全(函数调用)
      POST
    • 会话补全(o1-o3系列)
      POST
  1. 聊天模型(Chat)

会话补全(函数调用)

POST
/v1/chat/completions
只提供简单的请求示例,更详细的API接口使用说明 请阅读官方文档
注意:OpenAI、Claude、Gemini...等聊天模型均使用该接口格式。

请求参数

Authorization
JWT Bearer
在 Header 添加参数
Authorization
,其值为在 Bearer 之后拼接 Token
示例:
Authorization: Bearer ********************
or
Header 参数

Body 参数application/json

示例
{
    "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 '/v1/chat/completions' \
--header 'Authorization: Bearer <token>' \
--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": "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-09-23 14:13:30
上一页
会话补全(图片分析)
下一页
会话补全(o1-o3系列)
Built with