[Feature]: Rotate through API keys
Pre-submission Checklist
- [x] I have searched existing issues and discussions
- [x] I have read the documentation
- [x] This is a feature request, not a bug report
Problem Statement
This is for people hitting token usage limits but having multiple API keys for a provider.
Proposed Solution
I want to be able to add multiple API keys from one provider and then have CLIO switch seamlessly rotate through them, in case resources get exhausted. Mainly using Gemma-27b for now which is free within limits like 15k token per minute / 15k requests a day.
Ideally, all those keys would show up in /api show, and if you're at it, maybe you can make it an overview of all providers where API keys were entered, making it a complete overview.
Which area would this affect?
API / Provider Integration
Alternatives Considered
No response
Examples / References
No response
Would you be willing to contribute?
None
Additional Context
No response
Automated Triage Summary
| Field | Value |
|---|---|
| Classification | enhancement |
| Priority | medium |
| Completeness | 95% |
Analysis: Feature request: allow CLIO to rotate through multiple API keys for a provider. Investigation shows Config.pm already supports storing multiple per-provider keys (api_keys hash with set_provider_key/get_provider_key/list_provider_keys). However, the runtime only uses a single active key: APIManager retrieves the single current api_key (config->get('api_key')) and _get_endpoint_config_for_provider resolves only one provider key. There is no rotation/fallback logic when a key hits rate limits or auth errors. ResponseHandler parses rate-limit headers and Broker coordinates rate-limit state, which provide natural integration points for a rotation policy. Implementation plan (not requested from reporter): add key-rotation policy in APIManager (or a dedicated key manager) that uses Config::list_provider_keys, update /api show to list stored keys per provider, and trigger rotation on 401/403/429 or when ResponseHandler signals rate_limit. Ready for review and assignment to fewtarius.
Root Cause Analysis
Confidence: high
Relevant files:
lib/CLIO/Core/Config.pmlib/CLIO/Core/APIManager.pmlib/CLIO/UI/Commands/API.pmlib/CLIO/Core/API/ResponseHandler.pmlib/CLIO/Coordination/Broker.pm
Relevant functions:
CLIO::Core::Config::set_provider_keyCLIO::Core::Config::get_provider_keyCLIO::Core::Config::list_provider_keysCLIO::Core::APIManager::_get_api_keyCLIO::Core::APIManager::_get_endpoint_config_for_providerCLIO::UI::Commands::API::_display_api_configCLIO::Core::API::ResponseHandler::process_rate_limit_headersCLIO::Coordination::Broker (rate limit status handlers)
The codebase already stores per-provider keys in a map (Config.pm: the api_keys hash, with helpers get_provider_key / set_provider_key / list_provider_keys), but API usage and the UI are implemented around a single active key. APIManager->_get_api_key and other runtime paths use the single current 'api_key' (from config->get('api_key')) for requests; cross-provider helper _get_endpoint_config_for_provider resolves a single provider key via get_provider_key($provider_name) and sets auth headers from that single key. There is no code that iterates, rotates, or falls back through multiple keys for a single provider when rate limits or auth failures occur. The ResponseHandler already parses rate-limit headers and Broker coordinates rate-limit state, so integration points exist, but no rotation implementation is present. Consequently, the requested feature (rotate/round-robin through multiple API keys for one provider) is feasible with the existing storage structure but requires adding rotation logic in APIManager (and possibly a policy/strategy), exposing list_provider_keys in the CLI output (/api show) and adding runtime behavior to refresh/switch keys on auth/429/rate-limit events. Confidence: high
Affected Areas
- API key storage and retrieval (Config)
- API request orchestration (APIManager)
- CLI UI for /api show and /api set (UI Commands)
- Rate-limit handling (ResponseHandler)
- Multi-agent coordination of rate limits (Broker)
This is an automated analysis. A maintainer will review shortly.
This is interesting, let me think about how to implement it - it probably won't land right away.
I've spent some time thinking about this, and I don't think we'll implement it as it could be used as a method to circumvent provider limits.