指南
API 身份验证
创建 API Key,并使用它验证发送到 RunAPI 的请求。
RunAPI 使用 API Key 验证 API 请求。访问账户资源或创建任务时,每个请求都必须携带 API Key。
选择正确的密钥
创建 API Key
为每个应用分配独立的 API Key,以便单独轮换或撤销访问权限,而不中断其他集成。每个密钥只属于一个账户,请求只能访问该账户可见的资源。
每个账户的付费 API 调用限制为每分钟 300 次。收到 429 Too Many Requests 时,可根据 Retry-After、X-RateLimit-Limit-RPM、X-RateLimit-Remaining-RPM 和 X-RateLimit-Reset 响应头安排重试。
验证请求
在 Authorization 请求头中以 bearer token 形式发送 API Key:
HTTP
Authorization: Bearer YOUR_API_TOKEN
例如,使用 cURL 查询当前余额:
SHELL
curl "https://runapi.ai/api/v1/me/balance" \
-H "Authorization: Bearer YOUR_API_TOKEN"
Hosted MCP OAuth
远程 MCP 客户端连接到 https://mcp.runapi.ai/mcp,并使用 canonical OAuth resource https://mcp.runapi.ai 自动发现 RunAPI 授权流程。登录或创建 RunAPI 账户,选择一个 Account,然后批准访问,无需创建或共享 API Key。
RunAPI 的 Hosted MCP 访问支持 Dynamic Client Registration、使用 S256 PKCE 的 authorization code,以及轮换 refresh token。
OAuth discovery endpoints:
- Protected Resource Metadata:
https://runapi.ai/.well-known/oauth-protected-resource - Authorization Server Metadata:
https://runapi.ai/.well-known/oauth-authorization-server
先登录,再打开 /settings#oauth-connections 中的 Authorized apps,查看或撤销客户端访问权限。
安全保管 API Key
- 将 API Key 存储在密钥管理系统或加密凭据中。
- 切勿将 API Key 提交到源码仓库或暴露在浏览器代码中。
- 如果 API Key 可能已经泄露,请立即轮换。
- 开发环境和生产环境使用不同的 API Key。
排查身份验证问题
401 Unauthorized表示 API Key 缺失、格式错误、已撤销或无效。403 Forbidden表示密钥有效,但其凭据类别或账户角色不能执行该操作。- 确认请求头以
Bearer开头,随后是一个空格和完整的 API Key。 - 确认 API Key 属于当前请求资源所在的账户。