认证鉴权Authentication

所有 API 请求都需要通过 API Key 进行身份认证。调用平台代理地址时,统一使用 Authorization: Bearer YOUR_API_KEY。All API requests must be authenticated with an API Key. When calling the platform proxy endpoint, always use Authorization: Bearer YOUR_API_KEY.

获取 API KeyGet an API Key

1

登录控制台Log In to the Console

使用账号登录平台控制台。Log in to the platform console with your account.

2

进入令牌页面Go to the Token Page

在「令牌」页面点击「添加令牌」。On the Token page, click Add Token.

3

创建并保存Create and Save

按需设置名称、额度与模型范围,复制生成的 Key 并妥善保存。Set the name, quota, and model scope as needed, then copy the generated key and keep it safe.

API Key 是你的账户凭证,请务必妥善保管。不要在客户端代码、公开仓库或日志中暴露你的 API Key。Your API Key is your account credential. Keep it safe at all times. Never expose it in client-side code, public repositories, or logs.

认证方式总览Authentication Overview

平台对外统一使用 Bearer 认证,所有接口使用同一个平台 Token:The platform uses Bearer authentication externally, and all endpoints share the same platform Token:

接口Endpoint认证方式Authentication说明Description
POST /v1/chat/completionsAuthorization: Bearer <Token>OpenAI 兼容聊天接口OpenAI-compatible chat endpoint
POST /v1/images/generationsAuthorization: Bearer <Token>图片生成Image generation
POST /v1/audio/speechAuthorization: Bearer <Token>语音合成Speech synthesis
POST /v1/videos/generationsAuthorization: Bearer <Token>视频生成(异步)Video generation (async)
GET /v1/modelsAuthorization: Bearer <Token>模型列表Models

Bearer 认证Bearer Authentication

在请求的 Authorization Header 中携带平台 Token:Include the platform Token in the Authorization header of your request:

chat-auth.shcURL
curl {BASE_URL}/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxx" \
  -d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "你好"}]}'
一个平台 Token 可用于所有接口,无需为不同能力分别创建密钥。A single platform Token works for all endpoints, so there is no need to create separate keys for different capabilities.

请求头说明Request Headers

请求头Header必填Required类型Type说明Description
Authorization是Yesstring格式为 Bearer YOUR_API_KEY,用于身份认证Format: Bearer YOUR_API_KEY, used for authentication
Content-Type是Yesstring固定为 application/jsonAlways application/json

Request-Id

你可以在请求头中传入自定义的 Request-Id,用于请求追踪与问题排查:You can pass a custom Request-Id in the request header for request tracing and troubleshooting:

request-id.shcURL
curl {BASE_URL}/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Request-Id: your-unique-request-id-123" \
  -d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "你好"}]}'

在 SDK 中使用Using with SDKs

Python(OpenAI SDK)Python (OpenAI SDK)

openai.pyPython
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="{BASE_URL}/v1",
)

Node.js(OpenAI SDK)Node.js (OpenAI SDK)

openai.jsNode.js
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "YOUR_API_KEY",
  baseURL: "{BASE_URL}/v1",
});

常见认证错误Common Authentication Errors

状态码Status Code说明Description解决方法Solution
401API Key 无效或缺失The API Key is invalid or missing检查 Header 中是否正确携带了 AuthorizationCheck that the Authorization header is properly included
403权限不足Insufficient permissions检查 Token 是否有访问对应模型的权限,或模型是否已配置价格Check whether the Token has permission to access the model, or whether the model has pricing configured
429余额不足或请求过于频繁Insufficient balance or too many requests充值后恢复调用,或降低请求频率Top up your balance to resume calls, or reduce the request rate

下一步Next Steps