Repository navigation
Conversation
Currently, runtime and token usage statistics require dashboard authentication because their endpoints use the system scope, which developer API keys cannot access. External collectors therefore need dashboard credentials. We hence add a read-only stats scope for the two existing statistics endpoints /api/v1/stats and /api/v1/stats/provider-tokens. The scope needs opt-in (requires explicit selection) so existing keys and default permissions remain unchanged.
Enable developers to select "stats" permission through the existing key creation interface.
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. A key granted stats can read runtime and token-usage statistics, including plugin and session breakdowns. Reverting removes future access, but cannot undo information already retrieved.
|
Hi, If you are resolving an issue, I recommend using |
There was a problem hiding this comment.
Linked issues
#10957 [Feature] Add `stats` API key scope to allow external observability tool access · 4 of 4 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Allow stats-scoped API keys to access GET /api/v1/stats. |
✅ Met | The endpoint now requires ScopeDependency("stats"). |
| 2 | Allow stats-scoped API keys to access GET /api/v1/stats/provider-tokens. |
✅ Met | The endpoint now requires ScopeDependency("stats"). |
| 3 | Make the scope opt-in and do not grant administrative permissions. | ✅ Met | stats is accepted as an explicit scope but is not in the default scopes; it does not inherit other scopes, and the added tests check that it cannot perform administrative actions. |
| 4 | Let external tools retrieve these statistics without dashboard credentials. | ✅ Met | The scope dependency accepts API-key authentication, and the tests cover access with a stats-only key. |
|
@mantoujun6 Hello there! Thank you for your message. Updated the PR message according to your suggestion : ) |
|
The PR's CI flow failed in Similar patterns have been discovered in some other recent PRs:
Would appreciate some help on this issue (like re-running the Action jobs) 🙏 |
Close #10957
Existing runtime and token usage statistics endpoints require dashboard authentication because they use the system scope, which developer API keys cannot access. This blocks external observability systems to access and leverage the metrics.
This PR adds an opt-in, read-only
statsscope so external monitoring tools (e.g. Prometheus exporters) can access statistics-related endpoints.Modifications / 改动点
Add
statsas a supported API key scope, excluded from default permissions.GET /api/v1/statsGET /api/v1/stats/provider-tokensAdd an
statsoption to API key settings.Add tests for scope enforcement, administrative access denial, and unchanged default permissions.
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Verify with
Checklist / 检查清单
This is yet a reference implementation branch that is added as an appendix material for issue discussion.
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
📚 I checked the affected WebUI instructions and screenshots in
docs/zhanddocs/enagainst the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog./ 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新
docs/zh和docs/en的相关操作说明与截图(或说明无需更新文档的原因)。入口改名、移动或合并时,已在文档和 changelog 中补充 旧入口 → 新入口 对照。🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Enable external observability tools to securely access runtime and token usage statistics through explicitly scoped API keys.
New Features:
statsAPI key scope for runtime and provider token statistics endpoints.statsscope in API key settings and public OpenAPI documentation.Enhancements:
Documentation:
statsscope, supported endpoints, and usage examples in English and Chinese developer documentation.Tests: