picoclaw/pkg/providers
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
..
anthropic fix(anthropic): skip tool calls with empty names to prevent API errors (#1739) 2026-03-18 21:55:01 +08:00
anthropic_messages fix(providers): handle nil input in GLM series tool_use blocks 2026-03-17 12:16:24 +08:00
azure fix(provider/azure): lint err 2026-03-15 12:45:11 +08:00
common feat(provider): add support for azure openai provider (#1422) 2026-03-14 22:52:34 +08:00
openai_compat feat: Add Novita provider support (#1677) 2026-03-18 18:29:27 +08:00
protocoltypes feat(providers): add Media field to Message struct for vision support 2026-03-03 16:27:29 +08:00
antigravity_provider.go fix: handle ignored io.ReadAll errors across codebase 2026-03-05 20:56:38 +09:00
antigravity_provider_test.go fix(antigravity): normalize tool calls to avoid empty function names 2026-02-17 20:05:35 +05:30
claude_cli_provider.go fix(claude_cli): surface stdout in error when CLI exits non-zero 2026-03-12 22:01:56 -04:00
claude_cli_provider_integration_test.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
claude_cli_provider_test.go remove wrapper methods 2026-03-01 18:24:11 +11:00
claude_provider.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
claude_provider_test.go feat(fmt): Fix formatting 2026-02-20 20:03:11 +02:00
codex_cli_credentials.go refactor: centralize environment variable key constants (#1730) 2026-03-18 18:03:24 +08:00
codex_cli_credentials_test.go enable dogsled 2026-02-25 21:14:19 +11:00
codex_cli_provider.go remove wrapper methods 2026-03-01 18:24:11 +11:00
codex_cli_provider_integration_test.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
codex_cli_provider_test.go refactor: update model name and add VolcEngine coding plan (#1412) 2026-03-12 16:10:29 +08:00
codex_provider.go Add model-native search (prefer_native) for OpenAI/Codex (#1618) 2026-03-18 11:55:30 +08:00
codex_provider_test.go Add model-native search (prefer_native) for OpenAI/Codex (#1618) 2026-03-18 11:55:30 +08:00
cooldown.go style: fix gofmt formatting in cooldown files 2026-02-13 12:26:44 -03:00
cooldown_test.go refactor(modernize): apply safe modernize fixes 2026-02-27 16:35:07 +08:00
error_classifier.go fix(pkg):do regex precompile insteadd on the fly (#911) 2026-03-01 23:06:31 +11:00
error_classifier_test.go fix(pkg):do regex precompile insteadd on the fly (#911) 2026-03-01 23:06:31 +11:00
factory.go feat(providers): add LongCat model provider support (#1317) 2026-03-12 02:34:42 +08:00
factory_provider.go feat: Add Novita provider support (#1677) 2026-03-18 18:29:27 +08:00
factory_provider_test.go feat: Add Novita provider support (#1677) 2026-03-18 18:29:27 +08:00
factory_test.go feat(providers): add LongCat model provider support (#1317) 2026-03-12 02:34:42 +08:00
fallback.go feat(config): support multiple API keys for failover (#1707) 2026-03-19 00:57:20 +08:00
fallback_multikey_test.go feat(config): support multiple API keys for failover (#1707) 2026-03-19 00:57:20 +08:00
fallback_test.go feat(config): support multiple API keys for failover (#1707) 2026-03-19 00:57:20 +08:00
github_copilot_provider.go fix: improve error handling in GitHub Copilot provider (#919) 2026-03-01 22:58:41 +11:00
http_provider.go Add model-native search (prefer_native) for OpenAI/Codex (#1618) 2026-03-18 11:55:30 +08:00
legacy_provider.go fix:Openrouter in providers and modellist 2026-02-25 14:44:49 +08:00
model_ref.go feat: add model fallback chain with error classification 2026-02-13 12:12:12 -03:00
model_ref_test.go feat: add model fallback chain with error classification 2026-02-13 12:12:12 -03:00
tool_call_extract.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
toolcall_utils.go enable dupl check 2026-03-01 18:17:32 +11:00
types.go Add model-native search (prefer_native) for OpenAI/Codex (#1618) 2026-03-18 11:55:30 +08:00