API 目录

创建聊天函数调用

POST
/v1/chat/completions

创建聊天补全(函数调用)

POST https://www.vortapapi.com/v1/chat/completions

使用聊天补全接口向模型发送对话消息,并获取模型生成的回复。该接口兼容 OpenAI API 格式,可用于普通对话,也可通过工具 / 函数调用让模型在需要时返回结构化的函数调用参数。

请求头

名称必填说明
Content-Type请求体格式,通常为 application/json
Accept期望的响应格式,通常为 application/json
AuthorizationAPI Key 鉴权信息,格式为 Bearer sk-***

请求示例

curl https://www.vortapapi.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer sk-***" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [
      {
        "role": "user",
        "content": "北京今天适合出门吗?"
      }
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_weather",
          "description": "查询指定城市的天气情况",
          "parameters": {
            "type": "object",
            "properties": {
              "city": {
                "type": "string",
                "description": "城市名称,例如:北京"
              }
            },
            "required": ["city"]
          }
        }
      }
    ]
  }'

响应示例

{
  "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
  }
}

响应字段说明

字段类型说明
idstring本次聊天补全请求的唯一标识
objectstring对象类型,通常为 chat.completion
createdinteger响应创建时间,Unix 时间戳
choicesarray模型生成的候选结果列表
choices[].indexinteger当前候选结果在列表中的索引
choices[].messageobject模型返回的消息内容
choices[].message.rolestring消息角色,通常为 assistant
choices[].message.contentstring 或 null模型生成的自然语言内容;当模型选择调用工具时可能为空
choices[].finish_reasonstring生成结束原因,例如 stoptool_callslength
usageobjectToken 使用统计
usage.prompt_tokensinteger输入内容消耗的 token 数
usage.completion_tokensinteger输出内容消耗的 token 数
usage.total_tokensinteger输入与输出合计消耗的 token 数