OAIRoute 快速上手
OAIRoute 是一个 OpenAI 兼容的 API 网关:一个端点接入 GPT、Claude、Gemini 等主流模型,文本、语音、图像、视频共用同一套接口格式。
现有代码只需改一处:把地址指向 OAIRoute,其余照旧,三分钟就能跑通第一次调用。
OAIRoute is an OpenAI-compatible API gateway: one endpoint for GPT, Claude, Gemini, and other mainstream models, with text, speech, image, and video sharing a single request format.
Existing code needs one change: point the URL at OAIRoute and everything else stays the same. You'll be making your first call within three minutes.
接入地址
| 地址 | 承载的模型 |
|---|---|
api.oairoute.com | GPT、Claude、Gemini 等前沿模型,以及大部分图像与视频接口direct.oairoute.com 为直连备用 |
ark.oairoute.com | Seedance 系列与 Seedream 系列:视频、图像 |
api.oairoute.com 就够了,Key 与控制台都在那里创建。只有 Seedance 系列与 Seedream 系列走 ark.oairoute.com,这部分需要到 ark 站 单独获取 Key,与 api 站的 Key 不通用。其余图像与视频接口仍然使用 api 站的 Key。| Endpoint | Models it serves |
|---|---|
api.oairoute.com | Frontier models such as GPT, Claude, and Gemini, plus most image and video endpoints; direct.oairoute.com is a direct-connect backup |
ark.oairoute.com | The Seedance series and Seedream series: video and image |
api.oairoute.com covers the vast majority of endpoints, and your key and console live there. Only the Seedance and Seedream series go through ark.oairoute.com, which needs a key obtained separately from the ark site — it isn't shared with the api site's key. All other image and video endpoints still use the api site's key.第一次调用
从注册到跑通第一次请求,一共六步。前三步准备账号,后三步接入代码。下面的代码可以直接复制,把占位符换掉就能跑。
- 1注册账号
打开 注册页,填邮箱和密码完成注册。也可以用已支持的第三方账号登录。注册后邮箱会收到验证邮件,没收到就去垃圾箱找一下。
- 2
- 3准备额度
没有额度,Key 建好了也用不了,调用会直接返回 402
payment_required。在控制台的充值入口(钱包 / 充值页)充入金额后即可使用。额度是整个账户共用的,不是按 Key 分开的。 - 4创建 API Key
在控制台左侧「令牌」页面点新建,复制那串
sk-开头的字符。它相当于账号密码,不要发给别人。可以为不同项目建不同的 Key,方便分开统计用量和随时吊销某一个。 - 5把地址指向 OAIRoute
在 SDK 或客户端里把「API 地址」设为
https://api.oairoute.com/v1,其余配置不动。- 用 OpenAI 官方 SDK(Python / Node.js 等):填
base_url/baseURL参数 - 用 curl、Postman 或自己写 HTTP 请求:把 URL 里的
api.openai.com换成api.oairoute.com - 用第三方客户端(ChatBox、Cherry Studio 等):在设置里找到「API 地址 / Base URL」,填
https://api.oairoute.com/v1 - 代码里的
YOUR_MODEL_ID换成真实模型名,到模型广场找到你要用的模型复制
from openai import OpenAI client = OpenAI( api_key="YOUR_OAIRoute_KEY", base_url="https://api.oairoute.com/v1", ) res = client.chat.completions.create( model="YOUR_MODEL_ID", messages=[{"role": "user", "content": "你好"}], ) print(res.choices[0].message.content)curl https://api.oairoute.com/v1/chat/completions \ -H "Authorization: Bearer YOUR_OAIRoute_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "YOUR_MODEL_ID", "messages": [{"role": "user", "content": "你好"}] }' - 用 OpenAI 官方 SDK(Python / Node.js 等):填
- 6看返回结果
收到包含
choices字段的 JSON,且content里有文字,就说明接通了。返回结构见下一节。如果返回 401,检查 Key 是否复制完整、Bearer 后是否有一个空格;返回 402,回到第三步确认额度。
From sign-up to a working first request is six steps. The first three prepare the account; the last three wire up the code. The snippets below can be copied as-is; just replace the placeholders.
- 1Create an account
Open the sign-up page, enter an email and password, and register. You can also sign in with a supported third-party account. A verification email follows registration; check spam if it doesn't arrive.
- 2Sign in to the console
Open the sign-in page and go to the console. The console shows your balance, usage, token list, and call log; everything from here on happens there.
- 3Add balance
Without balance, a key won't work — calls return 402
payment_required. Top up through the console's wallet page and you're ready. Balance is shared across the whole account, not split per key. - 4Create an API key
On the "Tokens" page in the left sidebar, click to create one and copy the
sk-string. It works like a password; don't share it. Create separate keys for different projects to track usage separately and revoke them individually. - 5Point the URL at OAIRoute
In your SDK or client, set the API URL to
https://api.oairoute.com/v1and leave everything else alone.- With the official OpenAI SDK (Python, Node.js, etc.): set the
base_url/baseURLparameter - With curl, Postman, or your own HTTP requests: replace
api.openai.comin the URL withapi.oairoute.com - With a third-party client (ChatBox, Cherry Studio, etc.): find "API URL / Base URL" in settings and enter
https://api.oairoute.com/v1 - Replace
YOUR_MODEL_IDin the code with a real model name, copied from the model catalog
from openai import OpenAI client = OpenAI( api_key="YOUR_OAIRoute_KEY", base_url="https://api.oairoute.com/v1", ) res = client.chat.completions.create( model="YOUR_MODEL_ID", messages=[{"role": "user", "content": "Hello"}], ) print(res.choices[0].message.content)curl https://api.oairoute.com/v1/chat/completions \ -H "Authorization: Bearer YOUR_OAIRoute_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "YOUR_MODEL_ID", "messages": [{"role": "user", "content": "Hello"}] }' - With the official OpenAI SDK (Python, Node.js, etc.): set the
- 6Check the response
If you get JSON containing a
choicesfield with text incontent, you're connected. The structure is described in the next section. A 401 means the key was copied incompletely or the space afterBeareris missing; a 402 means you should revisit step 3.
返回结构
不同接口的返回形式不一样,对照着看就知道调用是否正常。
对话接口(最常用)返回 choices,回答在 message.content 里:
{
"id": "chatcmpl-01KA040M0HP1GJWBJYZMKX1XS1",
"object": "chat.completion",
"created": 1763088289,
"model": "<你的模型 ID>",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "你好!有什么可以帮你的?" },
"finish_reason": "stop"
}
],
"usage": { "prompt_tokens": 9, "completion_tokens": 12, "total_tokens": 21 }
}图像与视频接口是异步的,提交后先返回任务 ID,不会立刻给结果:
{
"code": 200,
"data": [
{ "status": "submitted", "task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K" }
]
}拿到 task_id 后查 /v1/tasks/{task_id},完成时返回文件地址:
{
"code": 200,
"data": [
{
"status": "completed",
"result": { "images": ["https://.../result.png"] }
}
]
}出错时所有接口都返回统一的错误体,code 说明原因:
{
"error": {
"code": 401,
"message": "身份验证失败,请检查您的API密钥",
"type": "authentication_error"
}
}完整的状态码含义、重试建议与处理方式,见错误码与限流。
Different endpoints return different shapes; comparing against these tells you whether a call worked.
Chat endpoints (the most common) return choices, with the answer in message.content:
{
"id": "chatcmpl-01KA040M0HP1GJWBJYZMKX1XS1",
"object": "chat.completion",
"created": 1763088289,
"model": "<your model ID>",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "Hello! How can I help?" },
"finish_reason": "stop"
}
],
"usage": { "prompt_tokens": 9, "completion_tokens": 12, "total_tokens": 21 }
}Image and video endpoints are asynchronous: submission returns a task ID rather than the result:
{
"code": 200,
"data": [
{ "status": "submitted", "task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K" }
]
}Once you have the task_id, query /v1/tasks/{task_id}; when it completes you get a file URL:
{
"code": 200,
"data": [
{
"status": "completed",
"result": { "images": ["https://.../result.png"] }
}
]
}On error every endpoint returns a uniform error body, with code explaining why:
{
"error": {
"code": 401,
"message": "Authentication failed, please check your API key",
"type": "authentication_error"
}
}For the full set of status codes, retry guidance, and handling, see Error codes and rate limits.
接口一览
平台优势
- 换地址即可迁移:请求体与返回结构沿用 OpenAI 标准,现有 SDK 和代码不用改
- 多供应商路由:同一模型可在多家上游之间调度,单家抖动时自动切换
- 服务可用性:多线路冗余与自动故障转移,面向企业提供明确的可用性指标与故障响应时限
- 全球 CDN 加速:边缘节点就近接入,降低跨境链路的首包延迟
- 实时状态监控:线路与模型可用性实时监测,异常可到 状态页 查看
- 计价透明:模型列表接口直接返回输入、输出与按次计费单价,调用前就能核算成本
- 异步可追踪:图像视频提交后返回任务 ID,可轮询,也可配 Webhook 回调
- Migrate by changing a URL: request and response structures follow the OpenAI standard, so existing SDKs and code need no changes
- Multi-vendor routing: the same model can be served by several upstreams, switching automatically when one hiccups
- Service availability: redundant routes and automatic failover, with explicit availability targets and incident response times for enterprise users
- Global CDN acceleration: edge nodes near you cut first-byte latency on cross-border links
- Real-time status monitoring: route and model availability is monitored continuously; check the status page for incidents
- Transparent pricing: the models list endpoint returns input, output, and per-call prices, so you can budget before calling
- Trackable async work: image and video submissions return a task ID you can poll, or receive via webhook
SDK 与代码示例
官方 SDK 不用换,直接用 OpenAI、Anthropic、Google 各自的库,只改初始化时的地址和 Key。下面只保留初始化部分,请求调用照原样写即可。
Python
通过 pip install openai 安装。设置 Base URL 并使用现有 OpenAI 代码,无需修改。
from openai import OpenAI
client = OpenAI(
api_key="YOUR_OAIRoute_KEY",
base_url="https://api.oairoute.com/v1",
)Node.js
通过 npm install openai 安装。配置 baseURL 参数为 OAIRoute 端点,保留现有集成。
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_OAIRoute_KEY",
baseURL: "https://api.oairoute.com/v1",
});Claude(Anthropic SDK)
通过 pip install anthropic 安装。注意 Claude 原生接口的地址不带 /v1 后缀。
from anthropic import Anthropic
client = Anthropic(
api_key="YOUR_OAIRoute_KEY",
base_url="https://api.oairoute.com",
)Java
通过 Maven 引入 OpenAI 官方 Java 客户端。设置 baseUrl 并使用现有代码,无需修改。
<!-- pom.xml -->
<dependency>
<groupId>com.openai</groupId>
<artifactId>openai-java</artifactId>
<version>2.6.0</version>
</dependency>import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
OpenAIClient client = OpenAIOkHttpClient.builder()
.apiKey("YOUR_OAIRoute_KEY")
.baseUrl("https://api.oairoute.com/v1")
.build();其他语言
文档的每个接口页右侧都有对应语言的完整示例,覆盖 cURL、Python、JavaScript、Go、Java、PHP、Ruby、Swift、C#、C、Objective-C、OCaml、Dart、R 十四种,点页面右上角的下拉即可切换。
You don't need a new SDK — use the official OpenAI, Anthropic, and Google libraries and change only the base URL and key at initialization. Only the setup is shown below; make requests exactly as you do today.
Python
Install with pip install openai. Set the base URL and keep your existing OpenAI code as is.
from openai import OpenAI
client = OpenAI(
api_key="YOUR_OAIRoute_KEY",
base_url="https://api.oairoute.com/v1",
)Node.js
Install with npm install openai. Set the baseURL parameter to the OAIRoute endpoint and keep your existing integration.
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_OAIRoute_KEY",
baseURL: "https://api.oairoute.com/v1",
});Claude (Anthropic SDK)
Install with pip install anthropic. Note that Claude's native endpoint base URL has no /v1 suffix.
from anthropic import Anthropic
client = Anthropic(
api_key="YOUR_OAIRoute_KEY",
base_url="https://api.oairoute.com",
)Java
Pull in the official OpenAI Java client through Maven. Set the baseUrl and keep your existing code as is.
<!-- pom.xml -->
<dependency>
<groupId>com.openai</groupId>
<artifactId>openai-java</artifactId>
<version>2.6.0</version>
</dependency>import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
OpenAIClient client = OpenAIOkHttpClient.builder()
.apiKey("YOUR_OAIRoute_KEY")
.baseUrl("https://api.oairoute.com/v1")
.build();Other languages
Every endpoint page has complete samples in the language panel on the right, covering cURL, Python, JavaScript, Go, Java, PHP, Ruby, Swift, C#, C, Objective-C, OCaml, Dart, and R — fourteen in all. Use the dropdown in the top right of the page to switch.
常见问题
常见问题的完整解答集中在帮助支持,按主题分页:
Full answers live in Help & support, split into pages by topic: