API 文档

WisGate 文本、图片、视频与通用接口调用说明

Responses

Responses 请求、流式事件与兼容渠道支持范围。

Responses 模型响应

POST /v1/responses 接收文本或结构化输入项,返回 response 对象;stream=true 时返回带类型的 SSE 事件。

本文使用 deepseek-v4-flash 演示。调用前请确认当前 API Key 已开通该模型的 Responses 兼容渠道;DeepSeek 专用渠道不支持此入口。Chat Completions 可用不代表 Responses 已开通。

接口信息

项目 值
地址 https://api.wisgate.cn/v1/responses
方法 POST
请求头 Authorization: Bearer YOUR_API_KEY、Content-Type: application/json
OpenAI SDK base URL https://api.wisgate.cn/v1
支持能力 创建普通响应、创建流式响应

当前未注册 Responses 查询、删除、取消、输入项列表、compact 或 Conversations 管理接口。不能把 OpenAI 官方完整端点清单直接视作 WisGate 的支持清单。

最小调用

curl --fail-with-body https://api.wisgate.cn/v1/responses \
  -H "Authorization: Bearer $WISGATE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "deepseek-v4-flash",
    "instructions": "请用简洁的中文回答。",
    "input": "解释什么是 API。",
    "max_output_tokens": 1024
  }'

响应节选示意:

{
  "id": "resp_example",
  "object": "response",
  "created_at": 1791504000,
  "status": "completed",
  "model": "deepseek-v4-flash",
  "output": [{
    "id": "msg_example",
    "type": "message",
    "role": "assistant",
    "status": "completed",
    "content": [{"type": "output_text", "text": "API 是程序之间交换信息的接口。", "annotations": []}]
  }],
  "usage": {"input_tokens": 24, "output_tokens": 16, "total_tokens": 40}
}

HTTP 客户端应遍历 output 中的 message 项,再取 content 的 output_text。output[0] 可能是推理或工具项。SDK 的 response.output_text 是便捷聚合属性,不应假定原始 JSON 一定有同名顶层字段。

输入与参数

参数 类型 处理边界
model string 必填,WisGate 模型名
input string / array 本地要求字段存在;实际调用应提供有效文本或输入项,不能依赖 null 绕过校验
instructions string 本轮系统指令
max_output_tokens integer 输出预算;不能替换为 Chat 的 max_tokens
stream boolean 是否使用 SSE
tools、tool_choice array / string / object 后端保留原始 JSON;具体工具由上游实现
parallel_tool_calls boolean 依赖模型是否支持
text object 输出格式设置,JSON 模式使用 text.format
reasoning object 可解析 effort、summary,可选值取决于模型
temperature、top_p number 模型相关;非透传渠道可能省略零值;不要依赖显式 0 原样转发
metadata、include、truncation object / array / string 可解析,语义和返回内容取决于上游
previous_response_id string 可转发,不等于网关保存历史;DeepSeek 官方 Responses 为无状态模式,示例不用此字段
store boolean 可能被渠道设置过滤;不代表 WisGate 提供检索接口
service_tier string 仅渠道允许时转发,不承诺统一等级或定价
prompt_cache_key、prompt、max_tool_calls、user 各自协议类型 需上游支持,不建议最小调用携带

官方字段语义参考 OpenAI 创建响应。非透传渠道不保留 background、conversation、stream_options 等字段;额外顶层字段可能丢失。不要用 background=true 实现本平台未提供的后台轮询流程。

多轮对话

推荐由客户端保存历史,每次发完整 input,这样不依赖上游的响应存储:

{
  "model": "deepseek-v4-flash",
  "instructions": "请用简洁的中文回答。",
  "input": [
    {"type": "message", "role": "user", "content": [{"type": "input_text", "text": "解释什么是 API。"}]},
    {"type": "message", "role": "assistant", "content": [{"type": "output_text", "text": "API 是程序之间交换信息的接口。", "annotations": []}]},
    {"type": "message", "role": "user", "content": [{"type": "input_text", "text": "举一个天气查询的例子。"}]}
  ]
}

历史包含工具或推理项时,保留上游要求的原始项和关联 ID。DeepSeek 当前官方 Responses 文档明确采用客户端维护历史的无状态方式。DeepSeek Responses 指南

流式事件

curl --fail-with-body -N https://api.wisgate.cn/v1/responses \
  -H "Authorization: Bearer $WISGATE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"model":"deepseek-v4-flash","input":"用三句话介绍杭州。","stream":true}'
事件 客户端处理
response.created / response.in_progress 建立请求状态
response.output_text.delta 累积 delta 文本
response.output_item.added / response.output_item.done 按 output_index 管理输出项
response.function_call_arguments.delta 累积函数参数片段,完成后解析
response.completed 成功终态,读取最终 response / usage
response.incomplete / response.failed / error 标记不完整或失败,检查详情

示意片段:

event: response.output_text.delta
data: {"type":"response.output_text.delta","item_id":"msg_example","output_index":0,"content_index":0,"delta":"杭州","sequence_number":2}

不要使用 Chat 的 choices[].delta 解析器,也不要只等待 [DONE]。DeepSeek 官方 Responses 使用终态事件结束;网关会转发上游事件。连接断开且未收到终态时,应标记本次结果未完整确认。OpenAI SSE 指南

函数工具调用

Responses 的函数定义采用平铺结构,不套 Chat 的 function 对象:

{
  "model": "deepseek-v4-flash",
  "input": "查询杭州天气。",
  "tools": [{
    "type": "function",
    "name": "get_weather",
    "description": "查询城市天气",
    "parameters": {
      "type": "object",
      "properties": {"city": {"type": "string"}},
      "required": ["city"]
    }
  }]
}

上游选择工具时,output 可包含 type=function_call、name、arguments、call_id。客户端校验参数并执行工具,再发历史与结果:

{
  "model": "deepseek-v4-flash",
  "input": [
    {"type": "message", "role": "user", "content": "查询杭州天气。"},
    {"type": "function_call", "call_id": "call_example", "name": "get_weather", "arguments": "{\"city\":\"杭州\"}"},
    {"type": "function_call_output", "call_id": "call_example", "output": "{\"temperature_c\":24}"}
  ]
}

这里的工具调用和天气都是结构示例;真实请求应使用实际返回的调用项,并保留可能存在的 reasoning 项。内置 web_search、file_search、图像生成、代码执行和 MCP 工具均不能仅因 tools 字段可转发,就认定 DeepSeek 渠道已支持。

结构化输出与多模态

需要 JSON 输出时,格式位置是 text.format,例如 {"text":{"format":{"type":"json_object"}}};提示词仍应明确要求输出 JSON。JSON Schema、严格约束或推理模式的组合是否支持,应对目标渠道验证。

图片输入在协议中使用 input_image,与 Chat 的 image_url 块不同。本页使用纯文本示例;不能把 DeepSeek 最新模型的视觉能力等同于所有 deepseek-v4-flash 路由的能力。WisGate /v1/files 当前为未实现路由,不能照搬“先上传 Files,再用 file_id”的官方工作流。

SDK

Python 普通响应:

import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["WISGATE_API_KEY"], base_url="https://api.wisgate.cn/v1")
response = client.responses.create(
    model="deepseek-v4-flash",
    input="解释什么是 API。",
    max_output_tokens=1024,
)
print(response.output_text)

Node.js 流式响应:

import OpenAI from "openai";

const client = new OpenAI({ apiKey: process.env.WISGATE_API_KEY, baseURL: "https://api.wisgate.cn/v1" });
const stream = await client.responses.create({
  model: "deepseek-v4-flash", input: "解释什么是 API。", stream: true,
});
for await (const event of stream) {
  if (event.type === "response.output_text.delta") process.stdout.write(event.delta);
  if (["response.failed", "response.incomplete", "error"].includes(event.type)) console.error(event);
}

排错

问题 排查方向
Chat 可用而 Responses 失败 检查目标渠道协议类型、Responses 变体与上游实际路径
input 缺失 使用 input,不要发送 messages 代替
回复中没有 choices 正常;遍历 output
多轮历史丢失 发送完整历史;不要依赖未实现的会话存储
参数不起作用 检查参数过滤、渠道覆盖和模型支持
HTTP 200 但结果不完整 检查 status、error、incomplete_details,SSE 则检查终态事件

普通错误使用 OpenAI 风格 error 对象。usage.input_tokens、output_tokens、total_tokens 以及可能的缓存明细表示用量,不直接表示账单金额。