身份验证
如何验证 Poomi API 请求的身份
所有 Poomi API 请求都需要通过在 Authorization 请求头中传递 API Key 进行身份验证。
验证方式
在 Authorization 请求头中使用 Bearer 方案传入你的 API Key:
curl https://www.poomi.pet/api/v1/{endpoint} \
-H "Authorization: Bearer pk_your_api_key_here"API Key 格式
pk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxKey 使用 pk_ 前缀,后跟 32 位 NanoID。
验证错误
| HTTP 状态码 | 错误代码 | 描述 |
|---|---|---|
| 401 | UNAUTHORIZED | 缺少或无效的 Authorization 请求头 |
| 401 | INVALID_KEY | API Key 不存在 |
| 403 | KEY_DISABLED | API Key 已被禁用 |
| 403 | KEY_REVOKED | API Key 已被撤销 |
| 403 | KEY_EXPIRED | API Key 已过期 |
错误响应示例
{
"success": false,
"error": {
"code": "INVALID_KEY",
"message": "Invalid API key"
}
}安全建议
- 使用环境变量 — 切勿在源代码中硬编码 API Key
- 仅限服务端 — 从后端发起 API 调用,切勿在客户端代码中暴露 Key
- 区分环境 — 开发和生产环境使用不同的 Key
- 撤销泄露的 Key — 如果 Key 被暴露,立即在开发者控制台中撤销