feat: configure multiple AI Bridge providers of the same type (#23948)

_Disclaimer: produced mostly by Claude Opus 4.6 following detailed
planning._

## Summary
- Support multiple instances of the same AI Bridge provider type via
indexed env vars (`CODER_AIBRIDGE_PROVIDER_<N>_<KEY>`), following the
`CODER_EXTERNAL_AUTH_<N>_<KEY>` pattern
- Existing single-provider env vars (`CODER_AIBRIDGE_OPENAI_KEY`, etc.)
continue to work unchanged
- Setting both a legacy env var and an indexed provider with the same
name errors at startup to prevent silent misconfiguration
- Mark legacy provider fields (`OpenAI`, `Anthropic`, `Bedrock`) as
deprecated in `AIBridgeConfig` in favor of `Providers`
  ## Example
```sh
CODER_AIBRIDGE_PROVIDER_0_TYPE=anthropic
CODER_AIBRIDGE_PROVIDER_0_NAME=anthropic-corp
CODER_AIBRIDGE_PROVIDER_0_KEY=sk-ant-corp-xxx

CODER_AIBRIDGE_PROVIDER_0_BASE_URL=https://llm-proxy.internal.example.com/anthropic

CODER_AIBRIDGE_PROVIDER_1_TYPE=anthropic
CODER_AIBRIDGE_PROVIDER_1_NAME=anthropic-direct
  CODER_AIBRIDGE_PROVIDER_1_KEY=sk-ant-direct-yyy         
  ```
  Each instance is routed by name:
- /api/v2/aibridge/**anthropic-corp**/v1/messages
- /api/v2/aibridge/**anthropic-direct**/v1/messages
Closes
[AIGOV-157](https://linear.app/codercom/issue/AIGOV-157/spike-to-understand-if-there-is-a-simple-way-to-handle-multi-api-key)

---------

Signed-off-by: Danny Kopping <danny@coder.com>
This commit is contained in:
Danny Kopping
2026-04-15 07:59:37 +00:00
committed by GitHub
parent 730edba87a
commit 08045c2aac
17 changed files with 1326 additions and 163 deletions
+39
View File
@@ -41,9 +41,23 @@ export interface AIBridgeBedrockConfig {
// From codersdk/deployment.go
export interface AIBridgeConfig {
readonly enabled: boolean;
/**
* Deprecated: Use Providers with indexed CODER_AIBRIDGE_PROVIDER_<N>_* env vars instead.
*/
readonly openai: AIBridgeOpenAIConfig;
/**
* Deprecated: Use Providers with indexed CODER_AIBRIDGE_PROVIDER_<N>_* env vars instead.
*/
readonly anthropic: AIBridgeAnthropicConfig;
/**
* Deprecated: Use Providers with indexed CODER_AIBRIDGE_PROVIDER_<N>_* env vars instead.
*/
readonly bedrock: AIBridgeBedrockConfig;
/**
* Providers holds provider instances populated from CODER_AIBRIDGE_PROVIDER_<N>_<KEY>
* env vars and/or the deprecated LegacyOpenAI/LegacyAnthropic/LegacyBedrock fields above.
*/
readonly providers?: readonly AIBridgeProviderConfig[];
/**
* Deprecated: Injected MCP in AI Bridge is deprecated and will be removed in a future release.
*/
@@ -109,6 +123,31 @@ export interface AIBridgeOpenAIConfig {
readonly key: string;
}
// From codersdk/deployment.go
/**
* AIBridgeProviderConfig represents a single AI Bridge provider instance,
* parsed from CODER_AIBRIDGE_PROVIDER_<N>_<KEY> environment variables.
* This follows the same indexed pattern as ExternalAuthConfig.
*/
export interface AIBridgeProviderConfig {
/**
* Type is the provider type: "openai", "anthropic", or "copilot".
*/
readonly type: string;
/**
* Name is the unique instance identifier used for routing.
* Defaults to Type if not provided.
*/
readonly name: string;
/**
* BaseURL is the base URL of the upstream provider API.
*/
readonly base_url: string;
readonly bedrock_region?: string;
readonly bedrock_model?: string;
readonly bedrock_small_fast_model?: string;
}
// From codersdk/deployment.go
export interface AIBridgeProxyConfig {
readonly enabled: boolean;