bub icon indicating copy to clipboard operation
bub copied to clipboard

Let users name provider endpoints (two endpoints speaking the same API) / 允许自定义 provider 名,让同一协议的多个端点并存

Open Gabyran opened this issue 1 month ago • 0 comments

Problem

api_key / api_base hold one value per any-llm provider, and the model prefix has to be an any-llm provider. So every endpoint that speaks a supported API has to borrow that provider's slot, and only one endpoint can hold it at a time:

  • Real OpenAI plus a company proxy, a relay or a local gateway can't be configured together, nor can two relays, nor two accounts with the same vendor. The same goes for proxies in front of Anthropic or Gemini.
  • Setting api_base.openai for a relay also switches off Codex OAuth, which is used only when openai has no custom base (should_use_openai_codex_provider).
  • BUB_ACME_API_KEY is already accepted (see test_client_options_resolve_provider_names_and_enum_values), but acme: can't be used as a model prefix.

This is not a request to add another named provider (cf. #279): any-llm already covers the protocols. It only lets the user name an endpoint and say which any-llm provider speaks for it.

Proposal

model: proxy:gpt-5.5
fallback_models:
  - openai:gpt-5.5
  - relay:claude-sonnet-5
providers:
  proxy:
    type: openai          # any LLMProvider value
    api_base: https://llm-proxy.example.com/v1
    api_key: sk-proxy-...
  relay:
    type: anthropic
    api_base: https://relay.example.com
    api_key: sk-relay-...

proxy: resolves to LLMProvider.OPENAI and relay: to LLMProvider.ANTHROPIC, each with its own base and key; openai: keeps its own api_key / api_base, or Codex OAuth. Fields left out fall back to api_key / api_base and BUB_<NAME>_API_*. An unknown type fails when settings load.

The change is about 20 lines in settings.py and one in model_runner.py, with tests and docs (en / zh-cn): https://github.com/Gabyran/bub/compare/main...feat/custom-providers. I'll open a PR if the direction looks right.


问题

api_key / api_base 每个 any-llm provider 只能放一个值,模型前缀也必须是 any-llm 的 provider 名。所以凡是说已支持协议的端点,都只能借用对应 provider 的位置,而且同一时间只能有一个端点占着:

  • 真 OpenAI 和公司代理、中转站或本地网关没法同时配置,两个中转站不行,同一厂商的两个账号也不行。Anthropic、Gemini 前面的代理同理。
  • 给中转站设置 api_base.openai 还会顺带关掉 Codex OAuth,因为只有 openai 没设自定义 base 时才会走 Codex OAuth(should_use_openai_codex_provider)。
  • BUB_ACME_API_KEY 现在已经能被读取(见 test_client_options_resolve_provider_names_and_enum_values),但 acme: 不能当模型前缀用。

这不是要再加一个具名 provider(参见 #279):协议 any-llm 都已经支持了。只是让用户给端点起个名字,并说明它走哪个 any-llm provider 的协议。

方案

配置见上方 YAML。proxy: 解析为 LLMProvider.OPENAI,relay: 解析为 LLMProvider.ANTHROPIC,各用自己的地址和 key;openai: 仍使用它自己的 api_key / api_base,或 Codex OAuth。条目里没写的字段回退到 api_key / api_base 和 BUB_<NAME>_API_*。type 不是已知 provider 时,加载配置直接报错。

改动是 settings.py 约 20 行加 model_runner.py 一行,带测试和中英文文档:https://github.com/Gabyran/bub/compare/main...feat/custom-providers 。方向没问题的话我就提 PR。

Gabyran avatar Oct 07 '26 07:10 Gabyran