LiteLLM proxy setup
Run LiteLLM as an OpenAI-compatible proxy on port 4000. Clients point baseURL at the proxy instead of calling providers directly.
Hub: Tokenminning with LiteLLM.
Minimal config.yaml
model_list:
- model_name: gpt-4o-mini
litellm_params:
model: gpt-4o-mini
api_key: os.environ/OPENAI_API_KEY
general_settings:
master_key: sk-<your-master-key>
database_url: postgresql://user:pass@localhost:5432/litellmStart the proxy:
litellm --config config.yaml --port 4000Postgres is required for budgets & spend.
Client wiring
from openai import OpenAI
client = OpenAI(
api_key="sk-<virtual-key>",
base_url="http://localhost:4000",
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello"}],
)Zed integration
Point Zed’s OpenAI-compatible provider at http://localhost:4000. See Zed local models for the full pattern.
Avoid double gateways
| Stack | Verdict |
|---|---|
| Client → LiteLLM → provider | Good — one routing layer |
| Client → LiteLLM → OpenRouter → provider | Bad — latency + double fees |
| Client → OpenRouter | Use OpenRouter guide instead |
Pick one gateway per client.
Spending guardrails
- Issue virtual keys — never distribute the master key
- Set
max_budgetat key creation - Run behind auth on shared networks — an open proxy is an open relay
- Log
x-litellm-response-costin your app middleware
Related
Last updated on