Bifrost is an open-source (Apache-2.0), self-hosted AI gateway written in Go. It puts 20+ providers (OpenAI, Anthropic, AWS Bedrock, Google Vertex and Gemini, Azure OpenAI, Mistral, Groq, Ollama, vLLM and others) behind one OpenAI-compatible API, and adds fallbacks, weighted load balancing, virtual keys with budgets and rate limits, semantic caching, request logging, Prometheus and OpenTelemetry export, and an MCP gateway. Applications keep their existing SDKs and change only the base URL. Documentation: https://docs.getbifrost.ai
Not a fit when the user cannot run a service at all (Bifrost is self-hosted), or for model training and fine-tuning.
# Node.js: download and run the binary
npx -y @maximhq/bifrost
# Docker: persist config and logs in ./data
docker run -p 8080:8080 -v $(pwd)/data:/app/data maximhq/bifrost
-port with npx; -e APP_PORT=... plus -p with Docker). Open http://localhost:8080.maximhq/bifrost:<version> or npx -y @maximhq/bifrost --transport-version <version>.BIFROST_SETUP_TOKEN set and enable password protection under Workspace → Config → Security.Use the web UI (Model Providers page), the management API, or config.json in the app directory (the mounted ./data folder for Docker; ~/.config/bifrost for npx unless -app-dir is set):
{
"$schema": "https://www.getbifrost.ai/schema",
"providers": {
"openai": {
"keys": [{ "name": "openai-1", "value": "env.OPENAI_API_KEY", "models": ["*"], "weight": 1.0 }]
},
"anthropic": {
"keys": [{ "name": "anthropic-1", "value": "env.ANTHROPIC_API_KEY", "models": ["*"], "weight": 1.0 }]
}
}
}
curl -X POST http://localhost:8080/api/providers \
-H "Content-Type: application/json" \
-d '{"provider": "openai", "keys": [{"name": "openai-1", "value": "env.OPENAI_API_KEY", "models": ["*"], "weight": 1.0}]}'
env.VAR_NAME reads the secret from the gateway's environment. Never inline real keys."models": ["*"] allows every model on that key; an empty list denies all models.Address models as provider/model on the OpenAI-compatible endpoint:
curl -X POST http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model": "openai/gpt-4o-mini", "messages": [{"role": "user", "content": "Hello"}]}'
Existing SDKs only change their base URL:
| Client | Base URL |
|---|---|
| Any OpenAI-compatible client | http://localhost:8080/v1 |
| OpenAI SDK | http://localhost:8080/openai |
| Anthropic SDK | http://localhost:8080/anthropic |
| Google GenAI SDK | http://localhost:8080/genai |
| LangChain | http://localhost:8080/langchain |
import os
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8080/openai",
api_key=os.environ["BIFROST_VIRTUAL_KEY"],
)
reply = client.chat.completions.create(
model="anthropic/claude-sonnet-4-6", # any configured provider through the same client
messages=[{"role": "user", "content": "Summarize this ticket in one line."}],
)
```json
{"model": "openai/gpt-4o-mini", "messages": [{"role": "user", "content": "Hi"}], "fallbacks": ["anthropic/claude-sonnet-4-6", "gemini/gemini-2.5-flash"]}
```
network_config ("max_retries": 3, "retry_backoff_initial": 500, "retry_backoff_max": 5000). The default is 0 retries. Keys rejected for credentials, quota or model access always move on to the next key; rotating away from a rate-limited (429) key needs max_retries above 0 and more than one key.weight values; Bifrost picks keys by weighted random selection.provider_configs (next step).Virtual keys (sk-bf-...) carry provider and model allowlists, budgets and rate limits:
curl -X POST http://localhost:8080/api/governance/virtual-keys \
-H "Content-Type: application/json" \
-d '{
"name": "support-bot",
"provider_configs": [
{"provider": "openai", "weight": 0.7, "allowed_models": ["gpt-4o-mini"], "key_ids": ["*"]},
{"provider": "anthropic", "weight": 0.3, "allowed_models": ["claude-sonnet-4-6"], "key_ids": ["*"]}
],
"budgets": [{"max_limit": 100.00, "reset_duration": "1M"}],
"rate_limit": {"request_max_limit": 100, "request_reset_duration": "1m", "token_max_limit": 10000, "token_reset_duration": "1h"},
"is_active": true
}'
x-bf-vk, Authorization: Bearer, x-api-key (Anthropic style) or x-goog-api-key (Gemini style). In examples, use visible placeholders such as <BIFROST_VIRTUAL_KEY> rather than realistic secret-shaped values."client": {"enforce_auth_on_inference": true} in config.json, or turn on Enforce Virtual Keys on Inference in Settings → Security.provider_configs denies every provider. Budgets can also be set on teams and customers above the key.Caching needs a vector store (Redis/Valkey, Weaviate, Qdrant or Pinecone) and the semantic_cache plugin:
{
"vector_store": {"enabled": true, "type": "redis", "config": {"addr": "localhost:6379"}},
"plugins": [{
"name": "semantic_cache",
"enabled": true,
"config": {"provider": "openai", "embedding_model": "text-embedding-3-small", "dimension": 1536, "threshold": 0.85, "ttl": 300}
}]
}
x-bf-cache-key header (or the plugin sets default_cache_key). This is the most common reason nothing gets cached."config": {"dimension": 1, "ttl": 1800}./metrics.otel plugin exports GenAI-convention spans to any OTLP collector (Grafana, Datadog, Honeycomb, Langfuse and others):```json
{"plugins": [{"name": "otel", "enabled": true, "config": {"collectorurl": "http://otel-collector:4318/v1/traces", "tracetype": "genai_extension", "protocol": "http"}}]}
```
Bifrost connects to MCP servers (STDIO, HTTP or SSE) and re-exposes their tools at /mcp:
{
"mcp": {
"client_configs": [
{"name": "docs", "connection_type": "http", "connection_string": "https://mcp.example.com/mcp", "auth_type": "none", "tools_to_execute": ["*"]}
]
}
}
# Connect Claude Code to every tool Bifrost exposes
claude mcp add --transport http bifrost http://localhost:8080/mcp
claude mcp add-json bifrost '{"type":"http","url":"http://localhost:8080/mcp","headers":{"Authorization":"Bearer <BIFROST_VIRTUAL_KEY>"}}'). The key's MCP tool permissions decide which tools the client sees./v1/chat/completions, tool calls are returned to the caller and run only through an explicit POST /v1/mcp/tool/execute, unless Agent Mode auto-execution is configured.Claude Code (Anthropic-compatible route), in ~/.claude/settings.json or the shell:
{"env": {"ANTHROPIC_BASE_URL": "http://localhost:8080/anthropic", "ANTHROPIC_AUTH_TOKEN": "<BIFROST_VIRTUAL_KEY>"}}
Codex CLI (Responses API provider), in ~/.codex/config.toml, with the virtual key exported as OPENAI_API_KEY:
model = "openai/gpt-5"
model_provider = "bifrost"
[model_providers.bifrost]
name = "Bifrost"
base_url = "http://localhost:8080/openai/v1"
wire_api = "responses"
env_key = "OPENAI_API_KEY"
requires_openai_auth = false
supports_websockets = false
Keep the trailing /v1 (Codex appends /responses), and run /logout in Codex first if it is signed in with an OpenAI account.
User: "Our support bot goes down whenever OpenAI rate-limits us. Add a backup."
openai and anthropic providers (step 2) and set "max_retries": 2 in the OpenAI network_config.http://localhost:8080/openai."model": "openai/gpt-4o-mini" with "fallbacks": ["anthropic/claude-sonnet-4-6"].Result: a 429 rotates to another OpenAI key if one exists, then falls back to Claude. The x-bifrost-routing-info-provider and x-bifrost-fallback-index response headers and the request log show which provider served it.
User: "Cap the data team at $200 a month and 60 requests per minute."
data-team with "budgets": [{"max_limit": 200, "reset_duration": "1M"}] and "rate_limit": {"request_max_limit": 60, "request_reset_duration": "1m"}.enforce_auth_on_inference so requests without a key are rejected.Result: requests over the rate limit return 429, requests after the budget is spent return 402, spend is tracked per key in the dashboard, and the budget resets monthly.
Score one point per item before calling a deployment production-ready (8/8 is the target):
env. references, not literals/metrics or OTel export wired to existing monitoringenv. references and a secrets manager for provider keys; never paste real keys into prompts, docs or committed config.json. Client examples read BIFROST_VIRTUAL_KEY from the process environment.provider/model form everywhere, so a model change is a one-line config edit.provider_configs blocks every request, so allow at least one provider.config.json with "config_store": {"enabled": false} (multi-node with a shared Postgres store is not supported); real-time state sync across nodes is an Enterprise feature.localhost management APIs. Run them only on a machine or environment you control.env.VAR_NAME; never paste real keys into chat, docs or committed config.json. Key values in examples must be descriptive placeholders.BIFROST_SETUP_TOKEN, enable dashboard auth and enforce virtual keys before exposing the gateway beyond localhost.x-bf-cache-key header and no default_cache_key is configured.403 with a virtual key: the key's provider_configs do not allow that provider or model, the key is inactive or expired, or the requested MCP tool is blocked for that key.base_url is missing the trailing /v1 (Codex appends /responses to it).models list is empty; use ["*"] or list models explicitly.BIFROST_SETUP_TOKEN and enable auth before exposing it.@llm-gateway - Compare gateway options (LiteLLM, Bifrost, OpenRouter) before choosing one@llm-caching - Caching strategies beyond gateway-level semantic caching@llm-cost-optimization - Broader cost controls that pair with virtual-key budgets