身份验证
向 FourA API 发送的每个 request 都需要进行身份验证。本页面将介绍如何获取、使用和管理您的 API key。
获取您的 API key
- 登录 FourA Dashboard
- 前往 API Keys 页面
- 点击 Create Key
- 立即复制该 key(它将不会再次完整显示)
您的 API key 类似于:pk_live_a1b2c3d4e5f6...
使用您的 API key
在每个 request 的 X-API-Key header 中包含您的 API key:
curl -X POST https://eu.api.foura.ai/api/single/ \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"method": "GET", "url": "https://example.com"}'
在 Python 中:
import requests
response = requests.post(
"https://eu.api.foura.ai/api/single/",
headers={
"X-API-Key": "YOUR_API_KEY",
"Content-Type": "application/json"
},
json={"method": "GET", "url": "https://example.com"}
)
在 Node.js 中:
const response = await fetch('https://eu.api.foura.ai/api/single/', {
method: 'POST',
headers: {
'X-API-Key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({ method: 'GET', url: 'https://example.com' })
});
API key 安全
请像对待密码一样对待您的 API key:
- 切勿将其提交至版本控制系统。 请改用环境变量。
- 切勿在客户端代码中泄露。 仅在服务端应用程序中使用。
- 若泄露请立即轮换。 在 Dashboard 中创建新 key 并停用旧 key。
使用环境变量
将您的 key 存储在环境变量中:
export FOURA_API_KEY="pk_live_a1b2c3d4e5f6..."
然后在代码中引用它:
import os
api_key = os.environ["FOURA_API_KEY"]
const apiKey = process.env.FOURA_API_KEY;
常见身份验证错误
所有身份验证失败均返回 401 Unauthorized 状态。
| 错误 | 消息 | 原因 | 解决方法 |
|---|---|---|---|
| 401 | Missing API key. Include X-API-Key header. | request 中缺少 X-API-Key header |
添加 X-API-Key header |
| 401 | Invalid API key | key 错误、包含多余空格或 key 已停用 | 验证 key、清除空格,或在 Dashboard 中创建新 key |
后续步骤
- 快速入门:发送您的首个 request
- API Endpoints:完整的 endpoint 参考
- 错误处理:优雅地处理身份验证错误