Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ PROXY=
# 单账户初始化超时
INIT_TIMEOUT=2m

# 普通请求最大执行时间
# 上游连续没有数据的最长时间,从请求开始到首个数据同样计入
REQUEST_TIMEOUT=30m

# 常驻预热账户数,未设置时 SpiderMonkey 后端为 10、Camoufox 后端为 5
Expand All @@ -60,7 +60,7 @@ ROUTING_STRATEGY=round-robin
# fill-first 依次使用的账户 ID,逗号分隔,未列出的账户排在后面并按 ID 排序,保存后立即生效
ACCOUNT_ORDER=

# 上游返回 403、5xx 等非额度错误时一个请求最多换几次账户重试,0 为不换号;额度用尽不计入
# 上游返回 403、5xx 等非额度错误时一个请求最多换几次账户重试,0 为不换号;登录失效与额度用尽不计入
MAX_ACCOUNT_SWITCHES=3

# 生成请求使用的上游通道:playground、build(旧通道,上游已停用其生成),逗号分隔
Expand Down Expand Up @@ -99,12 +99,24 @@ CONTINUATION_REWRITE=true
# 改写时与末尾 assistant 消息一起写入系统指令的续写提示词;设为空时末尾 assistant 消息改作 user 消息发送
CONTINUATION_PROMPT="Continue the assistant response after the following prefix. Return only the continuation, without repeating the prefix."

# 仅限角色扮演场景:声明内部 final 工具让模型一次性交付完整正文以减轻流式截断,思考照常实时输出,保存后立即生效
REPLY_TOOL=false

# 角色扮演场景思考防拦截:引导模型在内部思考中保持简洁抽象、不复述敏感词,并将思考强度上限收敛到低档,降低思考阶段触发上游过滤截断的概率,保存后立即生效
THINKING_GUARD=false

# 发送前将用户消息中的中文改写为指定文字(不改模型历史回答),并在系统指令中要求模型默认以简体中文回复:off 关闭,traditional 繁体中文,martian 火星文,保存后立即生效
USER_MESSAGE_REWRITE=off

# 原请求迟迟没有首字时用空闲账户(其他账户优先,没有时用原账户的空闲槽位)发起一个备用请求,先出首字的一方继续:off 关闭,auto 按各模型与通道近 24 小时首字等待的 p95,正整数为等待秒数
FIRST_EVENT_HEDGE=off

# 发起备用请求的模型 ID,逗号分隔;备用请求同样计入账户额度
FIRST_EVENT_HEDGE_MODELS=gemini-4-argon

# 一次尝试从取得账户起等待首个上游事件的最长时间,到时取消这次尝试并换号(计入 MAX_ACCOUNT_SWITCHES,不冷却账户),没有可换的账户时返回 504;off 关闭,正整数为秒数
FIRST_EVENT_TIMEOUT=off

# WAA 后端:spidermonkey 在服务进程内的 SpiderMonkey 中运行,camoufox 使用 Camoufox 页面
WAA_BACKEND=spidermonkey

Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ docker compose up -d

设置的生效时机:

- 保存后立即生效:账户选择策略、Worker 容量、换号次数上限、模型映射、非流式保活、假流式、搜索型号、全模型搜索与媒体输出;进行中的请求沿用开始时的设置
- 保存后立即生效:账户选择策略、Worker 容量、换号次数上限、模型映射、非流式保活、假流式、搜索型号、全模型搜索、回复工具防截断、简体转繁体改写与媒体输出;进行中的请求沿用开始时的设置
- 停止再启动生成服务后生效:其余生成服务配置,启动时读取最新 `.env`
- 重启管理进程后生效:管理页面地址、预览地址和 `PROXY_API_KEY`

Expand Down Expand Up @@ -357,12 +357,13 @@ curl http://127.0.0.1:2048/v1/chat/completions \
4. API 密钥填写 `.env` 中的 `PROXY_API_KEY`
5. 从 `/v1/models` 获取模型,或手动添加 `gemini-3.8-flash`、`gemini-3.5-flash-lite`

[Claude Code](https://github.com/anthropics/claude-code) 使用 Anthropic 接口,子 Agent 按 opus、sonnet、haiku 档位选择模型,以下变量把它们映射到 AI Studio 模型;WebSearch 由 Google Search 执行:
[Claude Code](https://github.com/anthropics/claude-code) 使用 Anthropic 接口,子 Agent 按 fable、opus、sonnet、haiku 档位选择模型,以下变量把它们映射到 AI Studio 模型;WebSearch 由 Google Search 执行:

```powershell
$env:ANTHROPIC_BASE_URL = "http://127.0.0.1:2048"
$env:ANTHROPIC_API_KEY = "<PROXY_API_KEY>"
$env:ANTHROPIC_MODEL = "gemini-3.8-flash"
$env:ANTHROPIC_DEFAULT_FABLE_MODEL = "gemini-4-argon"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL = "gemini-3.1-pro-preview"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL = "gemini-3.8-flash"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "gemini-3.5-flash-lite"
Expand Down Expand Up @@ -672,7 +673,7 @@ cp .env.example .env
| `ADMIN_PASSWORD` | 空 | 管理员密码,开启登录时必填 |
| `PROXY` | 空 | Chrome 导入、登录和账户默认使用的 HTTP、HTTPS 或 SOCKS5 代理,多个代理用逗号分隔组成代理池;留空时使用系统代理 |
| `INIT_TIMEOUT` | `2m` | 单账户 WAA 初始化超时 |
| `REQUEST_TIMEOUT` | `30m` | 单次请求最大执行时间,自动续写的每一轮开始时重新计时 |
| `REQUEST_TIMEOUT` | `30m` | 上游连续没有数据的最长时间,从请求开始到首个数据同样计入;上游仍在输出的请求不受总时长限制 |
| `WARM_WORKER_LIMIT` | `10`,Camoufox 后端 `5` | 常驻预热账户数 |
| `MAX_ACTIVE_WORKERS` | `20`,Camoufox 后端 `10` | 高峰期最多同时运行的 Worker 数 |
| `WARM_STARTUP_CONCURRENCY` | `5` | 按需扩容时同时冷启动的 Camoufox Worker 数,预热逐个启动;`WAA_BACKEND=spidermonkey` 时不限制 |
Expand All @@ -694,8 +695,12 @@ cp .env.example .env
| `GOOGLE_SEARCH` | `false` | 为 OpenAI、Anthropic、Gemini 与 Interactions 的生成请求启用 Google 搜索,包含普通型号与携带函数工具的请求 |
| `CONTINUATION_REWRITE` | `true` | 以 assistant 消息结尾的请求在不支持原生续写的模型上改写为续写请求;关闭时所有模型原样发送,上游拒绝时返回其错误 |
| `CONTINUATION_PROMPT` | 内置英文续写句 | 改写时与末尾 assistant 消息一起写入系统指令的提示词;设为空时末尾 assistant 消息改作 user 消息发送 |
| `REPLY_TOOL` | `false` | 仅限角色扮演场景:声明内部 `final` 工具让模型一次性交付完整正文以减轻流式截断,思考照常实时输出;保存后立即生效 |
| `THINKING_GUARD` | `false` | 角色扮演场景思考防拦截:引导模型在内部思考中保持简洁抽象、不复述敏感词,并将思考强度上限收敛到低档,降低思考阶段触发上游过滤截断的概率;保存后立即生效 |
| `USER_MESSAGE_REWRITE` | `off` | 发送前将用户消息中的中文改写为繁体中文或火星文(不改模型历史回答),并在系统指令中要求模型默认以简体中文回复;取值 `off`、`traditional` 或 `martian`,保存后立即生效 |
| `FIRST_EVENT_HEDGE` | `off` | 原请求迟迟没有首字时用空闲账户发起一个备用请求,取值 `off`、`auto` 或等待秒数 |
| `FIRST_EVENT_HEDGE_MODELS` | `gemini-4-argon` | 发起备用请求的模型 ID,逗号分隔;备用请求同样计入账户额度 |
| `FIRST_EVENT_TIMEOUT` | `off` | 单次尝试从取得账户起等待首个上游事件的最长时间,到时取消并换号,取值 `off` 或正整数秒 |
| `WAA_BACKEND` | `spidermonkey` | WAA 运行的位置,`spidermonkey` 或 `camoufox` |
| `MEDIA_OUTPUT` | `inline` | Chat Completions 与 Messages 正文中生成图片与音频的引用方式,`inline` 或 `url` |
| `MEDIA_BASE_URL` | 空 | 媒体 URL 使用的服务地址,例如 `https://ai.example.com`;留空时使用每个请求访问的地址,经反向代理时跟随 `X-Forwarded-Proto` |
Expand All @@ -704,7 +709,7 @@ cp .env.example .env

- `PREVIEW_LISTEN_ADDR`:无法监听时改用同一主机上的空闲端口;页面以当前访问的主机名加实际端口打开预览
- `AUTO_START`:网络等原因启动失败时按 5 秒起、翻倍至 5 分钟的间隔重试,手动启动或停止后不再重试
- `MAX_ACCOUNT_SWITCHES`:额度用尽不计入,照常依次尝试其余账户
- `MAX_ACCOUNT_SWITCHES`:登录失效与额度用尽不计入,照常依次尝试其余账户
- `NONSTREAM_KEEPALIVE`:返回 200 后每 10 秒写出一个换行直到写出 JSON 正文,经 Cloudflare 等反向代理时连接不会因长时间无数据断开;此后才出现的错误以协议错误正文返回
- `STRIP_THOUGHT_SIGNATURES`:函数调用带 `skip_thought_signature_validator`;之前各轮的思考内容不随签名发给模型,长对话的输入 token 较少
- `DISCOVER_HIDDEN_MODELS`:
Expand All @@ -715,6 +720,9 @@ cp .env.example .env
- 备用请求优先用其他账户,没有时用原账户的空闲槽位;先出首字的一方继续,另一方取消
- `auto` 按各模型与通道近 24 小时首字等待的 p95,请求少于 20 次的模型与通道不发起
- 正整数为等待秒数,设置页选自定义时填入请求最多的模型的近期 p95
- `FIRST_EVENT_TIMEOUT`:
- 每次尝试从取得账户起独立计时,收到首个语义事件即停止;到时取消这次尝试并换号,计入 `MAX_ACCOUNT_SWITCHES`、不冷却账户,没有可换账户时返回 504
- 与 `FIRST_EVENT_HEDGE` 同开时原请求与备用请求各自计时,建议大于对冲等待秒数;排除后台请求与 agent 后台任务,慢思考请求的首字可能需要几分钟
- `WAA_BACKEND`:
- `spidermonkey` 在服务进程内的 SpiderMonkey 中运行 WAA,不下载也不启动 Camoufox;`camoufox` 在 Camoufox 页面运行 WAA;其他取值按 `spidermonkey`
- 未设置时,启动时按 `auth/` 确定后写入 `.env`:已有账户而没有 `auth/.waa-interpreters` 时为 `camoufox`,否则为 `spidermonkey`
Expand Down Expand Up @@ -806,7 +814,7 @@ API 试用页的 HTML 预览运行在 `PREVIEW_LISTEN_ADDR` 提供的独立来

权益与模型目录的读取:

- “刷新全部”立即读取全部启用账户的权益与模型目录,后台每 24 小时也会读取一次;请求的模型不在目录中且距上次读取超过 10 分钟时,服务先读取一次再处理该请求
- “刷新全部”立即读取全部启用账户的权益与模型目录,在服务端运行,关闭或刷新管理页后继续,重新打开时显示进度与排队的账户;后台每 24 小时也会读取一次;请求的模型不在目录中且距上次读取超过 10 分钟时,服务先读取一次再处理该请求
- 从未读取成功的账户权益显示为未知,并显示最近一次失败原因;已有目录的账户读取失败时照常使用,账户行显示“目录同步失败”与原因
- 读取报告 AI Studio 不支持当前出口地区时,已有目录的账户同样显示该原因

Expand Down
18 changes: 13 additions & 5 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ Add more accounts on the same page; [Account Management](#account-management) co

When settings take effect:

- As soon as they are saved: the account selection strategy, worker capacity, max account switches, model mapping, non-streaming keepalive, fake streaming, search model variants, Google Search for all models, and media output; requests already in progress keep the settings they started with
- As soon as they are saved: the account selection strategy, worker capacity, max account switches, model mapping, non-streaming keepalive, fake streaming, search model variants, Google Search for all models, reply tool anti-truncation, Simplified to Traditional Chinese rewrite, and media output; requests already in progress keep the settings they started with
- After stopping and starting the generation service: the other data-plane settings, read from the latest `.env` at start
- After restarting the management process: `LISTEN_ADDR`, `PREVIEW_LISTEN_ADDR`, and `PROXY_API_KEY`

Expand Down Expand Up @@ -357,12 +357,13 @@ For Cherry Studio:
4. Set the API key to `PROXY_API_KEY` from `.env`
5. Load models from `/v1/models`, or add `gemini-3.8-flash` and `gemini-3.5-flash-lite` manually

[Claude Code](https://github.com/anthropics/claude-code) uses the Anthropic endpoint. Subagents pick models by the opus, sonnet, and haiku tiers; the variables below map them to AI Studio models. WebSearch runs on Google Search:
[Claude Code](https://github.com/anthropics/claude-code) uses the Anthropic endpoint. Subagents pick models by the fable, opus, sonnet, and haiku tiers; the variables below map them to AI Studio models. WebSearch runs on Google Search:

```powershell
$env:ANTHROPIC_BASE_URL = "http://127.0.0.1:2048"
$env:ANTHROPIC_API_KEY = "<PROXY_API_KEY>"
$env:ANTHROPIC_MODEL = "gemini-3.8-flash"
$env:ANTHROPIC_DEFAULT_FABLE_MODEL = "gemini-4-argon"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL = "gemini-3.1-pro-preview"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL = "gemini-3.8-flash"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "gemini-3.5-flash-lite"
Expand Down Expand Up @@ -672,7 +673,7 @@ Process environment variables override the same keys in `.env`, and those settin
| `ADMIN_PASSWORD` | empty | Administrator password, required when login is enabled |
| `PROXY` | empty | HTTP, HTTPS, or SOCKS5 proxy used by Chrome import, login, and accounts without an override; separate several proxies with commas to form a proxy pool; the system proxy is used when empty |
| `INIT_TIMEOUT` | `2m` | Per-account WAA initialization timeout |
| `REQUEST_TIMEOUT` | `30m` | Maximum request execution time, restarted at the start of each auto-continuation round |
| `REQUEST_TIMEOUT` | `30m` | Longest time upstream may send no data, counted from the start of the request until the first data too; requests that upstream is still streaming have no total time limit |
| `WARM_WORKER_LIMIT` | `10`, `5` with Camoufox | Number of resident prewarmed accounts |
| `MAX_ACTIVE_WORKERS` | `20`, `10` with Camoufox | Maximum workers active during peak load |
| `WARM_STARTUP_CONCURRENCY` | `5` | Camoufox workers cold-started concurrently during on-demand scaling; prewarming starts workers one at a time; unlimited with `WAA_BACKEND=spidermonkey` |
Expand All @@ -694,8 +695,12 @@ Process environment variables override the same keys in `.env`, and those settin
| `GOOGLE_SEARCH` | `false` | Enable Google Search for OpenAI, Anthropic, Gemini, and Interactions generation requests, including ordinary model IDs and requests with function tools |
| `CONTINUATION_REWRITE` | `true` | Rewrite requests ending with an assistant message as continuation requests on models without native continuation; when off, every model receives them unchanged and an upstream rejection is returned as is |
| `CONTINUATION_PROMPT` | built-in English sentence | Prompt written into the system instruction together with the trailing assistant message when rewriting; when set empty, the trailing assistant message is sent as a user message |
| `REPLY_TOOL` | `false` | For roleplay only: declare an internal `final` tool so the model delivers the complete reply at once to reduce mid-stream truncation while keeping thinking streamed live; applies on save |
| `THINKING_GUARD` | `false` | Roleplay thinking anti-block: guide internal reasoning to stay brief and abstract without repeating sensitive terms and cap thinking effort at low, reducing upstream filter truncation during reasoning; applies on save |
| `USER_MESSAGE_REWRITE` | `off` | Rewrite Chinese text in user messages to Traditional Chinese or Martian Chinese before sending (leaving assistant history unchanged) and instruct the model to reply in Simplified Chinese by default; `off`, `traditional`, or `martian`; applies on save |
| `FIRST_EVENT_HEDGE` | `off` | When a request has no first token for a while, send a backup request on an idle account; `off`, `auto`, or a wait in seconds |
| `FIRST_EVENT_HEDGE_MODELS` | `gemini-4-argon` | Comma-separated model IDs that get backup requests; backup requests also count against account quota |
| `FIRST_EVENT_TIMEOUT` | `off` | Longest time a single attempt waits for its first upstream event after taking an account before cancelling and switching accounts; `off` or a positive integer in seconds |
| `WAA_BACKEND` | `spidermonkey` | Where WAA runs: `spidermonkey` or `camoufox` |
| `MEDIA_OUTPUT` | `inline` | How Chat Completions and Messages include generated images and audio: `inline` or `url` |
| `MEDIA_BASE_URL` | empty | Service address used in media URLs, such as `https://ai.example.com`; empty uses the address of each request and follows `X-Forwarded-Proto` behind a reverse proxy |
Expand All @@ -704,7 +709,7 @@ Notes:

- `PREVIEW_LISTEN_ADDR`: when it cannot be bound, a free port on the same host is used; the page opens previews at the current host name with the port in use
- `AUTO_START`: if startup fails for reasons such as the network, it retries at intervals starting at 5 seconds and doubling up to 5 minutes, until the service is started or stopped manually
- `MAX_ACCOUNT_SWITCHES`: quota errors do not count, and the remaining accounts are still tried in turn
- `MAX_ACCOUNT_SWITCHES`: expired sessions and quota errors do not count, and the remaining accounts are still tried in turn
- `NONSTREAM_KEEPALIVE`: after returning 200, a newline is written every 10 seconds until the JSON body, so reverse proxies such as Cloudflare keep the connection open; errors after that point come back as the protocol error body
- `STRIP_THOUGHT_SIGNATURES`: function calls are sent with `skip_thought_signature_validator`; earlier turns' thinking is not passed to the model with the signatures, so long conversations use fewer input tokens
- `DISCOVER_HIDDEN_MODELS`:
Expand All @@ -715,6 +720,9 @@ Notes:
- The backup request uses another account first, otherwise a free slot on the same account; the first to answer continues and the other is cancelled
- `auto` waits for the p95 of each model and channel over the last 24 hours, and models with fewer than 20 requests are not hedged
- A positive integer is the wait in seconds; choosing Custom in settings fills in the recent p95 of the busiest model
- `FIRST_EVENT_TIMEOUT`:
- Each attempt is timed independently from taking an account until the first semantic event arrives; on timeout it cancels the attempt and switches accounts (counts toward `MAX_ACCOUNT_SWITCHES`, does not cool the account), returning 504 if no account is left
- With `FIRST_EVENT_HEDGE` enabled, the primary and backup requests keep separate timers and this should be set higher than the hedge wait; excludes background requests and background agent tasks; slow thinking requests may take several minutes before their first token
- `WAA_BACKEND`:
- `spidermonkey` runs WAA in SpiderMonkey inside the service process and neither downloads nor starts Camoufox; `camoufox` runs WAA in a Camoufox page; any other value means `spidermonkey`
- When unset, startup picks it from `auth/` and writes it to `.env`: `camoufox` if `auth/` already has accounts but no `auth/.waa-interpreters`, otherwise `spidermonkey`
Expand Down Expand Up @@ -805,7 +813,7 @@ Account actions depend on state. Click the state in an account row to set the ac

Reading the benefit tier and model catalog:

- Refresh all reads the benefit tier and model catalog of every enabled account immediately; the service also reads them every 24 hours, and when a request names a model missing from the catalog and the last read was more than 10 minutes ago, the service reads them first and then handles the request
- Refresh all reads the benefit tier and model catalog of every enabled account immediately; it runs on the server and keeps going after the console is closed or reloaded, and reopening the console shows its progress and the queued accounts; the service also reads them every 24 hours, and when a request names a model missing from the catalog and the last read was more than 10 minutes ago, the service reads them first and then handles the request
- An account whose catalog has never been read shows an unknown tier and the reason for the last failed read; an account with an existing catalog keeps working when a read fails, and its row shows "Model sync failed" with the reason
- When a read reports that AI Studio does not support the current egress region, accounts with an existing catalog show that reason as well

Expand Down
Loading