Skip to content

接口说明

文本生成

OpenAI Completions协议

shell
POST https://api.scnet.cn/api/llm/v1/chat/completions

1.功能介绍

根据输入的上下文,来让模型补全对话内容。

2.请求参数

Header 参数
名称类型必填示例值
Content-Typestringapplication/json
AuthorizationstringBearer <API Key>
Body 参数
名称类型必填默认值描述
modelstring\使用的模型 ID。可用模型及其能力以控制台 → 模型列表为准。视觉理解模型及多模态字段说明见下文“视觉理解与多模态输入”。
messagesarray\表示聊天上下文信息。
您必须在消息数组中提供一个或多个消息。每个消息必须与 system、user 或 assistant 中的一个角色相关联。
content 可以是纯文本字符串,也可以是内容块数组。多模态模型的 user 消息可混合传入 text、image_url、video_url、video、input_audio 等内容块,具体格式见下文“视觉理解与多模态输入”。
其中,system 角色可选,如存在则必须位于列表的最开始。user 和 assistant 需按对话顺序交替出现,以 user 提问开始。content 不能为空。
max_tokensinteger4096限制一次请求中模型生成 completion 的最大 token 数,输入 token 和输出 token 的总长度受模型的上下文长度的限制。请参考模型进行设置。
例如:DeepSeek-7B模型的上下文长度为32K(输入 token 和输出 token 的总长度),则其max_tokens介于 1 到 32768间的整数。
temperaturenumber1采样温度,介于 0 和 2 之间。较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2) 将使输出更加集中和确定。
对于DeepSeek-R1系列模型,官方给出使用建议如下:
temperature 设置在 0.5-0.7 之间,推荐 0.6,防止输出重复或不连贯。
enable_thinkingbooleantrue是否开启思考模式,适用于 Qwen3系列模型、DeepSeek-V4系列模型。
reasoning_effortstringhigh推理强度。可以调整推理强度,可选值为high和max。只适用于 DeepSeek-V4系列模型。只支持OpenAI协议
top_pnumber1top的值,介于 0 和 1 之间。作为调节采样温度的替代方案,模型会考虑前 top_p 概率的 token 的结果。所以 0.1 就意味着只有包括在最高 10% 概率中的 token 会被考虑。 我们通常建议修改这个值或者更改 temperature,但不建议同时对两者进行修改。
不支持以下模型(为了兼容已有软件,设置该参数后不会报错,但也不会生效):
DeepSeek-R1-Distill系列
stopobjectnull生成停止标识,当模型生成结果以stop中某个元素结尾时,停止文本生成。
streambooleanfalse流式响应的选项,当字段stream为true时,该字段生效。
注意: QwQ-32B 模型可支持流式及非流式输出方式,但使用非流式时,建议设置max_tokens值不超过4096,避免请求超时。
stream_optionsobjecttext当启用流式输出时,可通过将本参数设置为{"include_usage": true},在输出的最后一行显示所使用的Token数。
如果设置为false,则最后一行不显示使用的Token数。
本参数仅在设置stream为true时生效。
vl_high_resolution_imagesbooleanfalse是否启用高分辨率图像模式,仅视觉模型生效。设置为 true 时采用固定的高分辨率策略,单张图像上限为 16384 个视觉 Token,并忽略内容块中的 max_pixels;设置为 false 时由 max_pixels 控制图像缩放上限。该字段不是 OpenAI 标准参数,Python SDK 需通过 extra_body 传入。
response_formatobjecttext指定模型必须输出的格式。设置为 { "type": "json_object" } 以启用 JSON 模式,该模式保证模型生成的消息是有效的 JSON。
注意: 使用 JSON 模式时,你还必须通过系统或用户消息指示模型生成 JSON。否则,模型可能会生成不断的空白字符,直到生成达到令牌限制,从而导致请求长时间运行并显得“卡住”。此外,如果 finish_reason="length",这表示生成超过了 max_tokens 或对话超过了最大上下文长度,消息内容可能会被部分截断。
frequency_penaltynumber0介于 -2.0 和 2.0 之间的数字。如果该值为正,那么新 token 会根据其在已有文本中的出现频率受到相应的惩罚,降低模型重复相同内容的可能性。
不支持以下模型(为了兼容已有软件,设置该参数后不会报错,但也不会生效):
DeepSeek-R1-Distill系列
presence_penaltynumber0介于 -2.0 和 2.0 之间的数字。如果该值为正,那么新 token 会根据其是否已在已有文本中出现受到相应的惩罚,从而增加模型谈论新主题的可能性。
不支持以下模型(为了兼容已有软件,设置该参数后不会报错,但也不会生效):
DeepSeek-R1-Distill系列

3.响应参数

名称类型必填描述
idstring该对话的唯一标识符。
choicesobject[]模型生成的 completion 的选择列表,object[]包含以下三个参数:
● finish_reason(string),模型停止生成 token 的原因。必填。
    ○ stop:模型自然停止生成,或遇到 stop 序列中列出的字符串。
    ○ length :输出长度达到了模型上下文长度限制,或达到了 max_tokens 的限制。
    ○ content_filter:输出内容因触发过滤策略而被过滤。
    ○ insufficient_system_resource:系统推理资源不足,生成被打断。
● index(integer),该 completion 在模型生成的 completion 的选择列表中的索引。必填。
● message(object),模型生成的 completion 消息。必填。
    ○ content(string),该 completion 的内容。必填,可为空值。
    ○ reasoning_content(string),适用于DeepSeek-R1-671B,Qwen3-30B-A3B。内容为 assistant 消息中在最终答案之前的推理内容。非必填。
    ○ role(string),生成这条消息的角色。必填。
createdinteger创建聊天完成时的 Unix 时间戳(以秒为单位)。
modelstring生成该 completion 的模型名。
system_fingerprintstring代表模型运行的后端配置。
objectstring对象的类型, 其值为 chat.completion。
usageobjectToken 统计信息,格式:
{
  "prompt_tokens": 整数, // 输入 Token 数(含缓存命中部分)
  "completion_tokens": 整数, // 输出 Token 数
  "total_tokens": 整数, // 总 Token 数
  "prompt_tokens_details": {
    "cached_tokens": 整数 // 缓存命中 Token 数
  }
}
仅部分模型支持上下文缓存。模型未开启缓存或本次请求未命中缓存时,cached_tokens 为 0。缓存命中计费规则详见 计费说明

4.请求示例

cURL请求示例
shell
curl -L -X POST 'https://api.scnet.cn/api/llm/v1/chat/completions' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <API Key>' \
--data-raw '{
  "messages": [
    {
      "content": "You are a helpful assistant",
      "role": "system"
    },
    {
      "content": "Hi",
      "role": "user"
    }
  ],
  "model": "DeepSeek-R1-Distill-Qwen-7B",
  "frequency_penalty": 0,
  "max_tokens": 2048,
  "presence_penalty": 0,
  "response_format": {
    "type": "text"
  },
  "stop": null,
  "stream": false,
  "temperature": 1,
  "top_p": 1
}'
Python请求示例
  • OpenAI SDK
python
from openai import OpenAI

client = OpenAI(api_key="<API Key>", base_url="https://api.scnet.cn/api/llm/v1")

response = client.chat.completions.create(
  model="DeepSeek-R1-Distill-Qwen-7B",
  messages=[
    {"role": "system", "content": "You are a helpful assistant"},
    {"role": "user", "content": "Hello"},
  ],
  max_tokens=1024,
  temperature=0.7,
  stream=False
)
print(response.choices[0].message.content)
  • REQUESTS
python
import requests
import json

url = "https://api.scnet.cn/api/llm/v1/chat/completions"

payload = json.dumps({
  "messages": [
    {
      "content": "You are a helpful assistant",
      "role": "system"
    },
    {
      "content": "Hi",
      "role": "user"
    }
  ],
  "model": "DeepSeek-R1-Distill-Qwen-7B",
  "frequency_penalty": 0,
  "max_tokens": 2048,
  "presence_penalty": 0,
  "response_format": {
    "type": "text"
  },
  "stop": None,
  "stream": False,
  "temperature": 1,
  "top_p": 1
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer <API Key>'
}

response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
  • HTTP.CLIENT
python
import http.client
import json

conn = http.client.HTTPSConnection("api.scnet.cn")
payload = json.dumps({
  "messages": [
    {
      "content": "You are a helpful assistant",
      "role": "system"
    },
    {
      "content": "Hi",
      "role": "user"
    }
  ],
  "model": "DeepSeek-R1-Distill-Qwen-7B",
  "frequency_penalty": 0,
  "max_tokens": 2048,
  "presence_penalty": 0,
  "response_format": {
    "type": "text"
  },
  "stop": None,
  "stream": False,
  "temperature": 1,
  "top_p": 1
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer <API Key>'
}
conn.request("POST", "/api/llm/v1/chat/completions", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Go请求示例
go
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.scnet.cn/api/llm/v1/chat/completions"
  method := "POST"

  payload := strings.NewReader(`{
  "messages": [
    {
      "content": "You are a helpful assistant",
      "role": "system"
    },
    {
      "content": "Hi",
      "role": "user"
    }
  ],
  "model": "DeepSeek-R1-Distill-Qwen-7B",
  "frequency_penalty": 0,
  "max_tokens": 2048,
  "presence_penalty": 0,
  "response_format": {
    "type": "text"
  },
  "stop": null,
  "stream": false,
  "temperature": 1,
  "top_p": 1
}`)

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/json")
  req.Header.Add("Authorization", "Bearer <API Key>")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
Nodejs请求示例
  • OpenAI SDK
javascript
import OpenAI from "openai";

const openai = new OpenAI({
        baseURL: 'https://api.scnet.cn/api/llm/v1',
        apiKey: '<API Key>'
});

async function main() {
  const completion = await openai.chat.completions.create({
    messages: [{ role: "system", content: "You are a helpful assistant." }],
    model: "DeepSeek-R1-Distill-Qwen-7B",
  });

  console.log(completion.choices[0].message.content);
}

main();

5.响应示例

json
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "content": "Hello! How can I help you today?",
        "role": "assistant"
      }
    }
  ],
  "created": 1740036498,
  "id": "39bff8f688377b9e0c73564ab2fae566",
  "model": "DeepSeek-R1-Distill-Qwen-7B",
  "object": "chat.completion",
  "usage": {
    "completion_tokens": 10,
    "prompt_tokens": 16,
    "total_tokens": 26,
    "prompt_tokens_details": {
      "cached_tokens": 5
    }
  }
}

6.视觉理解与多模态输入

支持的模型

多模态字段只有在所选模型具备对应能力时才生效。具体可调用的模型 ID 及能力以 控制台 → 模型列表 为准。

注意

  1. 网关按协议透传多模态内容,不会根据模型名称预先判断模型能力。模型收到自身不支持的 image_urlvideo_urlinput_audio 等字段时,下游可能忽略该字段或返回不支持该模态的错误。
  2. 图片、视频和音频 URL 必须能被模型服务通过公网访问。URL 响应头必须包含正确的 Content-LengthContent-Type
messages.content 内容块
type输入内容主要字段说明
text文本text可与图片、视频内容块混合传入。
image_url图片image_url.urlimage_url.detail(可选)、max_pixels(可选)url 支持公网 URL 或 data:image/{format};base64,...。同一条消息可包含多个图片块。
video_url视频文件video_url.urlfps(可选)url 支持公网 URL 或 data:video/{format};base64,...
video视频帧列表videofps(可选)video 为按时间顺序排列的图片 URL 或图片 Data URL 数组。
input_audio音频input_audio.datainput_audio.formatdata 支持公网 URL 或 Base64 Data URL,format 为实际音频格式,例如 mp3wav。仅支持音频理解的模型生效。

image_url.detail 用于控制图片解析精度,可选值为 lowhighautolow 适合速度和成本优先的场景,high 适合 OCR、图表和细节识别,auto 由模型自动选择;不传时使用模型默认策略。

单图输入(cURL)
shell
curl -L -X POST 'https://api.scnet.cn/api/llm/v1/chat/completions' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <API Key>' \
  --data-raw '{
    "model": "Qwen3.8-Max",
    "messages": [{
      "role": "user",
      "content": [
        {
          "type": "image_url",
          "image_url": {
            "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg",
            "detail": "auto"
          }
        },
        {"type": "text", "text": "图中描绘了什么?"}
      ]
    }]
  }'
单图输入(Python)
python
from openai import OpenAI

client = OpenAI(api_key="<API Key>", base_url="https://api.scnet.cn/api/llm/v1")
response = client.chat.completions.create(
    model="Qwen3.8-Max",
    messages=[{
        "role": "user",
        "content": [
            {
                "type": "image_url",
                "image_url": {
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg",
                    "detail": "high"
                }
            },
            {"type": "text", "text": "详细描述图片内容。"}
        ]
    }]
)
print(response.choices[0].message.content)
单图输入(Node.js)
javascript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "<API Key>",
  baseURL: "https://api.scnet.cn/api/llm/v1"
});

const response = await client.chat.completions.create({
  model: "Qwen3.8-Max",
  messages: [{
    role: "user",
    content: [
      {
        type: "image_url",
        image_url: {
          url: "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg",
          detail: "low"
        }
      },
      { type: "text", text: "用一句话描述图片。" }
    ]
  }]
});
console.log(response.choices[0].message.content);
多图输入

以下示例在同一请求中混合传入两张公网图片:

shell
curl -L -X POST 'https://api.scnet.cn/api/llm/v1/chat/completions' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <API Key>' \
  --data-raw '{
    "model": "Qwen3.8-Max",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "image_url",
            "image_url": {
              "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"
            }
          },
          {
            "type": "image_url",
            "image_url": {
              "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250212/earbrt/vcg_VCG211286867973_RF.jpg"
            }
          },
          {
            "type": "text",
            "text": "分别描述两张图片,并比较它们的不同。"
          }
        ]
      }
    ],
    "stream": false
  }'
Base64 图片输入

OpenAI 兼容协议不能直接传入本地文件路径。请先读取图片并编码为 Base64,再按照 data:image/{format};base64,{data} 组成完整 Data URL。MIME Type 必须与实际图片格式一致,例如 JPEG 使用 image/jpeg、PNG 使用 image/png

python
import base64
from openai import OpenAI

client = OpenAI(api_key="<API Key>", base_url="https://api.scnet.cn/api/llm/v1")
with open("image.jpg", "rb") as image_file:
    image_data = base64.b64encode(image_file.read()).decode("utf-8")

response = client.chat.completions.create(
    model="Qwen3.8-Max",
    messages=[{
        "role": "user",
        "content": [
            {
                "type": "image_url",
                "image_url": {
                    "url": f"data:image/jpeg;base64,{image_data}",
                    "detail": "auto"
                }
            },
            {"type": "text", "text": "识别图片中的内容。"}
        ]
    }]
)
print(response.choices[0].message.content)

Base64 编码后的字符串不得超过 10MB;示例中的 Base64 必须是完整内容,不能使用截断字符串。

图片输入限制
限制项说明
图像尺寸宽度和高度均须大于 10 像素;长边与短边之比不超过 200:1;建议控制在 8K 以内。
图像格式4K 以下支持 BMP、JPEG、PNG、TIFF、WEBP、HEIC;4K 至 8K 仅支持 JPEG、JPG、PNG。Base64 Data URL 的 MIME Type 必须与实际格式一致。
文件大小公网 URL:Qwen3.8 / Qwen3.7 / Qwen3.6 / Qwen3.5 系列单图不超过 20MB;Base64 编码后的字符串不超过 10MB。
图片数量公网 URL:Qwen3.8 / Qwen3.7 / Qwen3.6 / Qwen3.5 系列最多 2048 张;Base64 最多 250 张。同时受模型最大输入 Token 数限制。
视频输入

视觉模型会从视频文件中抽取帧序列进行分析。fps 取值范围为 [0.1, 10],默认值为 2.0;运动较快的视频可适当提高,静态或较长的视频可降低。max_frames 用于限制最大抽帧数,但只有下游模型支持该参数时才生效。

视频文件 URL
shell
curl -L -X POST 'https://api.scnet.cn/api/llm/v1/chat/completions' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <API Key>' \
  --data-raw '{
    "model": "Qwen3.8-Max",
    "messages": [{
      "role": "user",
      "content": [
        {
          "type": "video_url",
          "video_url": {
            "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241115/cqqkru/1.mp4"
          },
          "fps": 2
        },
        {"type": "text", "text": "概括这段视频的内容。"}
      ]
    }]
  }'

Base64 视频使用相同结构,将 URL 改为完整 Data URL:

json
{
  "type": "video_url",
  "video_url": {
    "url": "data:video/mp4;base64,<视频Base64编码>"
  },
  "fps": 2
}
视频帧列表
json
{
  "role": "user",
  "content": [
    {
      "type": "video",
      "video": [
        "https://example.com/frame-001.jpg",
        "https://example.com/frame-002.jpg",
        "https://example.com/frame-003.jpg",
        "https://example.com/frame-004.jpg"
      ],
      "fps": 2,
      "max_frames": 256
    },
    {"type": "text", "text": "按时间顺序描述视频中的动作。"}
  ]
}
视频输入限制
限制项说明
视频大小公网 URL:Qwen3.8 / Qwen3.7 / Qwen3.6 / Qwen3.5 系列不超过 2GB;Base64 编码后的字符串小于 10MB。
视频时长Qwen3.8 / Qwen3.7 / Qwen3.6 / Qwen3.5 系列为 2 秒至 2 小时。
视频格式MP4、AVI、MKV、MOV、FLV、WMV 等。
视频数量单次请求最多传入 64 个视频,同时受模型上下文和 Token 上限限制。
视频帧列表Qwen3.8 / Qwen3.7 / Qwen3.6 / Qwen3.5 系列为 4 至 8000 张。
音频轨道不解析视频文件中的音频。需要分析音频时,请使用支持音频输入的模型和对应协议。
音频输入

Chat Completions 协议使用 input_audio 内容块传入音频。input_audio.datainput_audio.format 均为必填字段:data 可以是模型服务能够访问的公网 URL,也可以是完整的 Base64 Data URL;format 必须与音频文件的实际格式一致,例如 mp3wav

模型能力说明:协议支持 input_audio 参数不代表所有模型都具备音频理解能力。本次上线的 Qwen3.8-Max 不支持音频输入。请以控制台模型列表展示的能力为准,选择支持音频理解的模型。

公网音频 URL
shell
curl -L -X POST 'https://api.scnet.cn/api/llm/v1/chat/completions' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <API Key>' \
  --data-raw '{
    "model": "<支持音频输入的模型ID>",
    "messages": [{
      "role": "user",
      "content": [
        {
          "type": "input_audio",
          "input_audio": {
            "data": "https://example.com/audio/sample.wav",
            "format": "wav"
          }
        },
        {"type": "text", "text": "请转写并概括这段音频。"}
      ]
    }]
  }'
Base64 音频

本地音频文件不能直接传入文件路径。请先编码为 Base64,并组成完整的 Data URL:

json
{
  "type": "input_audio",
  "input_audio": {
    "data": "data:audio/wav;base64,<音频Base64编码>",
    "format": "wav"
  }
}

公网 URL 的响应头必须包含正确的音频 Content-TypeContent-Length。Base64 Data URL 中声明的 MIME Type、format 字段和实际音频格式必须保持一致。

多模态多轮对话

多轮请求需要把历史消息按 user → assistant → user 的顺序重新放入 messages。图片或视频通常只需放在首次 user 消息中,后续追问可以只传文本;历史中的视觉内容仍会占用输入 Token。

当模型响应包含 reasoning_content 时,下一轮应至少保留上一轮 assistant 的 content;若下游模型要求连续传递思考上下文,再同时原样保留 reasoning_content。不要把 reasoning_content 拼入展示给最终用户的正文。

cURL 示例
shell
curl -L -X POST 'https://api.scnet.cn/api/llm/v1/chat/completions' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <API Key>' \
  --data-raw '{
    "model": "Qwen3.8-Max",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "image_url",
            "image_url": {
              "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"
            }
          },
          {"type": "text", "text": "图中描绘了什么?"}
        ]
      },
      {
        "role": "assistant",
        "content": "图中是一位女孩在海边与一只狗互动。"
      },
      {
        "role": "user",
        "content": "再说明一下画面的氛围。"
      }
    ],
    "stream": false
  }'
Python 示例(含流式续问)
python
from openai import OpenAI

client = OpenAI(api_key="<API Key>", base_url="https://api.scnet.cn/api/llm/v1")
messages = [{
    "role": "user",
    "content": [
        {
            "type": "image_url",
            "image_url": {
                "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"
            }
        },
        {"type": "text", "text": "图中描绘了什么?"}
    ]
}]

first = client.chat.completions.create(model="Qwen3.8-Max", messages=messages)
assistant_message = {
    "role": "assistant",
    "content": first.choices[0].message.content
}
reasoning = getattr(first.choices[0].message, "reasoning_content", None)
if reasoning:
    assistant_message["reasoning_content"] = reasoning

messages.extend([assistant_message, {"role": "user", "content": "再说明一下画面的氛围。"}])
stream = client.chat.completions.create(
    model="Qwen3.8-Max",
    messages=messages,
    stream=True
)
for chunk in stream:
    text = chunk.choices[0].delta.content
    if text:
        print(text, end="", flush=True)
Node.js 示例
javascript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "<API Key>",
  baseURL: "https://api.scnet.cn/api/llm/v1"
});

const messages = [{
  role: "user",
  content: [
    {
      type: "image_url",
      image_url: {
        url: "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"
      }
    },
    { type: "text", text: "图中描绘了什么?" }
  ]
}];

const first = await client.chat.completions.create({ model: "Qwen3.8-Max", messages });
const answer = first.choices[0].message;
messages.push({
  role: "assistant",
  content: answer.content,
  ...(answer.reasoning_content ? { reasoning_content: answer.reasoning_content } : {})
});
messages.push({ role: "user", content: "再说明一下画面的氛围。" });

const second = await client.chat.completions.create({
  model: "Qwen3.8-Max",
  messages,
  stream: true
});
for await (const chunk of second) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

OpenAI Responses API协议

创建响应

shell
POST https://api.scnet.cn/api/llm/v1/responses
1.功能介绍

兼容 OpenAI Responses API 协议的模型调用接口。相较于对话补全(Chat Completions)接口,Responses 接口具备以下优势:

  • 更灵活的输入input 支持直接传入字符串作为模型输入,也兼容 Chat 格式的消息数组。
  • 简化上下文管理:通过传递上一轮响应的 previous_response_id,无需手动构建完整的消息历史数组即可实现多轮对话。
  • 结构化输出:模型回复、思考内容、工具调用以统一的输出项(output item)数组返回,便于程序化处理。

注意

  1. 仅部分模型支持 Responses 协议,具体以 控制台 → 模型列表 标注为准,下文示例中的模型名称仅供参考。
  2. 本接口在设计上兼容 OpenAI Responses API,但部分 OpenAI 参数(如异步执行参数 background)暂不支持;未列出的参数是否生效取决于所调用的模型。
2.请求参数
Header 参数
名称类型必填示例值
Content-Typestringapplication/json
AuthorizationstringBearer <API Key>
Body 参数
名称类型必填默认值描述
modelstring\使用的模型的 ID。仅部分模型支持 Responses 协议,具体以控制台模型列表标注为准。
inputstring/array\模型输入,支持以下两种格式:
● string:纯文本,如 "你好"。
● array:消息数组,按对话顺序排列。数组元素支持以下类型:
    ○ 消息对象:包含 role(user / assistant / system / developer)与 content。content 为纯文本时是 string 类型;为结构化内容时是数组,元素 type 可选:
        - input_text:文本输入,配合 text 字段。
        - input_image:图片输入(仅 user 角色,需视觉模型支持),配合 image_url 字段(公网 URL 或 Base64 Data URL),detail 可选 low / high / auto。
        - input_file:文件输入(仅 user 角色),配合 file_url(文件公网 URL)字段,可附带 filename。仅支持控制台标注具备文件理解能力的模型。
        - output_text:助手回复(仅 assistant 角色),配合 text 字段。
    ○ function_call:模型上一轮返回的函数调用项(含 name、arguments、call_id),用于工具调用多轮对话时回传。
    ○ function_call_output:函数调用的执行结果(含 call_id、output),必须紧跟对应的 function_call 项。
    ○ reasoning:模型上一轮返回的思考内容项,可原样传回用于在多轮对话中传递思考内容。
注意:结构化内容的分块类型为 input_text / input_image / input_file,与 Chat Completions 协议的 text / image_url 命名不同。Responses 协议当前不支持视频或音频输入,请改用 Chat Completions 协议。
instructionsstring\系统指令,会插入到上下文的起始位置。使用 previous_response_id 时,上一轮指定的 instructions 不会自动传入本轮上下文。
previous_response_idstring\上一个响应的唯一 ID(来自上一轮响应的 id 字段)。使用此参数可创建多轮对话,服务端会自动检索并组合该轮次的输入与输出作为上下文。当同时提供 input 消息数组和 previous_response_id 时,input 中的新消息会追加到历史上下文之后。仅当上一轮请求 store=true 时可用。
streambooleanfalse是否开启流式输出。设置为 true 时,模型响应以 SSE 事件流的形式实时返回,事件格式见响应示例。
storebooleantrue是否储存本次生成的模型响应。
● true:储存,当前响应可被 previous_response_id 引用,并支持检索/删除/输入项查询接口。
● false:不储存,响应内容不能被 previous_response_id 和后续接口使用。
temperaturenumber\采样温度,取值范围 [0, 2),控制生成文本的多样性。值越高输出越随机,值越低输出越确定。temperature 与 top_p 均可控制多样性,建议只设置其中一个。
top_pnumber\核采样的概率阈值,取值范围 (0, 1]。值越高生成文本越多样,值越低越确定。建议不要与 temperature 同时修改。
toolsarray\模型在生成响应时可调用的工具数组。支持自定义 function 工具,元素属性:
● type(string,必选):固定为 function。
● name(string,必选):工具名称,仅允许字母、数字、下划线和短划线。
● description(string,必选):工具描述信息,帮助模型判断何时以及如何调用该工具。
● parameters(object,可选):工具入参描述,需为合法的 JSON Schema;为空表示该工具没有入参。
当模型判断需要调用工具时,响应会返回 function_call 类型的输出项。
注意:与 Chat Completions 协议不同,Responses 协议的 function 工具定义不包裹在 function 子对象中,name / description / parameters 直接与 type 同级。
tool_choicestring/objectauto控制模型如何选择和调用工具。字符串模式可选值:
● auto:模型自动决定是否调用工具。
● none:禁止模型调用任何工具。
● required:强制模型调用工具。
对象模式可通过 {"type": "allowed_tools", "mode": "auto", "tools": [...]} 限定模型可调用的工具范围。
reasoningobject\控制模型的思考强度,仅推理模型支持。属性 effort(string)为思考强度档位:
● none:关闭思考,直接回答
● minimal:最小化思考,最快速响应
● low:轻度思考,侧重快速响应
● medium(默认值):中度思考,平衡速度与思考深度
● high:深度思考,侧重处理复杂专业问题
开启思考后,思考内容通过 reasoning 类型的输出项返回,思考 token 计入 usage.output_tokens_details.reasoning_tokens。
enable_thinkingboolean\是否开启思考模式,仅推理模型支持。该参数为非 OpenAI 标准参数,reasoning.effort 的优先级高于 enable_thinking,建议优先使用 reasoning.effort。
3.响应参数
名称类型必填描述
idstring本次响应的唯一标识符,格式为 resp_xxx。可用作后续请求的 previous_response_id 以创建多轮对话,也可用于检索/删除/输入项查询接口。
objectstring对象类型,固定为 response。
created_atinteger本次请求的 Unix 时间戳(秒)。
statusstring响应生成的状态:
● completed:生成完成
● failed:生成失败
● in_progress:生成中
● cancelled:已取消
● queued:请求排队中
● incomplete:生成不完整
modelstring用于生成响应的模型 ID。
outputobject[]模型生成的输出项数组,元素类型和顺序取决于模型的响应。每个输出项都包含 type 与 id 字段:
● type=message:消息类型,包含模型最终生成的回复内容。附加字段:
    ○ role(string),固定为 assistant。
    ○ status(string),可选值 completed、in_progress。
    ○ content(array),内容数组,元素包含 type(固定为 output_text)、text(回复文本)、annotations(注释数组,通常为空)。
● type=reasoning:推理类型,开启思考模式时返回。附加字段:
    ○ summary(array),思考摘要数组,元素包含 type(固定为 summary_text)和 text(摘要文本)。
● type=function_call:函数调用类型,使用 function 工具时返回,需要处理函数调用并将结果回传。附加字段:
    ○ name(string),工具函数名称。
    ○ arguments(string),调用参数,JSON 字符串格式,使用前需解析。
    ○ call_id(string),工具调用的唯一标识符,回传 function_call_output 时需与其保持一致。
    ○ status(string),可选值 completed、in_progress。
usageobjectToken 统计信息,格式:
{
  "input_tokens": 整数, // 输入 Token 数(含缓存命中部分)
  "output_tokens": 整数, // 输出 Token 数(含思考过程)
  "total_tokens": 整数, // 总 Token 数
  "input_tokens_details": {
    "cached_tokens": 整数, // 缓存命中 Token 数
    "cache_creation_input_tokens": 整数, // 本次请求新创建缓存的 Token 数(启用 Session 缓存后返回)
    "cache_creation": { // 缓存创建详情(启用 Session 缓存后返回)
      "ephemeral_5m_input_tokens": 整数, // 5 分钟临时缓存新创建的 Token 数
      "cache_type": "ephemeral" // 缓存类型,固定为 ephemeral
    }
  },
  "output_tokens_details": {
    "reasoning_tokens": 整数 // 思考过程 Token 数
  },
  "x_details": [ // 计费明细数组,比顶级 usage 字段提供更细粒度的多模态 Token 拆分
    {
      "input_tokens": 整数, // 输入 Token 数
      "output_tokens": 整数, // 输出 Token 数
      "total_tokens": 整数, // 总 Token 数,为 input_tokens 与 output_tokens 的总和
      "x_billing_type": "response_api", // 计费类型,固定为 response_api
      "image_tokens": 整数, // 图像输入的 Token 数(包含图像输入时返回,等同于 input_tokens_details.image_tokens)
      "input_tokens_details": { // 输入 Token 的细粒度分类(多模态输入时返回,目前仅区分文本与图像)
        "text_tokens": 整数, // 文本输入的 Token 数
        "image_tokens": 整数 // 图像输入的 Token 数
      },
      "output_tokens_details": { // 输出 Token 的细粒度分类
        "reasoning_tokens": 整数, // 思考过程 Token 数
        "text_tokens": 整数 // 文本输出的 Token 数(多模态输入时返回)
      },
      "plugins": { // 内置工具调用统计(使用内置工具时返回,与顶级 x_tools 字段内容相同)
        "web_search": {"count": 整数} // 联网搜索调用统计,count 为本次响应中联网搜索的调用次数
      }
    }
  ],
  "x_tools": { // 内置工具使用统计信息(使用内置工具时返回,包含各工具的调用次数)
    "web_search": {"count": 整数} // 示例:{"web_search": {"count": 1}}
  }
}
仅部分模型支持上下文缓存。模型未开启缓存或本次请求未命中缓存时,cached_tokens 为 0。缓存命中计费规则详见 计费说明
cache_creation_input_tokens、cache_creation 仅在启用 Session 缓存后返回;含图像输入但未命中缓存时 input_tokens_details 可能返回空对象。x_details、x_tools 为非 OpenAI 标准字段,x_details 仅在部分场景返回,使用时请做好空值兼容。
errorobject当模型生成响应失败时返回的错误对象。成功时为 null。
toolsarray回显请求中 tools 参数的完整内容,无工具时为空数组。
tool_choicestring回显请求中 tool_choice 参数的值。
4.请求示例
cURL请求示例
shell
curl -L -X POST 'https://api.scnet.cn/api/llm/v1/responses' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <API Key>' \
--data-raw '{
  "model": "qwen3.7-plus",
  "instructions": "你是一个简洁的助手",
  "input": "你好,用一句话介绍你自己",
  "stream": false
}'
Python请求示例
  • OpenAI SDK
python
from openai import OpenAI

client = OpenAI(api_key="<API Key>", base_url="https://api.scnet.cn/api/llm/v1")

response = client.responses.create(
  model="qwen3.7-plus",
  instructions="你是一个简洁的助手",
  input="你好,用一句话介绍你自己"
)
print(response.output_text)
  • OpenAI SDK(多轮对话)
python
from openai import OpenAI

client = OpenAI(api_key="<API Key>", base_url="https://api.scnet.cn/api/llm/v1")

# 第一轮对话
response1 = client.responses.create(
  model="qwen3.7-plus",
  input="我叫小明,请记住我的名字。"
)
print(f"第一轮回复: {response1.output_text}")

# 第二轮对话:使用 previous_response_id 关联上下文,无需手动拼接历史消息
response2 = client.responses.create(
  model="qwen3.7-plus",
  input="你还记得我的名字吗?",
  previous_response_id=response1.id
)
print(f"第二轮回复: {response2.output_text}")
  • REQUESTS
python
import requests
import json

url = "https://api.scnet.cn/api/llm/v1/responses"

payload = json.dumps({
  "model": "qwen3.7-plus",
  "input": [
    {"role": "user", "content": "你好,用一句话介绍你自己"}
  ],
  "stream": False
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer <API Key>'
}

response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Nodejs请求示例
  • OpenAI SDK
javascript
import OpenAI from "openai";

const openai = new OpenAI({
        baseURL: 'https://api.scnet.cn/api/llm/v1',
        apiKey: '<API Key>'
});

async function main() {
  const response = await openai.responses.create({
    model: "qwen3.7-plus",
    input: "你好,用一句话介绍你自己"
  });

  console.log(response.output_text);
}

main();
视觉理解请求示例

Responses 协议使用 input_textinput_imageinput_file 内容块,不可使用 Chat Completions 的 textimage_url 内容块名称。以下示例均要求所选模型具备相应的视觉或文档理解能力。

  • detail=low:使用较低分辨率,适合对速度和成本敏感的场景。
  • detail=high:保留更多图像细节,适合 OCR、图表和细粒度识别。
  • detail=auto:由模型自动选择,未传时按模型默认策略处理。

cURL(图片 URL)

shell
curl -L -X POST 'https://api.scnet.cn/api/llm/v1/responses' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <API Key>' \
  --data-raw '{
    "model": "Qwen3.8-Max",
    "input": [{
      "role": "user",
      "content": [
        {"type": "input_text", "text": "图中描绘了什么?"},
        {
          "type": "input_image",
          "detail": "high",
          "image_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"
        }
      ]
    }]
  }'

Python(Base64 图片)

python
import base64
from openai import OpenAI

client = OpenAI(api_key="<API Key>", base_url="https://api.scnet.cn/api/llm/v1")
with open("image.jpg", "rb") as image_file:
    image_data = base64.b64encode(image_file.read()).decode("utf-8")

response = client.responses.create(
    model="Qwen3.8-Max",
    input=[{
        "role": "user",
        "content": [
            {"type": "input_text", "text": "识别图中的内容。"},
            {
                "type": "input_image",
                "detail": "auto",
                "image_url": f"data:image/jpeg;base64,{image_data}"
            }
        ]
    }]
)
print(response.output_text)

Node.js(图片 URL)

javascript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "<API Key>",
  baseURL: "https://api.scnet.cn/api/llm/v1"
});

const response = await client.responses.create({
  model: "Qwen3.8-Max",
  input: [{
    role: "user",
    content: [
      { type: "input_text", text: "用一句话描述图片。" },
      {
        type: "input_image",
        detail: "low",
        image_url: "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"
      }
    ]
  }]
});
console.log(response.output_text);

文件输入(URL)

shell
curl -L -X POST 'https://api.scnet.cn/api/llm/v1/responses' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <API Key>' \
  --data-raw '{
    "model": "<支持文件输入的模型ID>",
    "input": [{
      "role": "user",
      "content": [
        {
          "type": "input_file",
          "filename": "report.pdf",
          "file_url": "https://example.com/report.pdf"
        },
        {"type": "input_text", "text": "总结文档的主要内容。"}
      ]
    }]
  }'

视频说明:Responses 协议当前没有 input_video 内容块,也不支持音频输入。视频理解请调用 /v1/chat/completions,并使用 video_urlvideo 内容块。

5.响应示例
非流式响应示例
json
{
  "id": "resp_2976b65e-3915-9e6b-b6af-cdce652b84eb",
  "object": "response",
  "created_at": 1771165900,
  "status": "completed",
  "model": "qwen3.7-plus",
  "output": [
    {
      "id": "msg_89ad23e6-f128-4d4c-b7a1-a786e7880abc",
      "type": "message",
      "role": "assistant",
      "status": "completed",
      "content": [
        {
          "type": "output_text",
          "text": "你好!我是一个乐于助人的 AI 助手,可以帮你解答问题、处理文本和完成各类任务。",
          "annotations": []
        }
      ]
    }
  ],
  "parallel_tool_calls": false,
  "tool_choice": "auto",
  "tools": [],
  "usage": {
    "input_tokens": 57,
    "input_tokens_details": {
      "cached_tokens": 0
    },
    "output_tokens": 44,
    "output_tokens_details": {
      "reasoning_tokens": 0
    },
    "total_tokens": 101
  }
}
流式响应示例(stream=true)

流式输出返回一系列 SSE 事件,每个事件包含 type 字段标识事件类型、sequence_number 字段标识事件顺序。主要事件类型:

  • response.created / response.in_progress:响应创建、开始处理。
  • response.output_item.added / response.output_item.done:新的输出项(message、reasoning、function_call 等)开始与完成。
  • response.content_part.added / response.content_part.done:输出项的内容块开始与完成。
  • response.output_text.delta / response.output_text.done:增量回复文本(多次触发,客户端拼接所有 delta 即可获得完整文本)与文本完成。
  • response.reasoning_summary_text.delta / response.reasoning_summary_text.done:(开启思考模式时)思考摘要的增量与完成。
  • response.completed:响应生成完成,response 对象包含完整响应(含 usage),此事件标志流式传输结束。
// response.created - 响应创建
{"response":{"id":"resp_428c90e9-9cd6-90a6-9726-c02b08ebe123","created_at":1769082930,"object":"response","status":"queued"},"sequence_number":0,"type":"response.created"}

// response.in_progress - 响应进行中
{"response":{"id":"resp_428c90e9-9cd6-90a6-9726-c02b08ebe123","status":"in_progress"},"sequence_number":1,"type":"response.in_progress"}

// response.output_item.added - 新增输出项
{"item":{"id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8e456","content":[],"role":"assistant","status":"in_progress","type":"message"},"output_index":0,"sequence_number":2,"type":"response.output_item.added"}

// response.content_part.added - 新增内容块
{"content_index":0,"item_id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8e456","output_index":0,"part":{"annotations":[],"text":"","type":"output_text"},"sequence_number":3,"type":"response.content_part.added"}

// response.output_text.delta - 增量文本(多次触发)
{"content_index":0,"delta":"人工智能","item_id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8e456","output_index":0,"sequence_number":4,"type":"response.output_text.delta"}
{"content_index":0,"delta":"(Artificial Intelligence,","item_id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8e456","output_index":0,"sequence_number":5,"type":"response.output_text.delta"}

// response.output_text.done - 文本完成
{"content_index":0,"item_id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8e456","output_index":0,"sequence_number":53,"text":"人工智能(Artificial Intelligence,简称 AI)是指由计算机系统模拟人类智能行为的技术和科学...","type":"response.output_text.done"}

// response.content_part.done - 内容块完成
{"content_index":0,"item_id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8e456","output_index":0,"part":{"annotations":[],"text":"...完整文本...","type":"output_text"},"sequence_number":54,"type":"response.content_part.done"}

// response.output_item.done - 输出项完成
{"item":{"id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8e456","content":[{"annotations":[],"text":"...完整文本...","type":"output_text"}],"role":"assistant","status":"completed","type":"message"},"output_index":0,"sequence_number":55,"type":"response.output_item.done"}

// response.completed - 响应完成(包含完整响应和 usage)
{"response":{"id":"resp_428c90e9-9cd6-90a6-9726-c02b08ebe123","created_at":1769082930,"model":"qwen3.7-plus","object":"response","output":[...],"status":"completed","usage":{"input_tokens":37,"output_tokens":243,"total_tokens":280}},"sequence_number":56,"type":"response.completed"}

检索响应

shell
GET https://api.scnet.cn/api/llm/v1/responses/{response_id}
1.功能介绍

根据 Response ID 获取一个已完成的模型响应。仅当原创建请求中 store=true 时返回的 Response ID 可被检索。

注意:响应的存储有一定有效期,请在响应生成后及时查询,过期后接口将返回 Response ID 不存在的错误。

2.请求参数
Header 参数
名称类型必填示例值
AuthorizationstringBearer <API Key>
Path 参数
名称类型必填描述
response_idstring要获取的 Response ID,格式为 resp_xxx,来自创建响应接口返回的 id 字段。
3.响应参数

返回与创建响应接口相同的 Response 对象(含 idobjectstatuscreated_atmodeloutputusage 等字段,字段含义见创建响应的响应参数说明),并额外回显原创建请求中的采样参数(temperaturetop_p 等)与 storemetadata 等字段。

4.请求示例
cURL请求示例
shell
curl -L -X GET 'https://api.scnet.cn/api/llm/v1/responses/resp_xxx' \
-H 'Authorization: Bearer <API Key>'
Python请求示例
  • OpenAI SDK
python
from openai import OpenAI

client = OpenAI(api_key="<API Key>", base_url="https://api.scnet.cn/api/llm/v1")

response = client.responses.retrieve("resp_xxx")
print(response)
5.响应示例
json
{
  "id": "resp_801bc2c4-93d9-910f-b35d-5274f5a737c1",
  "object": "response",
  "status": "completed",
  "created_at": 1778676418,
  "completed_at": 1778676420,
  "model": "qwen3.7-plus",
  "output": [
    {
      "id": "msg_8c54756c-9b65-4a95-81d7-4276d91406db",
      "type": "message",
      "role": "assistant",
      "status": "completed",
      "content": [
        {
          "type": "output_text",
          "text": "你好!很高兴见到你。有什么我可以帮助你的吗?",
          "annotations": []
        }
      ]
    }
  ],
  "store": true,
  "tool_choice": "auto",
  "tools": [],
  "usage": {
    "input_tokens": 45,
    "input_tokens_details": {
      "cached_tokens": 0
    },
    "output_tokens": 63,
    "output_tokens_details": {
      "reasoning_tokens": 0
    },
    "total_tokens": 108
  }
}

当指定的 Response ID 不存在或已过期时,返回以下错误:

json
{
    "error": {
        "message": "Response with id 'resp_xxx' not found.",
        "type": "InvalidParameter"
    }
}

删除响应

shell
DELETE https://api.scnet.cn/api/llm/v1/responses/{response_id}
1.功能介绍

根据 Response ID 删除一个已存储的模型响应。仅当原创建请求中 store=true 时返回的 Response ID 可被删除。

2.请求参数
Header 参数
名称类型必填示例值
AuthorizationstringBearer <API Key>
Path 参数
名称类型必填描述
response_idstring要删除的 Response ID,格式为 resp_xxx。
3.响应参数
名称类型描述
idstring被删除的 Response ID。
deletedboolean是否删除成功,成功为 true。
4.请求示例
cURL请求示例
shell
curl -L -X DELETE 'https://api.scnet.cn/api/llm/v1/responses/resp_xxx' \
-H 'Authorization: Bearer <API Key>'
Python请求示例
  • OpenAI SDK
python
from openai import OpenAI

client = OpenAI(api_key="<API Key>", base_url="https://api.scnet.cn/api/llm/v1")

response = client.responses.delete("resp_xxx")
print(response)
5.响应示例
json
{
  "id": "resp_4ca7fa5e-6ff5-9787-bc18-af6ca5eff36c",
  "deleted": true
}

查询输入项列表

shell
GET https://api.scnet.cn/api/llm/v1/responses/{response_id}/input_items
1.功能介绍

获取生成指定 Response 时所使用的输入项列表。在多轮对话(使用 previous_response_id 串联)中,会一并返回历史轮次的用户输入和模型回复。仅当原创建请求中 store=true 时返回的 Response ID 支持查询。

2.请求参数
Header 参数
名称类型必填示例值
AuthorizationstringBearer <API Key>
Path 参数
名称类型必填描述
response_idstring要查询输入项的 Response ID,格式为 resp_xxx。
Query 参数
名称类型必填默认值描述
afterstring\以指定的输入项 ID(格式为 msg_xxx)作为起点,返回排在该 ID 之后的数据,顺序由 order 决定。常用于翻页:把上一次返回的 last_id 作为本次的 after 传入,即可继续获取后续数据。
limitinteger20返回的最大条数,取值范围 [1, 100]。
orderstringdesc排序方式,支持 asc(升序)和 desc(降序)。
3.响应参数
名称类型描述
dataobject[]输入项列表。每个元素是一个消息对象,包含 id、role、content、type、status 字段。role 取值为 user 或 assistant;content 中元素的 type 取值为 input_text(用户输入)或 output_text(模型回复)。多轮对话中按发生顺序包含历史用户消息与历史模型回复。
first_idstring列表中第一个元素的 ID。
last_idstring列表中最后一个元素的 ID。
has_moreboolean是否还有未返回的数据。当为 true 时,把本次返回的 last_id 作为下一次请求的 after 参数,可继续获取后续数据。
idstring对应的 Response ID。
modelstring生成该 Response 时使用的模型名称。
created_atintegerResponse 创建时间的 Unix 时间戳(毫秒)。注意:与创建响应/检索响应接口返回的 created_at(秒)单位不同。
previous_response_idstring多轮对话(使用 previous_response_id 串联)时返回,值为上一轮的 Response ID。
4.请求示例
cURL请求示例
shell
curl -L -X GET 'https://api.scnet.cn/api/llm/v1/responses/resp_xxx/input_items?after=msg_xxx&limit=10&order=asc' \
-H 'Authorization: Bearer <API Key>'
Python请求示例
  • OpenAI SDK
python
from openai import OpenAI

client = OpenAI(api_key="<API Key>", base_url="https://api.scnet.cn/api/llm/v1")

response = client.responses.input_items.list("resp_xxx")
print(response.data)
5.响应示例
json
{
  "id": "resp_4ca7fa5e-6ff5-9787-bc18-af6ca5eff36c",
  "model": "qwen3.7-plus",
  "created_at": 1778674066000,
  "data": [
    {
      "id": "msg_8dac4972-fdba-42b5-bed9-280441ced8ea",
      "type": "message",
      "role": "user",
      "status": "completed",
      "content": [
        {
          "type": "input_text",
          "text": "你好"
        }
      ]
    }
  ],
  "first_id": "msg_8dac4972-fdba-42b5-bed9-280441ced8ea",
  "last_id": "msg_8dac4972-fdba-42b5-bed9-280441ced8ea",
  "has_more": false
}

Anthropic 协议

shell
POST https://api.scnet.cn/api/llm/anthropic/v1/messages

1.功能介绍

兼容 Anthropic 协议的对话补全能力,根据输入的上下文生成符合 Anthropic 规范的对话响应。

2.请求参数

Header 参数
名称类型必填示例值描述
Content-Typestringapplication/json请求体内容类型
AuthorizationstringBearer <API Key>身份验证,格式为 Bearer + API Key
anthropic-versionstring2023-06-01anthropic版本,可不填
Body 参数
名称类型支持状态必填描述
modelstring支持使用的模型 ID。支持范围包括平台已接入的千问、DeepSeek、Kimi、GLM、MiniMax 等模型,实际可用模型及能力以控制台 → 模型列表为准。图片和视频内容块仅对视觉模型生效。
messagesarray部分支持支持文本、工具调用,以及视觉模型的图片和视频输入;暂不支持 type=document 文档内容块。
- 每个消息包含 role(user/assistant)和 content 字段
- content 可以是字符串或结构化内容数组
- 以 user 消息开头,user 和 assistant 按对话顺序交替出现
- 系统提示词需通过 system 字段传递,而非 messages 中的 system 角色
max_tokensinteger支持模型生成的最大 token 数
streamboolean支持是否开启流式响应
systemstring/array支持系统提示词,用于设定模型的行为和规则
temperaturenumber支持采样温度,取值范围 (0.0, 1.0],控制输出随机性,较高的值增加随机性,较低的值更确定, 建议取值 1
tool_choicestring/object支持工具选择策略
toolsarray支持工具定义。每个工具必须包含input_schema,否则会报错。已知Claude Code自带的web_search工具不支持
top_pnumber支持核采样参数
metadataobject支持自定义元数据,Anthropic 协议兼容字段,格式为 {"user_id": "xxx"},用于标识用户,无实际业务逻辑影响
thinkingobject支持思考模式配置 type 取值:
- enabled:开启思考模式,模型在生成回复前会先进行推理,以提升回答准确度。可设置 budget_tokens限制思考过程的 Token 上限。
- disabled:关闭思考模式。
仅DeepSeek V4系列模型支持
reasoning_effortobject支持控制模型的推理强度。可选值:high、max,默认为max。仅DeepSeek V4系列模型支持
stop_sequencesarray忽略该参数会被忽略
top_knumber忽略该参数会被忽略
service_tierstring忽略该参数会被忽略
mcp_serversarray忽略该参数会被忽略
context_managementobject忽略该参数会被忽略
containerobject忽略该参数会被忽略

Messages 字段支持说明

字段类型支持状态必填描述
type="text"支持文本消息
type="tool_use"支持工具调用
type="tool_result"支持工具调用结果
type="thinking"不支持推理内容
type="image"条件支持图片输入,仅视觉模型生效。通过 source 传入公网 URL 或 Base64 数据。
type="video"条件支持视频输入,仅支持视频理解的视觉模型生效。通过 source 传入公网 URL 或 Base64 数据。
type="document"不支持暂不支持 Anthropic 的文档内容块。请使用 Responses 协议的 input_file;或将文档转为图片后,通过 Chat Completions 协议传入。

图片和视频内容块的 source 字段说明:

字段类型必填说明
source.typestringurl 表示公网 URL,base64 表示 Base64 编码。
source.urlstring条件必填source.type=url 时必填,URL 必须能够被模型服务访问。
source.media_typestring条件必填source.type=base64 时必填,例如 image/jpegimage/pngvideo/mp4
source.datastring条件必填source.type=base64 时必填,只传 Base64 编码本体,不包含 data:...;base64, 前缀。

3.响应参数

名称类型必填描述
idstring对话唯一标识符,格式兼容 Anthropic 规范(如 msg_xxxx)。
typestring响应类型,固定为 "message"(Anthropic 规范)。
rolestring响应消息的角色,固定为 "assistant"。
contentarray模型生成的内容列表,每个元素为 {"type": "text", "text": "生成内容"} 格式。
modelstring生成响应的模型名,兼容 Anthropic 模型名格式。
stop_reasonstring停止生成原因,映射原 finish_reason:
- "end_turn":对应 stop
- "max_tokens":对应 length
- "content_filter":对应 content_filter
- "error":对应 insufficient_system_resource
usageobjectToken 统计信息,格式:
{
  "input_tokens": 整数, // 输入 token 数(不包含缓存tokens)
  "output_tokens": 整数, // 输出 token 数
  "cache_read_input_tokens": 整数, // 缓存命中 token 数(从缓存读取的输入 token)
  "cache_creation_input_tokens": 整数, // 缓存写入 token 数(本次请求写入缓存的输入 token)
  "output_tokens_details": {
    "thinking_tokens": 整数 // 思考(推理)token 数
  }
}
注意:与 OpenAI 协议不同(cached_tokens 是 prompt_tokens 的子集),Anthropic 协议中 input_tokens 不包含缓存部分,输入总 token 数 = input_tokens + cache_read_input_tokens + cache_creation_input_tokens。仅部分模型支持上下文缓存,未开启缓存或未命中时缓存字段为 0。

4.请求示例

cURL请求示例
shell
curl https://api.scnet.cn/api/llm/anthropic/v1/messages \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -H "Authorization: Bearer <API KEY>" \
  -d '{
      "messages":  [
        {"role": "user", "content": "你好"}
      ],
      "model": "MiniMax-M2.5",
      "max_tokens":196000,
      "stream": false
    }'
Python请求示例
python
import requests
import json

url = "https://api.scnet.cn/api/llm/anthropic/v1/messages"

payload = json.dumps({
    "messages":  [
        {"role": "user", "content": "你好"}
    ],
    "model": "MiniMax-M2.5",
    "max_tokens":196000,
    "stream": false
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer <API Key>'
}

response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
图片 URL 请求示例
shell
curl -L -X POST 'https://api.scnet.cn/api/llm/anthropic/v1/messages' \
  -H 'Content-Type: application/json' \
  -H 'anthropic-version: 2023-06-01' \
  -H 'Authorization: Bearer <API Key>' \
  --data-raw '{
    "model": "Qwen3.8-Max",
    "max_tokens": 1024,
    "messages": [{
      "role": "user",
      "content": [
        {
          "type": "image",
          "source": {
            "type": "url",
            "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"
          }
        },
        {"type": "text", "text": "图中描绘了什么?"}
      ]
    }],
    "stream": false
  }'
Base64 图片请求示例
python
import base64
import requests

with open("image.jpg", "rb") as image_file:
    image_data = base64.b64encode(image_file.read()).decode("utf-8")

response = requests.post(
    "https://api.scnet.cn/api/llm/anthropic/v1/messages",
    headers={
        "Content-Type": "application/json",
        "anthropic-version": "2023-06-01",
        "Authorization": "Bearer <API Key>"
    },
    json={
        "model": "Qwen3.8-Max",
        "max_tokens": 1024,
        "messages": [{
            "role": "user",
            "content": [
                {
                    "type": "image",
                    "source": {
                        "type": "base64",
                        "media_type": "image/jpeg",
                        "data": image_data
                    }
                },
                {"type": "text", "text": "识别图片中的内容。"}
            ]
        }]
    }
)
print(response.json())

视频输入使用同样的 source 结构,将内容块类型改为 video,并使用视频 MIME Type:

json
{
  "type": "video",
  "source": {
    "type": "url",
    "url": "https://example.com/video.mp4"
  }
}

5.响应示例

json
{
    "id": "chatcmpl-f0ef02e4e54c628bd05fea07cd0b178e",
    "type": "message",
    "role": "assistant",
    "content": [
        {
            "type": "text",
            "text": "\n\n你好!有什么我可以帮助你的吗?"
        }
    ],
    "model": "MiniMax-M2.5",
    "stop_reason": "end_turn",
    "usage": {
        "input_tokens": 40,
        "output_tokens": 30,
        "cache_read_input_tokens": 20,
        "cache_creation_input_tokens": 0,
        "output_tokens_details": {
            "thinking_tokens": 0
        }
    }
}
流式响应示例(stream=true)
event: message_start
data: {"type":"message_start","message":{"id":"chatcmpl-17559d29890659196503f551da1f0ef4","content":[],"model":"MiniMax-M2.5","usage":{"input_tokens":40,"output_tokens":0,"cache_read_input_tokens":20,"cache_creation_input_tokens":0}}}

event: content_block_start
data: {"type":"content_block_start","content_block":{"type":"text","text":""},"index":0}

event: content_block_delta
data: {"type":"content_block_delta","delta":{"type":"text_delta","text":">\n"},"index":0}

event: content_block_delta
data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"\n你"},"index":0}

event: content_block_delta
data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"好"},"index":0}

event: content_block_delta
data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"!有什"},"index":0}

event: content_block_delta
data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"么我可"},"index":0}

event: content_block_delta
data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"以帮"},"index":0}

event: content_block_delta
data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"助你"},"index":0}

event: content_block_delta
data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"的"},"index":0}

event: content_block_delta
data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"吗"},"index":0}

event: content_block_stop
data: {"type":"content_block_stop","index":0}

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"input_tokens":40,"output_tokens":29}}

event: message_stop
data: {"type":"message_stop"}

data: [DONE]