feat: support multiple keys per AI Bridge provider (#24683)

## Description

Adds support for configuring multiple API keys per AI Bridge provider. This PR introduces the configuration parsing and validation only; wiring the key pools into the aibridge providers will happen in upstream PRs.

## Changes

Providers now accept a comma-separated list of keys via the `KEYS` env var (or a single key via the existing `KEY` var). The two are mutually exclusive. Bedrock follows the same pattern with `BEDROCK_ACCESS_KEYS` / `BEDROCK_ACCESS_KEY_SECRETS`, with an additional validation that the two slices have matching lengths.

Key validation at startup checks for empty values, duplicates, and a maximum of 5 keys per provider. 

Related to: https://github.com/coder/internal/issues/1445

> [!NOTE]
> Initially generated by Coder Agents, modified and reviewed by @ssncferreira
This commit is contained in:
Susana Ferreira
2026-04-30 09:19:32 +01:00
committed by GitHub
parent 123c8dfc02
commit 101a4082dd
5 changed files with 239 additions and 47 deletions
+15 -8
View File
@@ -4110,20 +4110,27 @@ type AIBridgeProviderConfig struct {
// Name is the unique instance identifier used for routing.
// Defaults to Type if not provided.
Name string `json:"name"`
// Key is the API key for authenticating with the upstream provider.
Key string `json:"-"`
// Keys holds one or more API keys for authenticating with the
// upstream provider. When multiple keys are configured, they
// form a key pool for automatic failover.
Keys []string `json:"-"`
// BaseURL is the base URL of the upstream provider API.
BaseURL string `json:"base_url"`
// DumpDir is the directory path for dumping API requests and responses.
DumpDir string `json:"dump_dir,omitempty"`
// Bedrock fields (only applicable when Type == "anthropic").
BedrockBaseURL string `json:"-"`
BedrockRegion string `json:"bedrock_region,omitempty"`
BedrockAccessKey string `json:"-"`
BedrockAccessKeySecret string `json:"-"`
BedrockModel string `json:"bedrock_model,omitempty"`
BedrockSmallFastModel string `json:"bedrock_small_fast_model,omitempty"`
BedrockBaseURL string `json:"-"`
BedrockRegion string `json:"bedrock_region,omitempty"`
// BedrockAccessKeys and BedrockAccessKeySecrets hold one or
// more AWS credential pairs for authenticating with Bedrock.
// When multiple pairs are configured, they form a key pool
// for automatic failover. The two slices must have the same
// length.
BedrockAccessKeys []string `json:"-"`
BedrockAccessKeySecrets []string `json:"-"`
BedrockModel string `json:"bedrock_model,omitempty"`
BedrockSmallFastModel string `json:"bedrock_small_fast_model,omitempty"`
}
type AIBridgeProxyConfig struct {