Code
Clone this repository
Search code
Latest commit
LiteLLM Price Mapper
A web server that matches the models stored in the LiteLLM database against the official LiteLLM price list (from GitHub).
On each request to /prices, the price list and the DB models are fetched
fresh and returned as JSON in the price list format. The response contains
all original models from the price list, plus the custom DB models
keyed by their backend model name.
How it works
- The price list is loaded from GitHub:
https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json - All models from the
LiteLLM_ProxyModelTabletable are read from the database. Thelitellm_paramsare decrypted with the salt key to get the real backend name. - For each custom DB model, the OpenRouter API (
/api/v1/models) is checked first. If the display name exists there, the OpenRouter data is used (converted to the LiteLLM price list format). - If the model is not found on OpenRouter, it is looked up in the LiteLLM
price list by its display name (
model_name). - The response contains all original price list entries, plus the custom DB
models keyed by their backend name (
litellm_params.model), with the price data from OpenRouter or the LiteLLM price list.
Configuration
Configuration is done via a .env file (see .env.example):
DATABASE_URL=postgresql://user:pass@postgres:5432/litellm
LITELLM_SALT_KEY=sk-...
| Variable | Description |
|---|---|
DATABASE_URL |
Connection URL to the LiteLLM database (required) |
LITELLM_SALT_KEY |
Salt key to decrypt the backend names (required for correct names) |
PRICE_LIST_URL |
Price list URL (optional, default = GitHub) |
Note:
LITELLM_SALT_KEYmust match theLITELLM_SALT_KEY/LITELLM_MASTER_KEYof your LiteLLM setup. Without it, backend names stay encrypted and cannot be matched correctly.
Endpoints
The server listens on port 8000.
| Endpoint | Description |
|---|---|
GET /prices |
Price list of the models stored in the DB (JSON) |
GET /health |
Health check |
GET /prices returns a JSON object in the price list format:
{
"gpt-4o": {
"input_cost_per_token": 2.5e-06,
"output_cost_per_token": 1e-05,
"max_input_tokens": 128000,
"max_output_tokens": 16384,
"litellm_provider": "openai",
"mode": "chat"
}
}
Run with Docker
cp .env.example .env
# adjust .env (set DATABASE_URL)
docker compose up --build -d
# server runs on http://localhost:8000
curl http://localhost:8000/prices
Run locally
cp .env.example .env
# adjust .env (set DATABASE_URL)
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python -m price_mapper