API Key Rotation Pool (proxy/keypool.go)

observer · internal/proxy/keypool.go · go · Apache-2.0
auth, security, infra, lang:go

Manages a local pool of API keys with automatic rotation based on rate-limit pressure. Use this to implement load balancing for LLM provider credentials.

// Source: https://github.com/superbasedapp/observer | License: Apache-2.0 | Copyright 2026 Gaja AI
// Provided via justclaw.it.com; keep this notice with the code.
package proxy

import (
	"crypto/subtle"
	"net/http"
	"strings"
	"sync/atomic"
)

// Multi-key rotation (§R12.4): a same-provider key pool rotated on
// rate-limit pressure — LiteLLM key-pool parity for the single node.
// The pool lives ONLY in the node's local config.toml ([routing.
// key_pool]); it is never synced, never pushed, and key material is
// never logged (rotation logs an index, nothing else). The §R11.5
// keychain-backed vault is the P3 upgrade path.
//
// Membership guard (SR27-B2): a key swaps ONLY into a request that already
// presented one of the pool's own keys - list every key the client may be
// configu

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key