Alive API 文档
个人在线状态服务 · FastAPI · POST 安全写入
先记住这两条
查询数据使用 GET;修改数据使用 POST。
密钥不要放在 URL,推荐放在 Authorization: Bearer 你的密钥 请求头。
网页管理后台不需要手写 API。访问 /panel,输入密钥登录后即可直接修改状态、设备和隐私模式。
公开读取接口
| 方法 | 路径 | 作用 | 需要密钥 |
| GET | /api/meta | 站点信息和版本 | 否 |
| GET | /api/status/query | 当前状态和设备 | 否 |
| GET | /api/status/list | 手动状态列表 | 否 |
| GET | /api/status/events | SSE 实时状态流 | 否 |
| GET | /api/health/query | 心率和今日步数 | 否 |
| GET | /api/music/query | 当前音乐和同步歌词 | 否 |
| GET | /api/metrics | 访问次数统计 | 否 |
数据修改接口
| 方法 | 路径 | JSON 内容 |
| POST | /api/status/set | {"status": 1} |
| POST | /api/device/set | 新增或更新设备 |
| POST | /api/device/app-icon | 上传 Android 当前应用图标 |
| POST | /api/admin/settings | 修改主页、弹幕和音乐目录 |
| POST | /api/admin/secret | 安全轮换全局密钥 |
| POST | /api/device/remove | {"id": "desktop"} |
| POST | /api/device/clear | {} |
| POST | /api/device/private | {"private": true} |
| POST | /api/health/set | 更新心率和今日步数 |
| POST | /api/music/set | 更新当前播放状态 |
| POST | /api/music/track/check | 按 SHA-256 检查是否已上传 |
| POST | /api/music/track/upload | 流式上传当前歌曲二进制 |
Windows PowerShell 上报示例
$secret = "填入 .env 中的 ALIVE_SECRET"
$headers = @{ Authorization = "Bearer $secret" }
$body = @{
id = "windows-test"
show_name = "Windows 测试机"
using = $true
status = "PowerShell"
} | ConvertTo-Json
Invoke-RestMethod `
-Method Post `
-Uri "http://localhost:9010/api/device/set" `
-Headers $headers `
-ContentType "application/json" `
-Body $body
Windows 客户端关闭行为
Ctrl+C 最可靠:脚本会先上报“未使用”,然后退出。
直接关闭 PowerShell 或 Windows Terminal 页面时,脚本也会监听关闭事件并尝试上报,但操作系统可能直接终止子进程,因此不能保证请求一定发完。
Alive 还有服务端兜底:客户端每 60 秒发送心跳;连续 150 秒没有任何上报,设备会自动变成“未使用”。可通过 status.device_timeout 调整。
密钥安全
Alive 只使用一个全局密钥,后台和所有设备客户端共同使用。最低 6 位,不需要为每台设备设置不同密码;正式部署仍建议使用更长的随机值。
不要使用 ?secret=xxx。查询字符串可能进入浏览器历史、代理日志、服务器日志和监控系统,Alive 会拒绝这种认证方式。
推荐 Bearer 请求头。网页后台登录成功后使用签名的 HttpOnly Cookie,Cookie 中不包含原始密钥。
Alive API Documentation
Personal status service · FastAPI · Secure POST mutations
Two rules to remember
Use GET to read data and POST to change it.
Never put the secret in a URL. Prefer the
Authorization: Bearer YOUR_SECRET header.
You can manage everything in a browser at /panel without writing API requests.
Public read endpoints
| Method | Path | Purpose | Secret |
| GET | /api/meta | Site metadata and version | No |
| GET | /api/status/query | Current status and devices | No |
| GET | /api/status/list | Manual status choices | No |
| GET | /api/status/events | Live SSE status stream | No |
| GET | /api/health/query | Heart rate and today's steps | No |
| GET | /api/music/query | Current music and timed lyrics | No |
| GET | /api/metrics | Visit metrics | No |
Mutation endpoints
| Method | Path | JSON body |
| POST | /api/status/set | {"status": 1} |
| POST | /api/device/set | Create or update a device |
| POST | /api/device/app-icon | Upload the current Android app icon |
| POST | /api/admin/settings | Update homepage, danmaku, and music directory |
| POST | /api/admin/secret | Securely rotate the global secret |
| POST | /api/device/remove | {"id": "desktop"} |
| POST | /api/device/clear | {} |
| POST | /api/device/private | {"private": true} |
| POST | /api/health/set | Update heart rate and steps |
| POST | /api/music/set | Update now-playing state |
| POST | /api/music/track/check | Check by SHA-256 before upload |
| POST | /api/music/track/upload | Stream the current audio file |
Device update JSON
{
"id": "windows-test",
"show_name": "Windows PC",
"using": true,
"status": "PowerShell",
"fields": {}
}
Closing the Windows client
Ctrl+C is the most reliable exit: the client reports “not using” before it stops.
Closing a PowerShell or Windows Terminal tab also triggers a best-effort close handler, but the operating system may kill the child process before the HTTP request finishes.
Server fallback: the client sends a heartbeat every 60 seconds. After 150 seconds without an update, Alive automatically marks the device as not using. Configure this with status.device_timeout.
Secret safety
Alive uses one global secret shared by the admin panel and all device clients. The minimum length is 6 characters; devices do not have separate passwords. Use a longer random value in production.
Do not use ?secret=xxx. Query strings can be recorded in browser history, proxy logs, server logs, and monitoring systems. Alive rejects query-string authentication.
Prefer a Bearer header. Browser admin sessions use a signed HttpOnly cookie that does not contain the original secret.