跳转到内容

聊天补全 (Chat Completions)

聊天补全(Chat Completions)是新一代大模型的主流接口,用于对话生成。它支持多模态输入(如图像)、流式输出(Streaming),并且与 OpenAI 的 API 完全兼容。

POST /v1/chat/completions
参数类型必填默认值说明
modelstring-调用的模型 ID(例如 gpt-4o, claude-3-5-sonnet)。
messagesarray-对话历史消息列表。
temperaturenumber1.0采样温度 (0-2)。值越大越有创意,值越小越精确。
top_pnumber1.0核采样参数。与 temperature 选其一调整即可。
max_tokensinteger-最大生成 token 数。
streambooleanfalse是否开启流式传输。如果为 true,以 text/event-stream 格式逐步返回。
toolsarray-模型可调用的工具(Function Calling)定义列表。
[
{ "role": "system", "content": "你是一个有用的助手。" },
{ "role": "user", "content": "你好,你能帮我写一段 Python 代码吗?" }
]
Terminal window
curl https://api.easytakeai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "你好!"}
],
"temperature": 0.7
}'
{
"id": "chatcmpl-123456",
"object": "chat.completion",
"created": 1716298500,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!很高兴为您服务。今天有什么我可以帮您的吗?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 26,
"total_tokens": 35
}
}