文档

API Keys

API Key 是访问 PromptMan REST API 的凭证,格式为 ph_ 前缀 + 64 位十六进制字符串。每个账户有唯一的 API Key,可在 Dashboard → 设置 → API Keys 中查看和管理。

获取 API Key

01

登录 Dashboard

访问 prompt.solokit.run/dashboard,使用账号登录。

02

进入设置页面

在 Dashboard 顶部导航中点击「设置」,或直接访问 /dashboard/settings。

03

切换到 API Keys 标签

在设置页左侧导航中点击「API Keys」。

04

查看或生成密钥

页面展示你的 API Key,点击「复制」即可获取完整密钥值。

TIP

你也可以通过登录接口直接获取 API Token,无需访问 Dashboard。

通过登录接口获取

bash
curl -X POST https://prompt.solokit.run/api/auth/token \
  -H "Content-Type: application/json" \
  -d '{
    "email": "you@example.com",
    "password": "yourpassword"
  }'
json
{
  "token": "ph_a1b2c3d4e5f6g7h8...",
  "userId": "u_1710000000000_abc123",
  "email": "you@example.com",
  "name": "张三"
}

在请求中使用 API Key

所有需要鉴权的接口,在 HTTP 请求头中添加 Authorization 字段:

bash
curl https://prompt.solokit.run/api/prompts \
  -H "Authorization: Bearer ph_your_api_key_here"

验证 API Key 是否有效

bash
curl https://prompt.solokit.run/api/auth/token \
  -H "Authorization: Bearer ph_your_api_key_here"
json
// 有效时返回
{
  "token": "ph_a1b2c3...",
  "userId": "u_xxx",
  "email": "you@example.com",
  "name": "张三"
}

// 无效时返回 401
{ "error": "Unauthorized" }

重置 API Key

如果 API Key 泄露,可以通过以下接口立即吊销并生成新的 Key:

bash
curl -X DELETE https://prompt.solokit.run/api/auth/token \
  -H "Authorization: Bearer ph_your_current_key"
json
// 返回新生成的 Token
{ "token": "ph_new_token_here..." }

CAUTION

重置后旧 Key 立即失效,请及时更新所有使用该 Key 的应用。

在不同语言中使用

cURL

bash
curl https://prompt.solokit.run/api/prompts \
  -H "Authorization: Bearer ph_your_api_key"

JavaScript

javascript
const response = await fetch('https://prompt.solokit.run/api/prompts', {
  headers: {
    'Authorization': 'Bearer ph_your_api_key',
    'Content-Type': 'application/json',
  },
});
const { data } = await response.json();

Python

python
import requests

headers = {"Authorization": "Bearer ph_your_api_key"}
resp = requests.get(
    "https://prompt.solokit.run/api/prompts",
    headers=headers
)
data = resp.json()

安全最佳实践

实践说明
使用环境变量将 API Key 存储在 .env 文件或系统环境变量中,而非硬编码在源代码里
不要提交到代码仓库在 .gitignore 中添加 .env 文件,防止 Key 意外泄露
定期轮换定期重置 API Key,特别是在人员变动或怀疑泄露时
最小权限原则仅在必要时传递 API Key,避免在前端代码中暴露
监控使用情况通过 Dashboard 查看 API 调用统计,及时发现异常访问

CAUTION

永远不要将 API Key 提交到公开的代码仓库,也不要在前端 JavaScript 中暴露它。如果 Key 已经泄露,立即使用重置接口生成新的 Key。