Chat Completions API
POST /v1/chat/completions — OpenAI 兼容的聊天完成接口,调用任意支持的模型进行对话。
请求示例
cURLBash
curl https://www.ulovegpt.com/v1/chat/completions \
-H "Authorization: Bearer <你的 API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-5.4-mini",
"messages": [
{"role": "user", "content": "解释一下什么是 RESTful API"}
],
"temperature": 0.7,
"max_tokens": 1024
}'请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型名称,格式 provider/model-name |
messages | array | 是 | 消息数组,支持 system/user/assistant/tool 角色 |
temperature | number | 否 | 0-2,越高越随机(默认 1) |
max_tokens | integer | 否 | 最大生成 token 数 |
top_p | number | 否 | 核采样参数(默认 1) |
frequency_penalty | number | 否 | -2 到 2,降低重复 token 概率 |
presence_penalty | number | 否 | -2 到 2,鼓励新话题 |
stream | boolean | 否 | 是否启用流式输出(默认 false) |
tools | array | 否 | 可用工具列表,用于 function calling |
response_format | object | 否 | 指定输出格式(text / json_object / json_schema) |
stop | string/array | 否 | 停止生成的 token 序列 |
响应格式
响应示例Json
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1704067200,
"model": "openai/gpt-5.4-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "RESTful API 是一种基于 HTTP 协议的 Web API 设计风格..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 35,
"completion_tokens": 128,
"total_tokens": 163
}
}消息角色
| 角色 | 说明 |
|---|---|
system | 系统指令,设定模型行为 |
user | 用户输入 |
assistant | 模型回复 |
tool | 工具调用结果 |