跳转到主要内容

请求体

model
string
必填
要使用的模型 ID。有关可用选项,请参阅 Models
messages
array
必填
构成对话的消息列表。每个消息对象包含:
  • role (string): systemuserassistant
  • content (string | array): 消息内容
temperature
number
默认值:"1"
介于 0 到 2 之间的采样温度。较高的值会使输出更具随机性。
max_tokens
integer
生成的最大 token 数量。
stream
boolean
默认值:"false"
如果为 true,部分消息增量将作为 SSE 事件发送。
stream_options
object
流式传输选项。设置 include_usage: true 以在流数据块中接收 token 使用情况。
top_p
number
默认值:"1"
核采样参数。我们建议修改此参数或 temperature,但不要同时修改两者。
frequency_penalty
number
默认值:"0"
介于 -2.0 到 2.0 之间的数值。正值会惩罚重复的 token。
presence_penalty
number
默认值:"0"
介于 -2.0 到 2.0 之间的数值。正值会惩罚文本中已出现的 token。
stop
string | array
API 将停止生成 token 的最多 4 个序列。
tools
array
模型可能调用的工具列表(function calling)。
tool_choice
string | object
控制模型如何使用工具。选项:autononerequired 或特定的工具对象。
parallel_tool_calls
boolean
默认值:"true"
是否启用并行函数调用。设置为 false 以按顺序调用函数。
max_completion_tokens
integer
补全的最大 token 数量。max_tokens 的替代方案,更适用于 o1/o3 等较新模型值。
reasoning_effort
string
o1/o3 模型的推理力度。选项:lowmediumhigh
seed
integer
用于确定性采样的随机种子。
n
integer
默认值:"1"
生成的补全数量 (1-128)。
logprobs
boolean
是否返回对数概率。
top_logprobs
integer
返回的前几个对数概率的数量 (0-20)。需要设置 logprobs: true
top_k
integer
Top-K 采样参数(适用于 Anthropic/Gemini 模型)。
response_format
object
响应格式规范。使用 {"type": "json_object"} 开启 JSON 模式,或使用 {"type": "json_schema", "json_schema": {...}} 获取结构化输出。
logit_bias
object
修改指定 token 出现的可能性。将 token ID(作为字符串)映射到 -100 到 100 之间的偏置值。
user
string
代表终端用户的唯一标识符,用于滥用监控。
cache_control
object
LemonData 缓存控制选项。
  • type (string): 缓存策略 - defaultno_cacheno_storeresponse_onlysemantic_only
  • max_age (integer): 缓存 TTL(以秒为单位,最大 86400)

响应

id
string
补全的唯一标识符。
object
string
始终为 chat.completion
created
integer
补全创建时的 Unix 时间戳。
model
string
用于补全的模型。
choices
array
补全选项列表。每个选项包含:
  • index (integer): 选项的索引
  • message (object): 生成的消息
  • finish_reason (string): 模型停止的原因 (stoplengthtool_calls)
usage
object
Token 使用情况统计。
  • prompt_tokens (integer): 提示词中的 token 数量
  • completion_tokens (integer): 补全中的 token 数量
  • total_tokens (integer): 使用的总 token 数量
curl -X POST "https://api.lemondata.cc/v1/chat/completions" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Hello!"}
    ],
    "temperature": 0.7,
    "max_tokens": 1000
  }'
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1706000000,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 20,
    "completion_tokens": 9,
    "total_tokens": 29
  }
}