BLACK HOLE 丨 黑洞智能体
Docs

创建对话补全 (Chat Completions)

POST /v1/chat/completions · 核心文本、视觉理解、深度思考、机器翻译与工具调用统一推理接口

POST https://api.blackholeagent.cn/chat/completions

向指定语言或多模态理解模型发送多轮消息上下文,支持同步 JSON 返回与低延迟 SSE 流式增量输出。

请求体参数(Request Body)

完整兼容 OpenAI Chat Completions 参数集,并支持推理强度控制与显存缓存粘性键:

参数名类型必填默认值说明
modelstring是—模型唯一标识符,例如 blackhole-v5-pro、blackhole-v5-flash、deepseek-v4.1-flash-1017、deepseek-v4-pro-0813、glm-5.4、qwen4-max、kimi-k3.1-pro 或翻译模型 hy-mt2-pro。
messagesMessage[]是—按时间顺序排列的消息数组,支持 system、user、assistant、tool 角色;content 可为纯文本字符串或包含 text / image_url 的多模态内容块数组。
streamboolean否false设为 true 时以 Server-Sent Events 流式推送增量 delta;配合 stream_options: {"include_usage": true} 可在末帧获取完整 Token 统计。
temperaturenumber否1.0采样温度(0.0 ~ 2.0)。代码生成与结构化抽取建议设为 0.1 ~ 0.3,创意写作可设为 0.8 ~ 1.0。
max_tokensinteger否—单次回复生成的最大 Token 数上限(包含推理模型输出上限控制)。
toolsToolDefinition[]否—可供模型调用的外部函数 JSON Schema 列表,支持单轮并行触发多个工具调用。
response_formatobject否—指定输出格式,支持 {"type": "text"}、{"type": "json_object"} 或严格模式 {"type": "json_schema", "json_schema": {...}}。
prompt_cache_keystring否—可选会话粘性路由键,引导网关优先命中同一显存缓存池实例。

请求示例与标准响应结构

以下示例演示如何调用深度推理模型并解析返回的思维链(reasoning_content)与精确缓存命中明细(prompt_tokens_details.cached_tokens):

cURL

curl https://api.blackholeagent.cn/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $BLACKHOLE_API_KEY" \
  -d '{
    "model": "deepseek-v4-pro-0813",
    "messages": [
      { "role": "system", "content": "请给出严谨的分布式系统故障排查步骤。" },
      { "role": "user", "content": "PostgreSQL 连接池在整点突发耗尽,如何快速定位根因?" }
    ],
    "temperature": 0.2
  }'

TypeScript

const res = await client.chat.completions.create({
  model: 'deepseek-v4-pro-0813',
  temperature: 0.2,
  messages: [
    { role: 'system', content: '请给出严谨的分布式系统故障排查步骤。' },
    { role: 'user', content: 'PostgreSQL 连接池在整点突发耗尽,如何快速定位根因?' }
  ]
})
console.log(res.choices[0]?.message.content)

Python

res = client.chat.completions.create(
    model="deepseek-v4-pro-0813",
    temperature=0.2,
    messages=[
        {"role": "system", "content": "请给出严谨的分布式系统故障排查步骤。"},
        {"role": "user", "content": "PostgreSQL 连接池在整点突发耗尽,如何快速定位根因?"}
    ],
)
print(res.choices[0].message.content)

响应示例

{
  "id": "chatcmpl-bh98f21a4c7e01",
  "object": "chat.completion",
  "created": 1764756000,
  "model": "deepseek-v4-pro-0813",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "reasoning_content": "整点突发连接耗尽通常与定时批处理 Cron、缓存集体过期击穿或长事务锁等待有关...",
        "content": "建议按以下四步在 3 分钟内定位整点连接池耗尽根因:\n1. 查询 pg_stat_activity 排查 wait_event_type..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 42,
    "completion_tokens": 318,
    "total_tokens": 360,
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 96
    }
  }
}

On this page