feat: add multi-key support with automatic rate-limit rotation #11
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "renekv/ocgo:feat/multi-key-rotation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Add multi-key API key support with automatic rate-limit rotation for the ocgo proxy. When an upstream request returns HTTP 429 (Too Many Requests), the proxy automatically rotates to the next API key and retries the request before returning an error to the client. Key index is persisted to
~/.config/ocgo/key-indexso the rotation state survives process restarts.Changes
Config (
cmd/ocgo/main.go— +138/-44 lines)APIKey stringAPIKey string(backward compat, omitempty) +APIKeys []stringhttp.NewRequestWithContext+client.Doin 3 proxy functionspostWithRetry()method with 429 detection and auto-rotationreadKeyIndex() % len(keys)— persisted round-robinrotateKey()increments index, writes tokey-indexfile (0600)Key Rotation Flow
postWithRetryiterates through all keys before returning 429 to callerEnvironment Variables (precedence order)
OCGO_API_KEYS— comma-separated, highest precedenceOCGO_API_KEY— single key, backward compatapi_keysarray orapi_keystringSetup Command
ocgo setupaccepts comma-separated keys via--api-keysflag or stdin prompt--api-keyflag retained as backward-compat alias--api-keys→--api-key→OCGO_API_KEYS→OCGO_API_KEY→ stdin promptBackward Compatibility
api_keyconfig field still works (treated as single-elementapi_keysarray)saveConfigwrites first key asapi_keyfor older ocgo versionsOCGO_API_KEYenv var still supportedproxyMessages,proxyChatCompletions,proxyResponses) refactored to callpostWithRetry— same behavior for non-429 responsesValidation
go vet ./cmd/ocgo/go test ./cmd/ocgo/go build -o /dev/null ./cmd/ocgo/Constraints Honored
Fixes #115
5354905c82to643efdabb6feat: add multi-key support with automatic rate-limit rotationto WIP: feat: add multi-key support with automatic rate-limit rotationWIP: feat: add multi-key support with automatic rate-limit rotationto feat: add multi-key support with automatic rate-limit rotation