文档

将 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。

请求体

参数类型描述
modelstringID of the model to use (e.g., gpt-4o, claude-3-5-sonnet)
messagesarrayA list of messages comprising the conversation so far
streambooleanIf true, partial message deltas will be sent as SSE events
temperaturenumberSampling temperature between 0 and 2 (default: 1)
max_tokensintegerThe maximum number of tokens to generate
top_pnumberNucleus 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-4ochatOpenAI's flagship multimodal model
gpt-4o-minichatFast and affordable model for focused tasks
gpt-4-turbochatGPT-4 with vision capabilities
o1-minireasoningReasoning model optimized for STEM tasks
claude-3-5-sonnet-20241022chatAnthropic's most capable model
gemini-1.5-prochatGoogle's multimodal model with 1M context
dall-e-3imageHigh-quality image generation model

频率限制

频率限制基于滑动窗口算法,按每个 API key 施加。

免费层

10 RPM

每分钟 10 次请求

付费层

60 RPM

每分钟 60 次请求

错误码

HTTP 状态码错误描述
400Bad RequestInvalid request parameters
401UnauthorizedMissing or invalid API key
402Payment RequiredInsufficient balance
429Too Many RequestsRate limit exceeded
500Internal Server ErrorUpstream API error or server fault
503Service UnavailableAll upstream providers are unavailable