Skip to main content
POST
/
v1
/
chat
/
completions
创建聊天对话
curl --request POST \
  --url https://api.tkhub.ai/v1/v1/chat/completions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "gpt-4",
  "messages": [
    {
      "role": "system",
      "content": "<string>",
      "name": "<string>",
      "tool_calls": [
        {
          "id": "<string>",
          "type": "function",
          "function": {
            "name": "<string>",
            "arguments": "<string>"
          }
        }
      ],
      "tool_call_id": "<string>",
      "reasoning_content": "<string>"
    }
  ],
  "temperature": 1,
  "top_p": 1,
  "n": 1,
  "stream": false,
  "stream_options": {
    "include_usage": true
  },
  "stop": "<string>",
  "max_tokens": 123,
  "max_completion_tokens": 123,
  "presence_penalty": 0,
  "frequency_penalty": 0,
  "logit_bias": {},
  "user": "<string>",
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "<string>",
        "description": "<string>",
        "parameters": {}
      }
    }
  ],
  "tool_choice": "none",
  "response_format": {
    "type": "text",
    "json_schema": {}
  },
  "seed": 123,
  "reasoning_effort": "low",
  "modalities": [
    "text"
  ],
  "audio": {
    "voice": "<string>",
    "format": "<string>"
  }
}
'
{
  "id": "<string>",
  "object": "chat.completion",
  "created": 123,
  "model": "<string>",
  "choices": [
    {
      "index": 123,
      "message": {
        "role": "system",
        "content": "<string>",
        "name": "<string>",
        "tool_calls": [
          {
            "id": "<string>",
            "type": "function",
            "function": {
              "name": "<string>",
              "arguments": "<string>"
            }
          }
        ],
        "tool_call_id": "<string>",
        "reasoning_content": "<string>"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123,
    "prompt_tokens_details": {
      "cached_tokens": 123,
      "text_tokens": 123,
      "audio_tokens": 123,
      "image_tokens": 123
    },
    "completion_tokens_details": {
      "text_tokens": 123,
      "audio_tokens": 123,
      "reasoning_tokens": 123
    }
  },
  "system_fingerprint": "<string>"
}

Authorizations

Authorization
string
header
required

使用 Bearer Token 认证。 格式: Authorization: Bearer sk-xxxxxx

Body

application/json
model
string
required

模型 ID

Example:

"gpt-4"

messages
object[]
required

对话消息列表

temperature
number
default:1

采样温度

Required range: 0 <= x <= 2
top_p
number
default:1

核采样参数

Required range: 0 <= x <= 1
n
integer
default:1

生成数量

Required range: x >= 1
stream
boolean
default:false

是否流式响应

stream_options
object
stop

停止序列

max_tokens
integer

最大生成 Token 数

max_completion_tokens
integer

最大补全 Token 数

presence_penalty
number
default:0
Required range: -2 <= x <= 2
frequency_penalty
number
default:0
Required range: -2 <= x <= 2
logit_bias
object
user
string
tools
object[]
tool_choice
Available options:
none,
auto,
required
response_format
object
seed
integer
reasoning_effort
enum<string>

推理强度 (用于支持推理的模型)

Available options:
low,
medium,
high
modalities
enum<string>[]
Available options:
text,
audio
audio
object

Response

成功创建响应

id
string
object
string
Example:

"chat.completion"

created
integer
model
string
choices
object[]
usage
object
system_fingerprint
string