How LiteLLM Proxy Exposes a Unified OpenAI-Compatible Endpoint
The LiteLLM proxy server runs an HTTP service (typically on port 4000) that accepts OpenAI-formatted requests (such as /v1/chat/completions, /v1/embeddings, and /v1/responses) and translates them into the schema each upstream provider expects.
Your client code only points to one base_url and one proxy key, while config.yaml maps public model_name aliases to provider-prefixed upstream models (provider/model-id):
- Provider-prefixed routing: Prefixing upstream models (such as
openai/...,anthropic/...,gemini/...,bedrock/...,azure/...,hosted_vllm/...) tells LiteLLM which adapter and credential format to use. - Shared aliases for routing & fallbacks: Listing multiple deployments under the same
model_nameletsrouter_settingsload-balance or fail over across providers or regions automatically. - Parameter normalization: Enabling
drop_params: trueunderlitellm_settingsstrips parameters that a specific target model does not support instead of failing the request. - Secret resolution from environment: Using
os.environ/VAR_NAMEinconfig.yamlkeeps API keys out of version control and pulls them from your environment or secret manager at startup.
Steps to Configure and Run LiteLLM Proxy
- Install the proxy package: Install LiteLLM with proxy dependencies (
pip install 'litellm[proxy]'oruv tool install 'litellm[proxy]'). - Define
model_list, routing, and proxy auth inconfig.yaml: Mapmodel_nameentries tolitellm_params(model,api_key,api_base, etc.), setrouter_settings, and protect the proxy withgeneral_settings.master_key. - Export provider and master API keys: Set
OPENAI_API_KEY,ANTHROPIC_API_KEY,GEMINI_API_KEY, andLITELLM_MASTER_KEYin your environment. - Start the proxy server: Run
litellm --config config.yaml --port 4000. - Point OpenAI SDKs to the proxy URL: Set
base_url="http://localhost:4000/v1"(orhttp://localhost:4000) and pass your proxy key.
Example config.yaml and Client Call
model_list:
# Primary alias with OpenAI + Anthropic fallback under the same model_name
- model_name: default-chat
litellm_params:
model: openai/gpt-4o-mini
api_key: os.environ/OPENAI_API_KEY
- model_name: default-chat
litellm_params:
model: anthropic/claude-sonnet-4-6
api_key: os.environ/ANTHROPIC_API_KEY
# Direct provider aliases
- model_name: gemini-flash
litellm_params:
model: gemini/gemini-2.5-flash
api_key: os.environ/GEMINI_API_KEY
# Self-hosted OpenAI-compatible endpoint (e.g., vLLM)
- model_name: local-vllm
litellm_params:
model: hosted_vllm/Qwen/Qwen2.5-Coder-32B-Instruct
api_base: http://localhost:8000/v1
api_key: os.environ/VLLM_API_KEY
router_settings:
routing_strategy: simple-shuffle
fallbacks:
- default-chat: ["gemini-flash"]
litellm_settings:
drop_params: true
general_settings:
master_key: os.environ/LITELLM_MASTER_KEY
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "http://localhost:4000/v1",
apiKey: process.env.LITELLM_MASTER_KEY,
});
const res = await client.chat.completions.create({
model: "default-chat",
messages: [{ role: "user", content: "Reply with OK and the model you are." }],
});
console.log(res.model, res.choices[0]?.message?.content);
Helpful Tips for Multi-Provider Proxies
- Add
/v1to custom OpenAI-compatibleapi_baseURLs: When pointing to self-hosted or third-party OpenAI-compatible servers, include/v1inapi_baseif the upstream expects/v1/chat/completions. - Add Redis and Postgres for multi-replica scale: Running multiple proxy instances behind a load balancer uses Postgres for keys/spend logs and Redis so rate limits and budgets stay consistent across replicas.
- Test fallbacks with simulated failures: Verify that your
model_namealiases and fallback lists behave as expected when an upstream provider times out or returns503/429before putting traffic through the gateway.
You must log in or register to comment.
