Outcome
你将能从 Provider Secret 一直追踪到一次确定结算的模型请求,并知道每一步由哪一个平面和哪一类事实负责。
Provider boundary
Developer Provider Secret
Written by the platform developer; never delivered to the application user.
Encrypted ProviderConnection
Stores one explicit upstream capability inside a Workspace.
Admin Plane
Application Backend
Uses a Management Key to configure resources and provision users.
Nexus Admin API
Creates User, WorkspaceAccess and QuotaPeriod.
Inference Key
Returned once and delivered to the trusted user client.
Data Plane
User SDK or Agent
Sends the Inference Key and an explicit connection UUID.
Nexus Gateway
Resolves Access and commits a Quota Reservation in PostgreSQL.
Workspace ProviderConnection
Supplies the selected Base URL and decrypted short-lived credential.
Model Provider
Receives the original provider path, model and payload.
Provider Secret 不到达最终用户;Admin Plane 管理配置与生命周期;Data Plane 只有在 PostgreSQL 中的 Access、Quota 和 Workspace-scoped ProviderConnection 校验全部成功后才调用 Provider。
1. Configure capacity in the Admin Plane
Organization Member 或应用后端通过 Console、Admin API 或 Management SDK:
- 创建 Workspace。
- 创建 ProviderConnection;Nexus 生成不可变 UUID,并加密 Provider Secret。
- 创建 WorkspacePlan,发布 QuotaStrategy,并通过 PlanStrategyBinding 绑定两者。
这些操作不进入 Gateway 请求热路径。
2. Provision an application user
应用后端按 (workspaceId, externalUserId) 幂等 Provision 用户。Nexus 创建或查找 Better Auth User,创建 WorkspaceAccess 和当前 QuotaPeriod,再签发只显示一次明文的 Inference Key。
Better Auth User
└── WorkspaceAccess → WorkspacePlan → QuotaPeriod
└── ApiKeyBinding ← Inference Key3. Resolve and reserve before dispatch
用户 SDK 把 Inference Key 放在 Authorization,把不可变 providerConnectionId 放在 Gateway Base URL。Gateway 的准入顺序是:
verify Inference Key
→ resolve ApiKeyBinding → WorkspaceAccess → Workspace
→ check Key, Access and QuotaPeriod time boundaries
→ resolve ACTIVE ProviderConnection by (workspaceId, providerConnectionId)
→ reserve Quota in PostgreSQL
→ call the Provider任何准入步骤失败都不会调用 Provider。客户端不能提供上游 Host,也不能使用另一 Workspace 的 Connection ID。
4. Preserve the provider request
Gateway 将 Connection ID 后的完整 Path、Query、Method 和 Body 安全追加到 ProviderConnection 的 Base URL。客户端的 Nexus Authorization 被消费,并替换为已保存的 Provider Secret;model 和 Provider 自有字段原样发送。
5. Stream and reach one terminal result
普通响应、SSE 完成、Provider 错误、超时和客户端断开都会进入幂等终态:
SETTLED:按可证明 Usage 扣除实际 Quota Units。RELEASED:没有可计量交付时释放预留。EXPIRED:恢复任务处理超时的 ACTIVE Reservation。
6. Keep authorization truth local
PostgreSQL 是 Access、Quota Reservation 和 Usage settlement 的事实源。Stripe、Creem、Queue、Cache 或 Analytics 不会绕过这条授权链;支付系统只异步投影 Access 和 Period 事实。