文档
将 UnityAI 集成到您的应用所需的一切。
快速入门
UnityAI 提供 100% 兼容 OpenAI 的 API。只需替换 base URL 并使用您的 UnityAI API key — 无需修改代码。
Python
from openai import OpenAI
client = OpenAI(
api_key="sk-your-unirouter-key",
base_url="https://api.unityai.cc/v1"
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)身份验证
所有 API 请求必须在 Authorization header 中包含您的 API key:
Authorization: Bearer sk-your-api-key请妥善保管您的 API key。切勿将其暴露在客户端代码或公开仓库中。您可以在 API Keys.
对话补全
POST
/v1/chat/completions为给定的对话创建模型响应。完全兼容 OpenAI Chat Completions API。
请求体
| 参数 | 类型 | 描述 |
|---|---|---|
| model | string | ID of the model to use (e.g., gpt-4o, claude-3-5-sonnet) |
| messages | array | A list of messages comprising the conversation so far |
| stream | boolean | If true, partial message deltas will be sent as SSE events |
| temperature | number | Sampling temperature between 0 and 2 (default: 1) |
| max_tokens | integer | The maximum number of tokens to generate |
| top_p | number | Nucleus sampling parameter (default: 1) |
流式输出
设置 stream: true:
const stream = await client.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Tell me a story" }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || "");
}模型
GET
/v1/models列出当前可用的模型。
| 模型 ID | 类型 | 描述 |
|---|---|---|
| gpt-4o | chat | OpenAI's flagship multimodal model |
| gpt-4o-mini | chat | Fast and affordable model for focused tasks |
| gpt-4-turbo | chat | GPT-4 with vision capabilities |
| o1-mini | reasoning | Reasoning model optimized for STEM tasks |
| claude-3-5-sonnet-20241022 | chat | Anthropic's most capable model |
| gemini-1.5-pro | chat | Google's multimodal model with 1M context |
| dall-e-3 | image | High-quality image generation model |
频率限制
频率限制基于滑动窗口算法,按每个 API key 施加。
免费层
10 RPM
每分钟 10 次请求
付费层
60 RPM
每分钟 60 次请求
错误码
| HTTP 状态码 | 错误 | 描述 |
|---|---|---|
| 400 | Bad Request | Invalid request parameters |
| 401 | Unauthorized | Missing or invalid API key |
| 402 | Payment Required | Insufficient balance |
| 429 | Too Many Requests | Rate limit exceeded |
| 500 | Internal Server Error | Upstream API error or server fault |
| 503 | Service Unavailable | All upstream providers are unavailable |