gateway_config.yaml

script

← Back to skill

Content hash: 6199962e756d3d56b92e87c0b0f2eab3c8c962bdfdee876b2ea632eeb4a2900a
# LiteLLM Gateway Configuration
#
# A unified proxy for multiple LLM providers: routing, fallback, budgets, observability.
#
# Usage:
#   litellm --config gateway_config.yaml --port 4000
#   curl http://localhost:4000/v1/chat/completions -H "Authorization: Bearer sk-..." ...

general_settings:
  master_key: ${LITELLM_MASTER_KEY}
  database_url: ${DATABASE_URL}  # optional: Postgres for spend tracking

model_list:
  # ── Primary models ────────────────────────────────────────────────────
  - model_name: gpt-4o
    litellm_params:
      model: openai/gpt-4o
      api_key: ${OPENAI_API_KEY}

  - model_name: claude-sonnet
    litellm_params:
      model: anthropic/claude-3-5-sonnet-20241022
      api_key: ${ANTHROPIC_API_KEY}

  - model_name: gemini-flash
    litellm_params:
      model: gemini/gemini-1.5-flash
      api_key: ${GEMINI_API_KEY}

  # ── Cost-optimized routing alias ──────────────────────────────────────
  - model_name: cheap-first
    litellm_params:
      model: openai/gpt-4o-mini
      api_key: ${OPENAI_API_KEY}
    model_info:
      mode: chat

  - model_name: cheap-first
    litellm_params:
      model: gemini/gemini-1.5-flash
      api_key: ${GEMINI_API_KEY}
    model_info:
      mode: chat

  # ── Local models ──────────────────────────────────────────────────────
  - model_name: local-llama
    litellm_params:
      model: openai/llama-3.2-3b-instruct
      api_base: http://localhost:8000/v1
      api_key: not-needed

# ── Router settings ─────────────────────────────────────────────────────

router_settings:
  # Automatic fallback chain
  fallbacks:
    - gpt-4o: ["claude-sonnet"]
    - claude-sonnet: ["gemini-flash"]

  # Context window overflow fallback
  context_window_fallbacks:
    - gpt-4o: ["claude-sonnet"]  # Claude has larger context

  # Cost-based routing (cheapest-first among deployments of same model_name)
  routing_strategy: "usage-based-routing-v2"

  # Redis-based rate limiting (multi-instance)
  redis_host: ${REDIS_HOST}
  redis_port: ${REDIS_PORT}
  redis_password: ${REDIS_PASSWORD}

litellm_settings:
  # Drop unmapped params instead of erroring
  drop_params: true

  # Global rate limit: requests per minute
  rpm: 1000

  # Budget tracking
  success_callback: ["prometheus"]