@yina-npm/openrouterx 0.4.53 → 0.4.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +396 -89
  2. package/app/.next/BUILD_ID +1 -1
  3. package/app/.next/build-manifest.json +2 -2
  4. package/app/.next/server/app/(dashboard)/dashboard/admin/keys/page_client-reference-manifest.js +1 -1
  5. package/app/.next/server/app/(dashboard)/dashboard/admin/users/page_client-reference-manifest.js +1 -1
  6. package/app/.next/server/app/(dashboard)/dashboard/basic-chat/page_client-reference-manifest.js +1 -1
  7. package/app/.next/server/app/(dashboard)/dashboard/cli-tools/[toolId]/page_client-reference-manifest.js +1 -1
  8. package/app/.next/server/app/(dashboard)/dashboard/cli-tools/page_client-reference-manifest.js +1 -1
  9. package/app/.next/server/app/(dashboard)/dashboard/combos/page_client-reference-manifest.js +1 -1
  10. package/app/.next/server/app/(dashboard)/dashboard/console-log/page_client-reference-manifest.js +1 -1
  11. package/app/.next/server/app/(dashboard)/dashboard/endpoint/page_client-reference-manifest.js +1 -1
  12. package/app/.next/server/app/(dashboard)/dashboard/focus-ui/page_client-reference-manifest.js +1 -1
  13. package/app/.next/server/app/(dashboard)/dashboard/media-providers/[kind]/[id]/page_client-reference-manifest.js +1 -1
  14. package/app/.next/server/app/(dashboard)/dashboard/media-providers/[kind]/page_client-reference-manifest.js +1 -1
  15. package/app/.next/server/app/(dashboard)/dashboard/media-providers/combo/[id]/page_client-reference-manifest.js +1 -1
  16. package/app/.next/server/app/(dashboard)/dashboard/media-providers/web/page_client-reference-manifest.js +1 -1
  17. package/app/.next/server/app/(dashboard)/dashboard/mitm/page_client-reference-manifest.js +1 -1
  18. package/app/.next/server/app/(dashboard)/dashboard/network-analysis/page_client-reference-manifest.js +1 -1
  19. package/app/.next/server/app/(dashboard)/dashboard/page_client-reference-manifest.js +1 -1
  20. package/app/.next/server/app/(dashboard)/dashboard/profile/page_client-reference-manifest.js +1 -1
  21. package/app/.next/server/app/(dashboard)/dashboard/providers/[id]/page_client-reference-manifest.js +1 -1
  22. package/app/.next/server/app/(dashboard)/dashboard/providers/new/page_client-reference-manifest.js +1 -1
  23. package/app/.next/server/app/(dashboard)/dashboard/providers/page_client-reference-manifest.js +1 -1
  24. package/app/.next/server/app/(dashboard)/dashboard/proxy-pools/page_client-reference-manifest.js +1 -1
  25. package/app/.next/server/app/(dashboard)/dashboard/quota/page_client-reference-manifest.js +1 -1
  26. package/app/.next/server/app/(dashboard)/dashboard/skills/page_client-reference-manifest.js +1 -1
  27. package/app/.next/server/app/(dashboard)/dashboard/translator/page_client-reference-manifest.js +1 -1
  28. package/app/.next/server/app/(dashboard)/dashboard/usage/page_client-reference-manifest.js +1 -1
  29. package/app/.next/server/app/(dashboard)/dashboard/user/page_client-reference-manifest.js +1 -1
  30. package/app/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  31. package/app/.next/server/app/_global-error.html +1 -1
  32. package/app/.next/server/app/_global-error.rsc +1 -1
  33. package/app/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  34. package/app/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  35. package/app/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  36. package/app/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  37. package/app/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  38. package/app/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  39. package/app/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  40. package/app/.next/server/app/_not-found.html +1 -1
  41. package/app/.next/server/app/_not-found.rsc +3 -3
  42. package/app/.next/server/app/_not-found.segments/_full.segment.rsc +3 -3
  43. package/app/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  44. package/app/.next/server/app/_not-found.segments/_index.segment.rsc +3 -3
  45. package/app/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  46. package/app/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  47. package/app/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  48. package/app/.next/server/app/api/models/route.js +1 -1
  49. package/app/.next/server/app/api/models/test/route.js +1 -1
  50. package/app/.next/server/app/api/providers/[id]/test-models/route.js +1 -1
  51. package/app/.next/server/app/api/providers/route.js +1 -1
  52. package/app/.next/server/app/api/translator/console-logs/route.js +1 -1
  53. package/app/.next/server/app/api/translator/console-logs/stream/route.js +1 -1
  54. package/app/.next/server/app/api/version/route.js +1 -1
  55. package/app/.next/server/app/api/version/shutdown/route.js +1 -1
  56. package/app/.next/server/app/api/version/update/route.js +1 -1
  57. package/app/.next/server/app/callback/page_client-reference-manifest.js +1 -1
  58. package/app/.next/server/app/callback.html +1 -1
  59. package/app/.next/server/app/callback.rsc +3 -3
  60. package/app/.next/server/app/callback.segments/_full.segment.rsc +3 -3
  61. package/app/.next/server/app/callback.segments/_head.segment.rsc +1 -1
  62. package/app/.next/server/app/callback.segments/_index.segment.rsc +3 -3
  63. package/app/.next/server/app/callback.segments/_tree.segment.rsc +1 -1
  64. package/app/.next/server/app/callback.segments/callback/__PAGE__.segment.rsc +1 -1
  65. package/app/.next/server/app/callback.segments/callback.segment.rsc +1 -1
  66. package/app/.next/server/app/dashboard/settings/pricing/page_client-reference-manifest.js +1 -1
  67. package/app/.next/server/app/dashboard/settings/pricing.html +1 -1
  68. package/app/.next/server/app/dashboard/settings/pricing.rsc +3 -3
  69. package/app/.next/server/app/dashboard/settings/pricing.segments/_full.segment.rsc +3 -3
  70. package/app/.next/server/app/dashboard/settings/pricing.segments/_head.segment.rsc +1 -1
  71. package/app/.next/server/app/dashboard/settings/pricing.segments/_index.segment.rsc +3 -3
  72. package/app/.next/server/app/dashboard/settings/pricing.segments/_tree.segment.rsc +1 -1
  73. package/app/.next/server/app/dashboard/settings/pricing.segments/dashboard/settings/pricing/__PAGE__.segment.rsc +1 -1
  74. package/app/.next/server/app/dashboard/settings/pricing.segments/dashboard/settings/pricing.segment.rsc +1 -1
  75. package/app/.next/server/app/dashboard/settings/pricing.segments/dashboard/settings.segment.rsc +1 -1
  76. package/app/.next/server/app/dashboard/settings/pricing.segments/dashboard.segment.rsc +1 -1
  77. package/app/.next/server/app/index.html +1 -1
  78. package/app/.next/server/app/index.rsc +3 -3
  79. package/app/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  80. package/app/.next/server/app/index.segments/_full.segment.rsc +3 -3
  81. package/app/.next/server/app/index.segments/_head.segment.rsc +1 -1
  82. package/app/.next/server/app/index.segments/_index.segment.rsc +3 -3
  83. package/app/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  84. package/app/.next/server/app/landing/page_client-reference-manifest.js +1 -1
  85. package/app/.next/server/app/landing.html +1 -1
  86. package/app/.next/server/app/landing.rsc +3 -3
  87. package/app/.next/server/app/landing.segments/_full.segment.rsc +3 -3
  88. package/app/.next/server/app/landing.segments/_head.segment.rsc +1 -1
  89. package/app/.next/server/app/landing.segments/_index.segment.rsc +3 -3
  90. package/app/.next/server/app/landing.segments/_tree.segment.rsc +1 -1
  91. package/app/.next/server/app/landing.segments/landing/__PAGE__.segment.rsc +1 -1
  92. package/app/.next/server/app/landing.segments/landing.segment.rsc +1 -1
  93. package/app/.next/server/app/login/page_client-reference-manifest.js +1 -1
  94. package/app/.next/server/app/login.html +1 -1
  95. package/app/.next/server/app/login.rsc +4 -4
  96. package/app/.next/server/app/login.segments/_full.segment.rsc +4 -4
  97. package/app/.next/server/app/login.segments/_head.segment.rsc +1 -1
  98. package/app/.next/server/app/login.segments/_index.segment.rsc +3 -3
  99. package/app/.next/server/app/login.segments/_tree.segment.rsc +1 -1
  100. package/app/.next/server/app/login.segments/login/__PAGE__.segment.rsc +2 -2
  101. package/app/.next/server/app/login.segments/login.segment.rsc +1 -1
  102. package/app/.next/server/app/page_client-reference-manifest.js +1 -1
  103. package/app/.next/server/chunks/1350.js +1 -1
  104. package/app/.next/server/chunks/3110.js +1 -1
  105. package/app/.next/server/chunks/7177.js +1 -1
  106. package/app/.next/server/chunks/7595.js +1 -1
  107. package/app/.next/server/middleware-build-manifest.js +1 -1
  108. package/app/.next/server/pages/404.html +1 -1
  109. package/app/.next/server/pages/500.html +1 -1
  110. package/app/.next/static/chunks/{1321-682ad944ed69404c.js → 1321-f7d4f75925b79060.js} +1 -1
  111. package/app/package.json +1 -1
  112. package/package.json +2 -2
  113. /package/app/.next/static/{4G6rOhJtfkDwKINMqIIf1 → f8CJGNglm2tzojtq8hcMG}/_buildManifest.js +0 -0
  114. /package/app/.next/static/{4G6rOhJtfkDwKINMqIIf1 → f8CJGNglm2tzojtq8hcMG}/_ssgManifest.js +0 -0
package/README.md CHANGED
@@ -1,166 +1,473 @@
1
1
  # openrouterX
2
2
 
3
- openrouterX is a local AI provider router and management dashboard for coding
4
- agents and AI developer tools.
3
+ 面向 AI 编码工具的本地统一路由服务。
5
4
 
6
- It exposes OpenAI-compatible, Anthropic-compatible, Gemini-compatible, and
7
- provider-scoped endpoints, then routes requests to the provider accounts you
8
- connect in the dashboard. It is designed for local and self-hosted workflows
9
- where you want one endpoint, many provider accounts, quota visibility, and
10
- predictable fallback behavior.
5
+ > 当前代码分支:[`feat/openrouterx-release`](https://github.com/hackyinge/9router/tree/feat/openrouterx-release)
6
+ > GitHub 仓库:[`hackyinge/9router`](https://github.com/hackyinge/9router)
7
+ > 如果这个项目对你有帮助,欢迎点一个 Star,后续会继续更新更多 AI 编码工具、MITM、账号切换和团队网关能力。
11
8
 
12
- [npm package](https://www.npmjs.com/package/@yina-npm/openrouterx)
9
+ `openrouterX` 可以把 Claude Code、Codex、Cursor、OpenCode、OpenClaw、Cline、Continue、Roo 等客户端统一接到一个本地 OpenAI-compatible 接口,并提供 Dashboard、模型路由、API Key 管理、Usage 分析、组合模型与自动 fallback。
13
10
 
14
- ## Install
11
+ ## 为什么用 openrouterX
12
+
13
+ - 统一本地接口:`http://localhost:20502/v1`
14
+ - 统一管理后台:`http://localhost:20502/dashboard`
15
+ - 同时接入订阅型供应商、API Key 供应商、免费供应商
16
+ - 支持组合模型与自动 fallback
17
+ - 支持 Codex 账号一键激活到本机 Codex,并自动刷新 token、写入 macOS Keychain、重启 Codex App
18
+ - 支持子用户在授权范围内切换 Codex 账号,适合团队共用多账号额度
19
+ - 支持 Antigravity MITM,带上游解析修复,避免依赖固定 IP 导致网络漂移后失效
20
+ - 默认端口前移到 `20502`,安装和启动时会迁移旧的 `20128` MITM router 配置
21
+ - 配额刷新请求做了分散调度,降低多个账号集中请求触发风控的概率
22
+ - 内置 `RTK`,适合 `git diff`、`grep`、日志等重工具调用场景
23
+ - 支持管理员创建子用户,并精细限制子用户可用供应商与 API Key
24
+
25
+ ## 新增功能速览
26
+
27
+ ### Codex 账号一键激活
28
+
29
+ 在配额页面的 Codex 账号卡片上点击 `Activate`,即可把该账号应用到本机 Codex:
30
+
31
+ - 检测本机是否安装 Codex CLI 或 macOS Codex.app
32
+ - 使用账号的 `refresh_token` 刷新最新 `access_token` / `id_token`
33
+ - 写入 `~/.codex/auth.json`
34
+ - 在 macOS 上同步写入 `Codex Auth` Keychain
35
+ - 自动重启 Codex.app,让新账号立即生效
36
+
37
+ 如果本机没有安装 Codex,会提示安装方式:
38
+
39
+ ```bash
40
+ npm install -g @openai/codex
41
+ # macOS 也可以:
42
+ brew install --cask codex
43
+ ```
44
+
45
+ ### 子用户也能切换 Codex 账号
46
+
47
+ 子用户在配额页面仍然保持只读,不能编辑、删除或启停供应商连接,但可以对自己被授权看到的 Codex 账号点击 `Activate`。后端会做连接级权限校验,手写未授权的 `connectionId` 会返回 `403`。
48
+
49
+ 注意:Codex 激活修改的是当前机器的本地 Codex 登录态,是机器级状态,不是每个子用户隔离一份本地 Codex 状态。
50
+
51
+ ### Antigravity MITM 更稳定
52
+
53
+ MITM 不再依赖固定上游 IP 列表。解析上游地址时会跳过本机 alias、回环路由和已失败地址,减少这类错误:
54
+
55
+ ```txt
56
+ Passthrough error: connect EADDRNOTAVAIL ...
57
+ Router fetch failed for http://localhost:20128/v1/chat/completions
58
+ ```
59
+
60
+ 同时默认端口已从 `20128` 迁移到 `20502`,升级安装和启动时会刷新旧配置,避免其他机器升级后继续指向旧端口。
61
+
62
+ ## 安装
63
+
64
+ 从 npm 全局安装:
15
65
 
16
66
  ```bash
17
67
  npm install -g @yina-npm/openrouterx
18
68
  openrouterX
19
69
  ```
20
70
 
21
- The dashboard starts on:
71
+ 开发者在验证本地改动时,必须区分“源码启动”和“npm 包安装测试”。发布、CLI、MITM、安装布局相关改动请先阅读 [Local npm Package Testing](docs/LOCAL_NPM_TESTING.md)。
22
72
 
23
- ```text
24
- http://localhost:20502/dashboard
25
- ```
73
+ 启动后默认地址:
74
+
75
+ - Dashboard:`http://localhost:20502/dashboard`
76
+ - OpenAI-compatible API:`http://localhost:20502/v1`
26
77
 
27
- Useful commands:
78
+ ## 快速开始
79
+
80
+ ### 1. 启动本地服务
28
81
 
29
82
  ```bash
30
- openrouterX --version
31
- openrouterX status
32
- openrouterX restart --skip-update
33
- openrouterX stop
83
+ openrouterX
34
84
  ```
35
85
 
36
- Runtime data is stored outside the package:
86
+ 登录页默认在:
37
87
 
38
- ```text
39
- macOS/Linux: ~/.openrouterx
40
- Windows: %APPDATA%/openrouterx
88
+ ```txt
89
+ http://localhost:20502/login
41
90
  ```
42
91
 
43
- ## What It Does
92
+ ### 2. 登录
93
+
94
+ - `Super Admin`:完整管理权限
95
+ - `Sub User`:受限使用权限,适合团队成员或子账号
96
+
97
+ ### 3. 连接供应商
44
98
 
45
- - One local endpoint for coding tools such as Claude Code, OpenAI Codex,
46
- GitHub Copilot, Gemini CLI, OpenCode, Cline, Kilo Code, and compatible tools.
47
- - Dashboard-based provider and account management.
48
- - OAuth and API-key providers, including subscription-style provider accounts.
49
- - Multi-account routing with per-provider fallback and round-robin strategies.
50
- - Quota and usage views for supported providers.
51
- - Sub-user accounts with provider/account-level access control.
52
- - Provider-scoped OpenAI-compatible routes, for example
53
- `/api/v1/providers/codex/chat/completions`.
54
- - MITM helpers for supported local tooling workflows.
55
- - Packaged standalone Next.js runtime for global npm installation.
99
+ 进入 Dashboard 后可以接入:
56
100
 
57
- ## Default Endpoint
101
+ - 订阅型供应商:Claude Code、Codex、Copilot、Cursor
102
+ - API Key 供应商:OpenAI、Anthropic、OpenRouter、GLM、Gemini、DeepSeek、Groq、Mistral、MiniMax、Kimi 等
103
+ - 免费或低成本供应商:Kiro、OpenCode Free、Vertex AI
58
104
 
59
- Use the local OpenAI-compatible endpoint with your tools:
105
+ ### 4. 创建或复制 API Key
60
106
 
61
- ```text
62
- http://localhost:20502/api/v1
107
+ 在 Dashboard 中创建 API Key,然后把它配置到你的编码工具里。
108
+
109
+ ### 5. 把工具接到 openrouterX
110
+
111
+ ```txt
112
+ Base URL: http://localhost:20502/v1
113
+ API Key: 你的 Dashboard API Key
114
+ Model: 任意可用模型或 combo
63
115
  ```
64
116
 
65
- Common examples:
117
+ ## 工作方式
118
+
119
+ ```txt
120
+ 你的工具
121
+ -> Claude Code / Codex / Cursor / OpenCode / OpenClaw / Cline / Continue
66
122
 
67
- ```text
68
- http://localhost:20502/api/v1/chat/completions
69
- http://localhost:20502/api/v1/responses
70
- http://localhost:20502/api/v1/embeddings
71
- http://localhost:20502/api/v1/images/generations
123
+ openrouterX
124
+ -> 本地 OpenAI-compatible 接口
125
+ -> 请求格式适配
126
+ -> 模型路由与 fallback
127
+ -> 配额感知切换
128
+ -> Usage 统计
129
+ -> API Key 与子用户隔离
130
+
131
+ 上游供应商
132
+ -> 订阅账号
133
+ -> API Key 供应商
134
+ -> 免费供应商
72
135
  ```
73
136
 
74
- For tools that expect `/v1`, openrouterX also exposes:
137
+ ## 核心能力
138
+
139
+ ### 统一本地接口
75
140
 
76
- ```text
141
+ 多个工具共享同一个本地入口:
142
+
143
+ ```txt
77
144
  http://localhost:20502/v1
78
145
  ```
79
146
 
80
- ## Model Names
147
+ ### Dashboard 驱动配置
148
+
149
+ Dashboard 可以完成:
150
+
151
+ - 连接供应商
152
+ - 创建 API Key
153
+ - 测试模型
154
+ - 配置 combo
155
+ - 查看 Usage 和请求明细
156
+ - 生成各类 CLI Tools 的手动配置
157
+
158
+ ### RTK Token Saver
159
+
160
+ `RTK` 会在请求发送到上游模型前,对冗长的工具输出进行压缩,尤其适合:
81
161
 
82
- Model aliases are managed in the dashboard. Typical provider-prefixed model
83
- names look like:
162
+ - `git diff`
163
+ - `grep`
164
+ - `ls`
165
+ - 构建日志
166
+ - 长文本工具输出
84
167
 
85
- ```text
86
- codex/gpt-5.5
87
- codex/gpt-5.3-codex
88
- github/gpt-5.3-codex
89
- claude/claude-opus-4-5
90
- gemini/gemini-3-pro
168
+ ### Combo 与自动 fallback
169
+
170
+ 你可以创建一个命名 combo,让多个模型串联:
171
+
172
+ ```txt
173
+ premium-coding
174
+ 1. cc/claude-opus
175
+ 2. glm/glm-5
176
+ 3. kr/claude-sonnet-4.5
91
177
  ```
92
178
 
93
- Auto routes and custom combos can be configured in the dashboard when you want
94
- fallback across multiple providers.
179
+ 主模型不可用时,可以自动切到后备模型。
95
180
 
96
- ## API Keys And Users
181
+ ### 子用户权限隔离
97
182
 
98
- For local-only use, the dashboard can run with relaxed local defaults. For
99
- shared or remote deployments, create API keys in the dashboard and assign them
100
- carefully:
183
+ 管理员可以为子用户单独控制:
101
184
 
102
- - Super admin keys are unassigned keys.
103
- - Sub-user keys are bound to a specific sub-user.
104
- - Sub-users can be limited to specific providers and specific provider
105
- connection IDs.
185
+ - 可使用哪些供应商
186
+ - 可见哪些 API Key
187
+ - Usage 是否只看自己的数据
188
+ - 是否仅能查看 `CLI Tools` 手动配置,而不能修改本地工具设置
106
189
 
107
- ## Updating
190
+ 这适合团队共用部署、代运营账号、或敏感 API Key 隔离场景。
108
191
 
109
- ```bash
110
- npm install -g @yina-npm/openrouterx@latest --prefer-online
111
- openrouterX restart --skip-update
192
+ ### 团队共享网关
193
+
194
+ `openrouterX` 不只是单人使用工具,也可以作为团队内部统一网关:
195
+
196
+ - 管理员统一管理供应商、API Key、用户、combo
197
+ - 子用户只看到分配给自己的 API Key 和允许使用的供应商
198
+ - 子用户的 Usage 页面只展示自己的调用数据
199
+ - 子用户可以在 `CLI Tools` 页面复制配置,但不会拿到完整管理权限
200
+ - 上游供应商凭证不会暴露给普通成员
201
+
202
+ ### Usage 分析
203
+
204
+ Dashboard 支持查看:
205
+
206
+ - 请求数
207
+ - tokens
208
+ - estimated cost
209
+ - 按 API Key 的使用情况
210
+ - 请求明细
211
+
212
+ 其中成本展示主要用于统计和对比,`openrouterX` 本身不会向你收费。
213
+
214
+ ## 支持的工具
215
+
216
+ `openrouterX` 面向各类 AI 编码工具和 OpenAI-compatible 客户端,包括:
217
+
218
+ - Claude Code
219
+ - Codex CLI
220
+ - Cursor
221
+ - OpenCode
222
+ - OpenClaw
223
+ - Cline
224
+ - Continue
225
+ - Roo
226
+ - 兼容 Copilot 的相关流程
227
+ - 其他支持 OpenAI-compatible 接口的自定义工具
228
+
229
+ ## 支持的供应商类型
230
+
231
+ ### 订阅型供应商
232
+
233
+ - Claude Code
234
+ - Codex
235
+ - GitHub Copilot
236
+ - Cursor
237
+
238
+ ### API Key 供应商
239
+
240
+ - OpenAI
241
+ - Anthropic
242
+ - OpenRouter
243
+ - GLM
244
+ - Gemini
245
+ - DeepSeek
246
+ - Groq
247
+ - Mistral
248
+ - MiniMax
249
+ - Kimi
250
+ - 以及其他兼容供应商
251
+
252
+ ### 免费或低成本供应商
253
+
254
+ - Kiro
255
+ - OpenCode Free
256
+ - Vertex AI
257
+
258
+ 实际可用性取决于上游服务当前状态和你的本地配置。
259
+
260
+ ## CLI Tools 配置
261
+
262
+ Dashboard 内置了 `CLI Tools` 页面,可以直接生成可复制的配置。
263
+
264
+ ### 通用 OpenAI-compatible 配置
265
+
266
+ ```txt
267
+ Base URL: http://localhost:20502/v1
268
+ API Key: 你的 Dashboard API Key
269
+ Model: 你选择的模型或 combo
112
270
  ```
113
271
 
114
- ## Uninstall
272
+ ### Codex CLI
115
273
 
116
274
  ```bash
117
- npm uninstall -g @yina-npm/openrouterx
275
+ export OPENAI_BASE_URL="http://localhost:20502/v1"
276
+ export OPENAI_API_KEY="your-dashboard-api-key"
118
277
  ```
119
278
 
120
- This removes the npm package. Runtime data under `~/.openrouterx` is not removed
121
- automatically.
279
+ ### Claude Code
280
+
281
+ 直接使用 `CLI Tools -> Claude Code` 中生成的手动配置。
282
+
283
+ ### OpenClaw
284
+
285
+ 直接使用 `CLI Tools -> OpenClaw` 中生成的手动配置。
286
+
287
+ ### OpenCode
288
+
289
+ 直接使用 `CLI Tools -> OpenCode` 中生成的手动配置。
290
+
291
+ ## 管理员与子用户
292
+
293
+ `openrouterX` 内置两种角色:
294
+
295
+ - `super_admin`
296
+ - `sub_user`
297
+
298
+ ### `super_admin`
299
+
300
+ 可以管理:
122
301
 
123
- ## Local Development
302
+ - providers
303
+ - API keys
304
+ - combos
305
+ - users
306
+ - usage analytics
307
+ - 本地工具集成配置
308
+
309
+ ### `sub_user`
310
+
311
+ 可以被限制为:
312
+
313
+ - 只能使用分配给自己的 API Key
314
+ - 只能访问被允许的供应商
315
+ - 只能查看自己的 Usage 数据
316
+ - 只显示精简版 `CLI Tools`
317
+ - 可以复制手动配置,但不能管理供应商
318
+ - 页面范围聚焦在自己的可见资源内
319
+
320
+ 这使得一个部署可以服务多个用户,同时避免把所有供应商和凭证暴露给每个人。
321
+
322
+ ## 本地开发
323
+
324
+ 从源码运行:
124
325
 
125
326
  ```bash
327
+ cp .env.example .env
126
328
  npm install
127
- npm run dev
329
+ PORT=20502 NEXT_PUBLIC_BASE_URL=http://localhost:20502 npm run dev
128
330
  ```
129
331
 
130
- Build:
332
+ 生产构建:
131
333
 
132
334
  ```bash
133
335
  npm run build
336
+ PORT=20502 HOSTNAME=0.0.0.0 NEXT_PUBLIC_BASE_URL=http://localhost:20502 npm run start
134
337
  ```
135
338
 
136
- Create and validate the npm staging package without publishing:
339
+ ### 切换端口
340
+
341
+ 默认端口是 `20502`。临时切到其他端口时,同时设置 `PORT` 和对外 base URL:
137
342
 
138
343
  ```bash
139
- npm run release:npm:dry
344
+ PORT=20600 NEXT_PUBLIC_BASE_URL=http://localhost:20600 npm run dev
140
345
  ```
141
346
 
142
- Install a local test build globally:
347
+ 生产模式同理:
348
+
349
+ ```bash
350
+ PORT=20600 HOSTNAME=0.0.0.0 NEXT_PUBLIC_BASE_URL=http://localhost:20600 npm run start
351
+ ```
352
+
353
+ 如果使用全局安装的 `openrouterX`,端口来自 CLI 内置默认值或启动时的 `PORT` 环境变量。修改默认端口后需要重新 npm 全局安装并重启:
143
354
 
144
355
  ```bash
145
356
  npm run release:npm:install-local
357
+ openrouterX restart --no-browser --skip-update
146
358
  ```
147
359
 
148
- ## Package
360
+ 切换端口后,CLI 工具里的 Base URL 也要同步改成新端口,例如 `http://localhost:20600/v1`。
361
+
362
+ ## 部署
363
+
364
+ ### PM2
149
365
 
150
- Published package:
366
+ ```bash
367
+ npm install
368
+ npm run build
369
+ pm2 start npm --name openrouterx -- start
370
+ ```
151
371
 
152
- ```text
153
- @yina-npm/openrouterx
372
+ ### Docker
373
+
374
+ ```bash
375
+ docker build -t openrouterx .
376
+
377
+ docker run -d \
378
+ --name openrouterx \
379
+ -p 20502:20502 \
380
+ --env-file ./.env \
381
+ -v openrouterx-data:/app/data \
382
+ openrouterx
154
383
  ```
155
384
 
156
- Global command:
385
+ ## 环境变量
386
+
387
+ | 变量 | 说明 |
388
+ | --- | --- |
389
+ | `JWT_SECRET` | Dashboard 登录鉴权使用的 JWT secret |
390
+ | `INITIAL_PASSWORD` | 初始登录密码,在没有已保存 hash 时使用 |
391
+ | `DATA_DIR` | 主数据库目录 |
392
+ | `PORT` | 服务端口 |
393
+ | `HOSTNAME` | 监听地址 |
394
+ | `BASE_URL` | 服务端内部使用的 base URL |
395
+ | `CLOUD_URL` | 云端同步使用的 base URL |
396
+ | `NEXT_PUBLIC_BASE_URL` | 前端可见的 base URL |
397
+ | `NEXT_PUBLIC_CLOUD_URL` | 前端可见的云端 URL |
398
+ | `API_KEY_SECRET` | 生成 API Key 时使用的签名 secret |
399
+ | `MACHINE_ID_SALT` | 机器标识计算使用的 salt |
400
+ | `ENABLE_REQUEST_LOGS` | 是否开启请求日志 |
401
+ | `AUTH_COOKIE_SECURE` | 是否强制使用安全 Cookie |
402
+ | `REQUIRE_API_KEY` | 是否要求 `/v1/*` 必须携带 Bearer API Key |
403
+
404
+ ## API 示例
405
+
406
+ ### Chat Completions
157
407
 
158
- ```text
159
- openrouterX
408
+ ```bash
409
+ curl http://localhost:20502/v1/chat/completions \
410
+ -H "Authorization: Bearer YOUR_API_KEY" \
411
+ -H "Content-Type: application/json" \
412
+ -d '{
413
+ "model": "kr/claude-sonnet-4.5",
414
+ "messages": [
415
+ { "role": "user", "content": "Write a Node.js hello world server." }
416
+ ],
417
+ "stream": false
418
+ }'
160
419
  ```
161
420
 
162
- Default port:
421
+ ### 列出模型
163
422
 
164
- ```text
165
- 20502
423
+ ```bash
424
+ curl http://localhost:20502/v1/models \
425
+ -H "Authorization: Bearer YOUR_API_KEY"
166
426
  ```
427
+
428
+ ## 常见问题
429
+
430
+ ### Dashboard 打不开
431
+
432
+ - 检查 `20502` 端口是否被占用
433
+ - 启动前显式设置 `PORT=20502`
434
+
435
+ ### 登录失败
436
+
437
+ - 初始化环境时检查 `INITIAL_PASSWORD`
438
+ - 如果已经有历史数据,请使用当前保存的管理员密码,不要假设存在默认密码
439
+
440
+ ### 工具看不到模型
441
+
442
+ - 确认供应商已连接
443
+ - 确认当前 API Key 属于当前用户
444
+ - 如果是子用户,检查 `Admin -> Users` 中配置的 allowed providers
445
+
446
+ ### Usage 没有数据
447
+
448
+ - 确认工具接入的是 `http://localhost:20502/v1`
449
+ - 确认使用的是 Dashboard 中生成的 Bearer API Key
450
+
451
+ ### 上游报错或配额不足
452
+
453
+ - 重新连接供应商
454
+ - 切换到其他模型
455
+ - 创建带 fallback 的 combo
456
+
457
+ ## 包信息
458
+
459
+ - npm 包:[`@yina-npm/openrouterx`](https://www.npmjs.com/package/@yina-npm/openrouterx)
460
+ - 启动命令:`openrouterX`
461
+ - 代码仓库:[`hackyinge/9router`](https://github.com/hackyinge/9router)
462
+ - 当前分支:[`feat/openrouterx-release`](https://github.com/hackyinge/9router/tree/feat/openrouterx-release)
463
+ - 协议:MIT
464
+
465
+ ## 作者
466
+
467
+ 如果你喜欢这个项目,欢迎到 GitHub 给 [`hackyinge/9router`](https://github.com/hackyinge/9router) 点个 Star。Star 会直接决定作者继续摸鱼写功能的速度。
468
+
469
+ 作者除了写 AI 工具,也在番茄小说写小说。感兴趣可以在番茄小说搜索作者:**首席摸鱼**。
470
+
471
+ ## License
472
+
473
+ MIT,见 [LICENSE](LICENSE)。
@@ -1 +1 @@
1
- 4G6rOhJtfkDwKINMqIIf1
1
+ f8CJGNglm2tzojtq8hcMG
@@ -4,8 +4,8 @@
4
4
  ],
5
5
  "devFiles": [],
6
6
  "lowPriorityFiles": [
7
- "static/4G6rOhJtfkDwKINMqIIf1/_buildManifest.js",
8
- "static/4G6rOhJtfkDwKINMqIIf1/_ssgManifest.js"
7
+ "static/f8CJGNglm2tzojtq8hcMG/_buildManifest.js",
8
+ "static/f8CJGNglm2tzojtq8hcMG/_ssgManifest.js"
9
9
  ],
10
10
  "rootMainFiles": [
11
11
  "static/chunks/webpack-b9b0d264958323b9.js",