API 文档开始接入

沙箱

沙箱是一套免费的联调接口:请求格式、响应格式、错误格式都和正式接口一致,但返回的是模拟结果,不调用模型、不扣积分、不保存记录。开发阶段对接沙箱地址,上线时切换到正式地址即可。

正式接口地址

https://01router.com/api/v1

沙箱接口地址

https://01router.com/api/sandbox/v1

支持的接口

POST/chat/completions支持

OpenAI 兼容的对话接口,立即返回固定回复;"stream": true 时以 SSE 分段返回,最后发送 usage 和 [DONE]。

POST/generations支持

校验模型是否存在,然后返回 processing 状态的任务,任务 ID 以 sbx_ 开头。不扣积分。

GET/generations/{id}支持

创建后约 3 秒内为 processing,之后变为 succeeded,返回提示词库中的真实素材:优先使用同一模型的图片、视频或音频,没有则使用同类型的素材。

POST/generations/{id}/cancel支持

任务处于 processing 时可取消(状态 failed,错误为 "Canceled by user");已完成时返回 409 not_cancelable。

GET/generations支持

沙箱任务不保存,因此始终返回空列表。

POST/images/generations支持

OpenAI 兼容的图片生成接口,立即返回提示词库中的 n 张示例图片,支持 url 和 b64_json 两种格式。

GET/models · /models/{slug}支持

查询不收费,因此 307 重定向到正式模型列表,返回的是真实数据。

POST/quote使用正式接口

沙箱不提供。报价不收费,请直接调用正式接口。

GET/prompts · /prompts/{id}使用正式接口

沙箱不提供。提示词库不收费,请直接调用正式接口。

请求

OpenAI SDK · 切换 base URL
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env.API_KEY,
  // Live: https://01router.com/api/v1
  baseURL: 'https://01router.com/api/sandbox/v1',
});

const reply = await client.chat.completions.create({
  model: 'gpt-6-sol',
  messages: [{ role: 'user', content: 'Hello!' }],
});
cURL · 创建任务
curl 'https://01router.com/api/sandbox/v1/generations' \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "seedance-2.5",
  "input": {
    "prompt": "A red fox running through fresh snow, cinematic"
  }
}'
cURL · 查询任务
curl 'https://01router.com/api/sandbox/v1/generations/sbx_example' \
  -H "Authorization: Bearer $API_KEY"
cURL · 模拟错误
curl 'https://01router.com/api/sandbox/v1/generations' \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Sandbox-Error: 402" \
  -d '{"model":"seedance-2.5","input":{"prompt":"A red fox running through fresh snow, cinematic"}}'

响应示例

200 · application/json
{
  "id": "sbx_example",
  "object": "generation",
  "model": "seedance-2.5",
  "type": "video",
  "provider": "sandbox",
  "status": "processing",
  "input": {
    "prompt": "A red fox running through fresh snow, cinematic"
  },
  "outputs": [],
  "error": null,
  "credits": 0,
  "price_usd": 0,
  "created_at": "2026-10-25T08:00:00.000Z",
  "completed_at": null
}
200 · 约 3 秒后再次查询
{
  "id": "sbx_example",
  "object": "generation",
  "model": "seedance-2.5",
  "type": "video",
  "provider": "sandbox",
  "status": "succeeded",
  "input": {},
  "outputs": [
    "https://example.com/sandbox.mp4"
  ],
  "error": null,
  "credits": 0,
  "price_usd": 0,
  "created_at": "2026-10-25T08:00:00.000Z",
  "completed_at": "2026-10-25T08:00:03.000Z"
}
402 · X-Sandbox-Error: 402
{
  "error": {
    "message": "Sandbox simulated 402 error",
    "code": "insufficient_credits"
  }
}

响应仅用于说明结构;ID、用量、价格和结果以实际请求为准。

使用说明

  • 上线时只需把 base URL 改回 https://01router.com/api/v1。请求体、响应字段和错误格式都不变,其他代码无需修改。切换后每次请求都会真实调用模型并扣费。
  • 使用平时的 API Key,放在 Authorization: Bearer sk_… 中。沙箱只校验 Key 的格式,不查询 Key 本身,因此项目限制、IP 白名单和 Key 额度都不生效。
  • 生成任务先保持约 3 秒 processing,然后变为 succeeded,轮询逻辑可以和正式环境完全一样运行。输出来自提示词库的真实素材,优先按模型选取,没有则按类型选取;同一个任务每次查询返回的结果相同。
  • 对话接口始终返回同一句回复。usage.prompt_tokens 按你的 messages 估算,completion_tokens 按回复长度计算;请求 json_object 或 json_schema 时返回一个简单的 JSON 对象。
  • 测试错误处理时,在请求头加上 X-Sandbox-Error,取值 400、401、402、404、429、500、502 或 503。所有支持的接口都会返回对应状态码,错误体格式与正式接口一致(error.message 和 error.code)。
  • 沙箱任务 ID 以 sbx_ 开头,只能在沙箱中查询;正式任务 ID 也不能在沙箱中查询。
  • 以下内容不模拟:各模型的参数校验、供应商路由、项目与自定义模型、Key 额度、callback_url 回调和价格(credits 与 price_usd 始终为 0)。沙箱请求不会出现在任务日志和用量统计中,按 IP 限流约每秒 10 次。

给 AI 使用

把文档索引或完整接口文档交给 AI 编程助手,包含实时模型参数。