Skip to content

docs(usage): phase 2 batch 2 — usage side 4 docs (#167)#178

Merged
g1331 merged 2 commits into
masterfrom
docs/phase2-usage-batch
May 23, 2026
Merged

docs(usage): phase 2 batch 2 — usage side 4 docs (#167)#178
g1331 merged 2 commits into
masterfrom
docs/phase2-usage-batch

Conversation

@g1331
Copy link
Copy Markdown
Owner

@g1331 g1331 commented May 23, 2026

Summary

Phase 2 第二批:撰写 issue #167 第一批 10 篇中的使用侧 4 篇正文,事实依据为当前管理 UI 与代理路由源码。

文档 路径 主要内容
管理后台导览 docs/guide/usage/admin-overview.md 主导航 4 项 + 系统段 6 项的职责一览,登录与 session 模型,移动端导航差异
添加第一个上游 docs/guide/usage/first-upstream.md OpenAI 兼容上游端到端:4 必填字段、route_capabilities 全枚举、可选字段默认值、连通性测试错误分类
创建客户端 API Key docs/guide/usage/client-keys.md 受限/全量访问模式与自动推断规则、allowed_models、密钥一次性返回与 ALLOW_KEY_REVEAL 揭示、三种鉴权 header
通过 AutoRouter 调用模型 docs/guide/usage/invoke-models.md cURL / OpenAI SDK (Python+TS) / Anthropic SDK / Gemini SDK 示例、支持路径全表、SSE 行为、统一错误码

事实依据

逐条以当前 master 源码为根:

  • src/components/admin/sidebar.tsx + src/messages/zh-CN.json:导航条目与中文标签
  • src/app/api/admin/upstreams/route.tssrc/lib/services/upstream-crud.tsupstream-connection-tester.ts:上游创建 / 加密 / 连通性测试
  • src/lib/route-capabilities.tsroute_capabilities 枚举与 provider 同组约束
  • src/app/api/admin/keys/route.tssrc/lib/services/key-manager.ts:密钥创建、access_mode 推断、bcrypt + Fernet 双存
  • src/app/api/admin/keys/[id]/reveal/route.tssrc/lib/utils/config.ts:揭示接口与 ALLOW_KEY_REVEAL 校验
  • src/app/api/proxy/v1/[...path]/route.tssrc/lib/services/route-capability-matcher.ts:路径到能力的映射、三种鉴权 header、SSE 包装

无法在源码中定值的部分(部署 host、端口、Key 后缀)一律用尖括号占位符 <...> 形式标注,避免给出假数据。

不在本 PR 范围

  • 架构侧 2 篇(PR3 收尾)
  • README 减负
  • UI helper text
  • 4 篇之外的其他占位文档(仍是 Phase 2 后续批次)

Test plan

  • pnpm format:check 全绿(prettier 自动对齐表格列宽)
  • pnpm docs:build 3.62 s 构建成功,无 dead link 报告
  • 修复了首版中遗留的一处占位 anchor [失败转移与熔断](#),改为指向 /circuit-breaker
  • CI 的 Docs workflow build job 通过
  • Verify 全绿(pull_request 触发会跑全套,预期与改动无关)
  • 待人工 review 后由你决定是否合并

g1331 added 2 commits May 23, 2026 18:35
Write the four usage-side documents from issue #167 phase 2 first
batch, grounded in the current admin UI and proxy implementation:

- guide/usage/admin-overview.md: dashboard sidebar inventory (main +
  system sections), per-page purpose, login / session model, mobile
  nav differences. Routes and labels cross-checked against
  src/components/admin/sidebar.tsx and src/messages/zh-CN.json.
- guide/usage/first-upstream.md: end-to-end OpenAI-compatible upstream
  creation, the four minimum fields, all route_capabilities enum
  values with corresponding client paths, optional fields with
  defaults from createUpstreamSchema, the connection test errorType
  taxonomy, and the localhost-vs-service-name pitfall again.
- guide/usage/client-keys.md: client key creation including
  access_mode inference rule, allowed_models semantics, the
  one-shot key_value reveal in the create response, ALLOW_KEY_REVEAL
  gating, the legacy bcrypt-only key path, and the three accepted
  auth header forms.
- guide/usage/invoke-models.md: curl / OpenAI SDK (Python+TS) /
  Anthropic SDK / Gemini SDK examples, the complete supported path
  table, SSE handling, and the unified error code summary.

Sources cited per claim: src/app/api/admin/{upstreams,keys}/route.ts
and route_capabilities, src/lib/services/key-manager.ts and
upstream-crud.ts, src/lib/route-capabilities.ts,
src/lib/services/route-capability-matcher.ts,
src/app/api/proxy/v1/[...path]/route.ts. No claim is left
unsubstantiated; example values that depend on deployment (host,
port, key prefix tail) use angle-bracket placeholders.

Out of scope: architecture batch, README slimming, UI helper text.
All three issues confirmed against the current source before fixing.

1. Gemini SDK base URL was missing the trailing /v1, which would
   have made google-genai SDK target /api/proxy/v1beta/... — the
   proxy handler is at /api/proxy/v1/[...path] so that path is a
   404. Corrected the example to use /api/proxy/v1 as the base URL
   so SDK-side concatenation yields /api/proxy/v1/v1beta/..., and
   added an explicit note explaining the wiring.
   Source: src/app/api/proxy/v1/[...path]/route.ts.

2. The "revoke vs delete" lifecycle description was wrong. The UI
   "revoke" button calls DELETE /api/admin/keys/[id] which routes to
   deleteApiKey and actually removes the record. There is no separate
   "revoke that retains the record" operation. Merged the two rows in
   the lifecycle table and added a warning callout pointing users
   toward is_active=false ("disable") when audit retention matters.
   Source: src/app/api/admin/keys/[id]/route.ts:45.

3. The proxy error code table claimed 401 returns
   { code: "INVALID_API_KEY", ... } and that NO_UPSTREAMS_CONFIGURED
   is HTTP 404. In reality:
   - Auth-stage failures return bare { error: "Missing API key" } /
     "Invalid API key" / "API key has expired" with HTTP 401 and no
     code field (route.ts:2446-2473).
   - NO_UPSTREAMS_CONFIGURED is HTTP 503; NO_AUTHORIZED_UPSTREAMS is
     HTTP 403 (src/lib/services/unified-error.ts:105-106).
   Rewrote the section to split "auth-stage" vs "routing/forward
   stage" error shapes and corrected both rows.
@g1331 g1331 merged commit 4f1a664 into master May 23, 2026
14 checks passed
@g1331 g1331 deleted the docs/phase2-usage-batch branch May 23, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant