Skip to content

Commit a9d6459

Browse files
refactor: remove support for direct api keys
1 parent ecbfec1 commit a9d6459

66 files changed

Lines changed: 235 additions & 1248 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/configs/withpostgresmcpclientsinconfig/config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"$schema": "https://www.getbifrost.ai/schema",
33
"client": {
4-
"allow_direct_keys": false,
54
"allowed_origins": [
65
"*"
76
],

core/bifrost.go

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5795,7 +5795,7 @@ func (bifrost *Bifrost) requestWorker(provider schemas.Provider, config *schemas
57955795
if len(supportedKeys) == 0 {
57965796
// SkipKeySelection path — keyProvider stays nil, zero Key is used.
57975797
} else if !canRotate {
5798-
// Fixed key (DirectKey, explicit ID/name, session stickiness): always
5798+
// Fixed key (explicit ID/name, session stickiness): always
57995799
// return the same key regardless of usedKeyIDs.
58005800
fixedKey := supportedKeys[0]
58015801
keyProvider = func(_ map[string]bool) (schemas.Key, error) {
@@ -7145,18 +7145,6 @@ func (bifrost *Bifrost) releaseMCPRequest(req *schemas.BifrostMCPRequest) {
71457145
// getAllSupportedKeys retrieves all valid keys for a ListModels request.
71467146
// allowing the provider to aggregate results from multiple keys.
71477147
func (bifrost *Bifrost) getAllSupportedKeys(ctx *schemas.BifrostContext, providerKey schemas.ModelProvider, baseProviderType schemas.ModelProvider) ([]schemas.Key, error) {
7148-
// Check if key has been set in the context explicitly
7149-
if ctx != nil {
7150-
key, ok := ctx.Value(schemas.BifrostContextKeyDirectKey).(schemas.Key)
7151-
if ok {
7152-
if err := validateKey(baseProviderType, &key); err != nil {
7153-
return nil, fmt.Errorf("invalid direct key for provider %v: %w", baseProviderType, err)
7154-
}
7155-
// If a direct key is specified, return it as a single-element slice
7156-
return []schemas.Key{key}, nil
7157-
}
7158-
}
7159-
71607148
keys, err := bifrost.account.GetKeysForProvider(ctx, providerKey)
71617149
if err != nil {
71627150
return nil, err
@@ -7195,18 +7183,6 @@ func (bifrost *Bifrost) getAllSupportedKeys(ctx *schemas.BifrostContext, provide
71957183
// For batch operations, only keys with UseForBatchAPI enabled are included.
71967184
// Model filtering: if model is specified and key has model restrictions, only include if model is in list.
71977185
func (bifrost *Bifrost) getKeysForBatchAndFileOps(ctx *schemas.BifrostContext, providerKey schemas.ModelProvider, baseProviderType schemas.ModelProvider, model *string, isBatchOp bool) ([]schemas.Key, error) {
7198-
// Check if key has been set in the context explicitly
7199-
if ctx != nil {
7200-
key, ok := ctx.Value(schemas.BifrostContextKeyDirectKey).(schemas.Key)
7201-
if ok {
7202-
if err := validateKey(baseProviderType, &key); err != nil {
7203-
return nil, fmt.Errorf("invalid direct key for provider %v: %w", baseProviderType, err)
7204-
}
7205-
// If a direct key is specified, return it as a single-element slice
7206-
return []schemas.Key{key}, nil
7207-
}
7208-
}
7209-
72107186
keys, err := bifrost.account.GetKeysForProvider(ctx, providerKey)
72117187
if err != nil {
72127188
return nil, err
@@ -7278,7 +7254,6 @@ func (bifrost *Bifrost) getKeysForBatchAndFileOps(ctx *schemas.BifrostContext, p
72787254
// via the keyProvider closure built by the caller.
72797255
//
72807256
// canRotate=false is returned for cases where the caller must always use the same key:
7281-
// - DirectKey (caller-supplied key bypasses all selection)
72827257
// - SkipKeySelection (provider allows keyless requests; empty slice returned)
72837258
// - Explicit BifrostContextKeyAPIKeyID / APIKeyName (user pinned a specific key)
72847259
// - Session stickiness (key persisted in KV store for the session lifetime)
@@ -7287,15 +7262,6 @@ func (bifrost *Bifrost) getKeysForBatchAndFileOps(ctx *schemas.BifrostContext, p
72877262
// canRotate=true is returned when there are two or more eligible keys and no pinning
72887263
// or stickiness constraint is in effect.
72897264
func (bifrost *Bifrost) selectKeyFromProviderForModelWithPool(ctx *schemas.BifrostContext, requestType schemas.RequestType, providerKey schemas.ModelProvider, model string, baseProviderType schemas.ModelProvider) ([]schemas.Key, bool, error) {
7290-
// DirectKey: caller supplied a key directly — no pool, no rotation.
7291-
if ctx != nil {
7292-
if key, ok := ctx.Value(schemas.BifrostContextKeyDirectKey).(schemas.Key); ok {
7293-
if err := validateKey(baseProviderType, &key); err != nil {
7294-
return nil, false, fmt.Errorf("invalid direct key for provider %v: %w", baseProviderType, err)
7295-
}
7296-
return []schemas.Key{key}, false, nil
7297-
}
7298-
}
72997265
// SkipKeySelection: provider allows keyless requests — return empty pool, no rotation.
73007266
if skipKeySelection, ok := ctx.Value(schemas.BifrostContextKeySkipKeySelection).(bool); ok && skipKeySelection && isKeySkippingAllowed(providerKey) {
73017267
return []schemas.Key{}, false, nil

core/internal/llmtests/account.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,6 @@ func replicateProviderTestKeys() []schemas.Key {
204204
}
205205
}
206206

207-
// ReplicateDirectKeyForListModels returns the key used for Replicate ListModels (deployments endpoint).
208-
// List-models tests set it on the context as schemas.BifrostContextKeyDirectKey so Bifrost passes only this key.
209-
func ReplicateDirectKeyForListModels() schemas.Key {
210-
return replicateProviderTestKeys()[0]
211-
}
212-
213207
// GetKeysForProvider returns the API keys and associated models for a given provider.
214208
func (account *ComprehensiveTestAccount) GetKeysForProvider(ctx context.Context, providerKey schemas.ModelProvider) ([]schemas.Key, error) {
215209
switch providerKey {

core/internal/llmtests/list_models.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import (
99
"github.com/maximhq/bifrost/core/schemas"
1010
)
1111

12-
// listModelsBifrostContext returns a context for ListModels. For Replicate, sets BifrostContextKeyDirectKey
13-
// so only the deployments key is used (see replicateProviderTestKeys in account.go). That key must not use an
14-
// empty Models allowlist, or ListModelsPipeline.ShouldEarlyExit returns no models before the API runs.
12+
// listModelsBifrostContext returns a context for ListModels. For Replicate, pins the deployments-endpoint
13+
// key by name (see replicateProviderTestKeys in account.go) so the test always exercises that specific key.
14+
// That key must not use an empty Models allowlist, or ListModelsPipeline.ShouldEarlyExit returns no models
15+
// before the API runs.
1516
func listModelsBifrostContext(parent context.Context, provider schemas.ModelProvider) *schemas.BifrostContext {
1617
bfCtx := schemas.NewBifrostContext(parent, schemas.NoDeadline)
1718
if provider == schemas.Replicate {
18-
bfCtx.SetValue(schemas.BifrostContextKeyDirectKey, ReplicateDirectKeyForListModels())
19+
bfCtx.SetValue(schemas.BifrostContextKeyAPIKeyName, ReplicateKeyNameListModels)
1920
}
2021
return bfCtx
2122
}

core/providers/utils/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,11 +2786,11 @@ func completeDeferredSpan(ctx *schemas.BifrostContext, result *schemas.BifrostRe
27862786

27872787
// CheckAndSetDefaultProvider checks if the default provider should be used based on the context.
27882788
// It returns the default provider if it should be used, otherwise it returns an empty string.
2789-
// Checks if the direct key is set in the context, or if key selection is skipped.
2790-
// Or if the available providers are set in the context and the default provider is in the list.
2789+
// Checks if key selection is skipped, or if the available providers are set in the context
2790+
// and the default provider is in the list.
27912791
func CheckAndSetDefaultProvider(ctx *schemas.BifrostContext, defaultProvider schemas.ModelProvider) schemas.ModelProvider {
27922792
if ctx != nil {
2793-
if ctx.Value(schemas.BifrostContextKeyDirectKey) != nil || ctx.Value(schemas.BifrostContextKeySkipKeySelection) != nil {
2793+
if ctx.Value(schemas.BifrostContextKeySkipKeySelection) != nil {
27942794
return defaultProvider
27952795
}
27962796
if ctx.Value(schemas.BifrostContextKeyAvailableProviders) != nil {

core/schemas/bifrost.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ const (
172172
BifrostContextKeyAPIKeyID BifrostContextKey = "x-bf-api-key-id" // string (explicit key ID selection, takes priority over name)
173173
BifrostContextKeyRequestID BifrostContextKey = "request-id" // string
174174
BifrostContextKeyFallbackRequestID BifrostContextKey = "fallback-request-id" // string
175-
BifrostContextKeyDirectKey BifrostContextKey = "bifrost-direct-key" // Key struct
176175

177176
// NOTE: []string is used for both keys, and by default all clients/tools are included (when nil).
178177
// If "*" is present, all clients/tools are included, and [] means no clients/tools are included.

core/schemas/context.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ var reservedKeys = []any{
1616
BifrostContextKeyAPIKeyID,
1717
BifrostContextKeyRequestID,
1818
BifrostContextKeyFallbackRequestID,
19-
BifrostContextKeyDirectKey,
2019
BifrostContextKeySelectedKeyID,
2120
BifrostContextKeySelectedKeyName,
2221
BifrostContextKeyNumberOfRetries,

docs/deployment-guides/config-json.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ A production-ready file with PostgreSQL storage, multi-provider setup, governanc
136136
"enable_logging": true,
137137
"log_retention_days": 90,
138138
"enforce_auth_on_inference": true,
139-
"allow_direct_keys": false,
140139
"allowed_origins": ["https://app.yourcompany.com"]
141140
},
142141

docs/deployment-guides/config-json/client.mdx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ These settings are also configurable via the UI (**MCP Gateway → MCP Settings*
127127
| Field | Type | Default | Description |
128128
|-------|------|---------|-------------|
129129
| `allowed_origins` | array | `["*"]` | CORS allowed origins (use URIs or `"*"`) |
130-
| `allow_direct_keys` | boolean | `false` | Allow callers to pass provider keys directly in requests |
131130
| `enforce_auth_on_inference` | boolean | `false` | Require auth (virtual key, API key, or user token) on `/v1/*` inference routes |
132131
| `max_request_body_size_mb` | integer | `100` | Maximum allowed request body size in MB |
133132
| `whitelisted_routes` | array of strings | `[]` | Routes that bypass auth middleware |
@@ -140,7 +139,6 @@ These settings are also configurable via the UI (**MCP Gateway → MCP Settings*
140139
"https://app.yourcompany.com",
141140
"https://admin.yourcompany.com"
142141
],
143-
"allow_direct_keys": false,
144142
"enforce_auth_on_inference": true,
145143
"max_request_body_size_mb": 50,
146144
"whitelisted_routes": ["/health", "/metrics"]
@@ -324,7 +322,6 @@ A top-level `auth_config` is also accepted for backwards compatibility, but `gov
324322
"mcp_external_client_url": "env.BIFROST_EXTERNAL_URL",
325323

326324
"allowed_origins": ["https://app.yourcompany.com"],
327-
"allow_direct_keys": false,
328325
"enforce_auth_on_inference": true,
329326
"max_request_body_size_mb": 100,
330327

docs/deployment-guides/config-json/schema-reference.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ Controls the worker pool, logging pipeline, security, and SDK shims. All fields
6161
| `log_retention_days` | integer | `365` | Days to retain log entries |
6262
| `logging_headers` | array | `[]` | HTTP headers to capture in log metadata |
6363
| `enforce_auth_on_inference` | boolean | `false` | Require a virtual key on every `/v1/*` request |
64-
| `allow_direct_keys` | boolean | `false` | Allow callers to pass provider API keys directly |
6564
| `allowed_origins` | array | `["*"]` | CORS allowed origins |
6665
| `max_request_body_size_mb` | integer | `100` | Maximum request body in MB |
6766
| `whitelisted_routes` | array | `[]` | Routes that bypass auth middleware |

0 commit comments

Comments
 (0)