picoclaw/pkg/config
Liu Yuan e73d9d959e
feat(config): support multiple API keys for failover (#1707)
* feat(config): support multiple API keys for failover

Add api_keys field to ModelConfig to support multiple API keys with
automatic failover. When multiple keys are configured, they are expanded
into separate model entries with fallbacks set up for key-level failover.

Example config:
  {
    "model_name": "glm-4.7",
    "model": "zhipu/glm-4.7",
    "api_keys": ["key1", "key2", "key3"]
  }

Expands internally to:
  - glm-4.7 (key1) -> fallbacks: [glm-4.7__key_1, glm-4.7__key_2]
  - glm-4.7__key_1 (key2)
  - glm-4.7__key_2 (key3)

Backward compatible: single api_key still works as before.

* fix(providers): change cooldown tracking from provider to ModelKey

This enables proper key-switching when multiple API keys share the same
provider. Previously, when one key failed, all keys were blocked because
cooldown was tracked per-provider.

Now each (provider, model) combination has independent cooldown, allowing
fallback to alternate keys when one is rate limited.

Includes TestMultiKeyWithModelFallback and related failover tests.
2026-03-19 00:57:20 +08:00
..
config.go feat(config): support multiple API keys for failover (#1707) 2026-03-19 00:57:20 +08:00
config_test.go feat: Add Novita provider support (#1677) 2026-03-18 18:29:27 +08:00
defaults.go feat: telegram use parse mode ModeMarkdownV2 instead of ModeHTML (#1018) 2026-03-18 21:29:21 +08:00
envkeys.go refactor: centralize environment variable key constants (#1730) 2026-03-18 18:03:24 +08:00
migration.go feat(provider): add ModelScope as OpenAI-compatible provider (#1486) 2026-03-13 14:02:23 +08:00
migration_test.go feat(provider): add ModelScope as OpenAI-compatible provider (#1486) 2026-03-13 14:02:23 +08:00
model_config_test.go fix(config): start model round robin from the first match 2026-03-17 21:59:04 +08:00
multikey_test.go feat(config): support multiple API keys for failover (#1707) 2026-03-19 00:57:20 +08:00
version.go feat:Modify the location where version is obtained, and insert version information into the context (#1300) 2026-03-10 17:42:05 +08:00
version_test.go feat:Modify the location where version is obtained, and insert version information into the context (#1300) 2026-03-10 17:42:05 +08:00