API 参考

OpenAI Responses API

使用 input 发送内容,以 Responses 格式读取模型回复。

POST https://api.aigocode.dev/v1/responses

Responses 是 OpenAI 兼容协议的调用入口,可用于 GPT、Grok 等支持该协议的模型。直接通过 API 调用时,选择支持外接调用的分组,使用 Authorization: Bearer YOUR_API_KEY 鉴权。

AIGoCode 所有支持 OpenAI 协议的模型,都同时支持 Responses 和 Chat Completions。现有代码采用 input 格式时,使用本接口即可。

请求参数

字段类型必填说明
modelstring是当前分组中的模型 ID
inputstring / array首次调用时填写文本输入,或 Responses 格式的输入条目数组
instructionsstring否系统指令
streamboolean否设置为 true 时使用 SSE 流式返回

请求示例

下面使用 gpt-6-astra。按终端选择对应示例,并填写支持该模型的可外接分组 Key。

export AIGOCODE_API_KEY="填写支持 OpenAI 协议且可外接分组的 API Key"

curl "https://api.aigocode.dev/v1/responses" \
  -H "Authorization: Bearer $AIGOCODE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-6-astra",
  "input": "Reply with exactly: Hello from AIGoCode!"
}'
$env:AIGOCODE_API_KEY = "填写支持 OpenAI 协议且可外接分组的 API Key"

$body = @{
  model = "gpt-6-astra"
  input = "Reply with exactly: Hello from AIGoCode!"
} | ConvertTo-Json -Depth 6

$response = Invoke-RestMethod `
  -Method Post `
  -Uri "https://api.aigocode.dev/v1/responses" `
  -Headers @{ Authorization = "Bearer $env:AIGOCODE_API_KEY" } `
  -ContentType "application/json; charset=utf-8" `
  -Body ([System.Text.Encoding]::UTF8.GetBytes($body))

$response | ConvertTo-Json -Depth 20
set "AIGOCODE_API_KEY=填写支持 OpenAI 协议且可外接分组的 API Key"

curl.exe "https://api.aigocode.dev/v1/responses" ^
  -H "Authorization: Bearer %AIGOCODE_API_KEY%" ^
  -H "Content-Type: application/json" ^
  -d "{\"model\":\"gpt-6-astra\",\"input\":\"Reply with exactly: Hello from AIGoCode!\"}"

响应

以下展示正文相关字段:

{
  "id": "resp_example",
  "object": "response",
  "model": "gpt-6-astra",
  "status": "completed",
  "output": [
    {
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "Hello from AIGoCode!"
        }
      ]
    }
  ]
}

遍历 output 中的消息条目,从 content 中读取 type 为 output_text 的 text。使用 OpenAI SDK 时,也可以通过 response.output_text 读取汇总文本。

用量信息位于 usage,常见字段为 input_tokens、output_tokens 和 total_tokens。平台实际扣减额度可在控制台的「使用统计」中查看。

流式响应

在请求中增加 "stream": true,按 SSE 事件逐段读取:

事件含义
response.output_text.delta新增的正文文本
response.completed响应完成
response.failed / response.incomplete / error失败、未完整结束或错误信息

curl 查看流式输出时使用 -N。程序应按完整事件边界解析,收到正文增量后追加显示。

相关入口

本页目录