Skip to content

语言模型 API

OpenAI Chat Completions 兼容接口。

POST https://api.ashpetals.com/v1/chat/completions

请求参数

参数类型说明
modelstring必填,模型 ID(/v1/models 可查)
messagesarray必填,对话消息列表
streamboolean是否流式返回(SSE),默认 false
max_tokensint最大输出 token 数
temperaturenumber采样温度,默认 1
top_pnumber核采样
toolsarray工具调用定义(Function Calling)
tool_choicestring/object工具选择策略

基础请求

bash
curl https://api.ashpetals.com/v1/chat/completions \
  -H "Authorization: Bearer sk-你的APIKey" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.6-sol",
    "messages": [
      { "role": "system", "content": "你是一个乐于助人的助手。" },
      { "role": "user", "content": "用一句话介绍你自己。" }
    ],
    "max_tokens": 200
  }'

流式请求(SSE)

bash
curl https://api.ashpetals.com/v1/chat/completions \
  -H "Authorization: Bearer sk-你的APIKey" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-flash",
    "messages": [{ "role": "user", "content": "讲个笑话" }],
    "stream": true
  }'

响应为 data: 开头的 SSE 分块,以 data: [DONE] 结束。

视觉理解

支持视觉的模型可在消息中携带图片(图片 URL 或 Base64):

json
{
  "model": "gpt-5.6-sol",
  "messages": [
    {
      "role": "user",
      "content": [
        { "type": "text", "text": "这张图里有什么?" },
        { "type": "image_url", "image_url": { "url": "https://example.com/cat.png" } }
      ]
    }
  ]
}

工具调用

json
{
  "model": "gpt-5.6-sol",
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "查询城市天气",
        "parameters": {
          "type": "object",
          "properties": { "city": { "type": "string" } },
          "required": ["city"]
        }
      }
    }
  ],
  "tool_choice": "auto"
}

注意事项

  • 推理模型(如带 reasoning 的模型)的思考内容会占用 max_tokens 预算,请设置足够大的 max_tokens
  • 上下文长度与并发限制以模型与分组策略为准;超长上下文可尝试精简历史消息。
  • 使用 Anthropic 协议的 Claude 模型请见 Claude Code 配置 或直接调用 /v1/messages

AshPetals API — 单主站 · OpenAI 兼容