How do you configure LiteLLM proxy server to expose an OpenAI-compatible endpoint for 100+ model providers? | A1Lab@HamzaM to AI & LLMEnglish • 4 days ago

How do you configure LiteLLM proxy server to expose an OpenAI-compatible endpoint for 100+ model providers?

message-square
0

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_name lets router_settings load-balance or fail over across providers or regions automatically.
  • Parameter normalization: Enabling drop_params: true under litellm_settings strips parameters that a specific target model does not support instead of failing the request.
  • Secret resolution from environment: Using os.environ/VAR_NAME in config.yaml keeps API keys out of version control and pulls them from your environment or secret manager at startup.

Steps to Configure and Run LiteLLM Proxy

  1. Install the proxy package: Install LiteLLM with proxy dependencies (pip install 'litellm[proxy]' or uv tool install 'litellm[proxy]').
  2. Define model_list, routing, and proxy auth in config.yaml: Map model_name entries to litellm_params (model, api_key, api_base, etc.), set router_settings, and protect the proxy with general_settings.master_key.
  3. Export provider and master API keys: Set OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY, and LITELLM_MASTER_KEY in your environment.
  4. Start the proxy server: Run litellm --config config.yaml --port 4000.
  5. Point OpenAI SDKs to the proxy URL: Set base_url="http://localhost:4000/v1" (or http://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 /v1 to custom OpenAI-compatible api_base URLs: When pointing to self-hosted or third-party OpenAI-compatible servers, include /v1 in api_base if 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_name aliases and fallback lists behave as expected when an upstream provider times out or returns 503/429 before putting traffic through the gateway.