结构化输出 / TypeSafe

区分通用 JSON 输出与尚未接入的专用 TypeSafe 接口。

接入状态

雪糕 AI 当前没有配置专用 TypeSafe / System One 接口。本页保留接入说明位置,后续开放后补充;请勿将其他平台的 /v1/systemone 示例直接用于本站。

使用支持 JSON 输出的模型

如果只需要程序可读取的 JSON,可选择支持 response_format 的模型,通过标准 Chat Completions 接口调用。该能力是否可用以模型和渠道为准。

cURL

curl --fail-with-body --max-time 120 "https://xuegaoai.com/v1/chat/completions" \
  -H "Authorization: Bearer $XUEGAOAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "YOUR_MODEL_ID",
  "messages": [
    {
      "role": "system",
      "content": "Return a JSON object with a string field named category."
    },
    {
      "role": "user",
      "content": "Classify this request: I need help with my invoice."
    }
  ],
  "response_format": {
    "type": "json_object"
  }
}'

Python

import json
import os
import urllib.request

body = json.loads('''{
  "model": "YOUR_MODEL_ID",
  "messages": [
    {
      "role": "system",
      "content": "Return a JSON object with a string field named category."
    },
    {
      "role": "user",
      "content": "Classify this request: I need help with my invoice."
    }
  ],
  "response_format": {
    "type": "json_object"
  }
}''')
request = urllib.request.Request(
    "https://xuegaoai.com/v1/chat/completions",
    data=json.dumps(body).encode("utf-8"),
    headers={
        "Authorization": "Bearer " + os.environ["XUEGAOAI_API_KEY"],
        "Content-Type": "application/json",
    },
    method="POST",
)
with urllib.request.urlopen(request, timeout=120) as response:
    print(json.dumps(json.load(response), ensure_ascii=False, indent=2))

Node.js

const response = await fetch("https://xuegaoai.com/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.XUEGAOAI_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "model": "YOUR_MODEL_ID",
  "messages": [
    {
      "role": "system",
      "content": "Return a JSON object with a string field named category."
    },
    {
      "role": "user",
      "content": "Classify this request: I need help with my invoice."
    }
  ],
  "response_format": {
    "type": "json_object"
  }
}),
  signal: AbortSignal.timeout(120_000),
});
if (!response.ok) {
  throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
console.log(await response.json());

在应用端校验结果

  1. 解析 JSON 后,用应用的数据结构或 schema 验证字段和类型。
  2. 对缺字段、空结果或拒答保留降级逻辑。
  3. 记录响应中的实际模型 ID 与请求 ID,便于排查和复现。

返回文档目录