认证方式
所有 API 请求都需要通过 Authorization 请求头携带 API Key 进行认证。
获取 API Key
Section titled “获取 API Key”- 前往 api.tokensupernova.com
- 用邮箱注册(无需手机号)
- 在控制台中找到 API Keys 页面
- 点击 创建 Key 并立即复制
使用 API Key
Section titled “使用 API Key”在每个请求的 Authorization 请求头中携带 Key:
Authorization: Bearer tsn_live_xxxxxxxxxxxx配合 OpenAI SDK
Section titled “配合 OpenAI SDK”from openai import OpenAI
client = OpenAI( api_key="tsn_live_xxx", base_url="https://api.tokensupernova.com/v1",)配合 curl
Section titled “配合 curl”curl "https://api.tokensupernova.com/v1/chat/completions" \ -H "Authorization: Bearer tsn_live_xxx" \ -H "Content-Type: application/json" \ -d '{...}'安全最佳实践
Section titled “安全最佳实践”- 绝不将 API Key 提交到版本控制系统
- 使用环境变量:
export TSN_API_KEY="tsn_live_xxx" - 在控制台中定期轮换 Key
- 每个 Key 仅限你的账户使用 — 开发和生产环境使用不同的 Key
Key 格式
Section titled “Key 格式”| 环境 | 前缀 | 示例 |
|---|---|---|
| 生产环境 | tsn_live_ | tsn_live_a1b2c3d4... |
| 测试环境(规划中) | tsn_test_ | tsn_test_a1b2c3d4... |