litellm - ✅(Solved) Fix [Feature]: Allow loading model cost map from external path / injected JSON [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#25062Fetched 2026-04-08 02:34:51
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Author
Participants
Timeline (top)
labeled ×2commented ×1cross-referenced ×1mentioned ×1

PR fix notes

PR #25072: feat: load model cost map from LITELLM_MODEL_COST_MAP_PATH

Description (problem / solution / changelog)

relevant issues

  • Fixes #25062

Type

🆕 New Feature

Changes

  • LITELLM_MODEL_COST_MAP_PATH loads the local model cost map from a file; otherwise unchanged bundled backup.
  • Tests added.

Changed files

  • litellm/litellm_core_utils/get_model_cost_map.py (modified, +23/-7)
  • tests/llm_translation/test_model_cost_map_resilience.py (modified, +54/-0)

Code Example

@staticmethod
def load_local_model_cost_map() -> dict:
    path = os.getenv("LITELLM_MODEL_COST_MAP_PATH", "").strip()
    if path:
        with open(path, "r", encoding="utf-8") as f:
            return json.load(f)

    # existing fallback
    return json.loads(
        files("litellm")
        .joinpath("model_prices_and_context_window_backup.json")
        .read_text(encoding="utf-8")
    )
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

The Feature

LiteLLM currently loads the “local fallback” model cost map from a JSON bundled inside the Python package (via importlib.resources). In packaged/bundled deployments (e.g., PyInstaller, slim Docker images), that bundled JSON may be missing, which can break offline fallback behavior.

Proposal: support user-provided local sources for the model cost map:

  • LITELLM_MODEL_COST_MAP_PATH=/path/to/model_cost_map.json (load JSON from file)

Pseudocode

@staticmethod
def load_local_model_cost_map() -> dict:
    path = os.getenv("LITELLM_MODEL_COST_MAP_PATH", "").strip()
    if path:
        with open(path, "r", encoding="utf-8") as f:
            return json.load(f)

    # existing fallback
    return json.loads(
        files("litellm")
        .joinpath("model_prices_and_context_window_backup.json")
        .read_text(encoding="utf-8")
    )

Motivation, pitch

This is mainly for offline/firewalled and packaged environments where:

  • remote fetch (GitHub raw) is blocked/unavailable, and
  • package data files (backup JSON) may be excluded by packaging/build tooling.

Related but not duplicates:

  • #1434 (local-only mode via LITELLM_LOCAL_MODEL_COST_MAP=True) still assumes the bundled backup JSON exists.
  • #15274 (custom remote URL env var) is about remote sources, not local file injection.

This change would make LiteLLM more reliable in air-gapped deployments and bundled binaries, while keeping current default behavior unchanged.

What part of LiteLLM is this about?

SDK (litellm Python package)

LiteLLM is hiring a founding backend engineer, are you interested in joining us and shipping to all our users?

No

Twitter / LinkedIn details

No response

extent analysis

TL;DR

To support user-provided local sources for the model cost map in LiteLLM, implement a configuration option to load the model cost map from a JSON file specified by the LITELLM_MODEL_COST_MAP_PATH environment variable.

Guidance

  • Implement the proposed load_local_model_cost_map method to load the model cost map from a JSON file if the LITELLM_MODEL_COST_MAP_PATH environment variable is set.
  • Update the LiteLLM configuration to use the load_local_model_cost_map method to load the model cost map.
  • Test the implementation in offline/firewalled and packaged environments to ensure the model cost map is loaded correctly from the user-provided JSON file.
  • Consider adding error handling to handle cases where the JSON file is missing or invalid.

Example

import os
import json
from importlib import resources

class LiteLLM:
    @staticmethod
    def load_local_model_cost_map() -> dict:
        path = os.getenv("LITELLM_MODEL_COST_MAP_PATH", "").strip()
        if path:
            with open(path, "r", encoding="utf-8") as f:
                return json.load(f)

        # existing fallback
        return json.loads(
            resources.files("litellm")
            .joinpath("model_prices_and_context_window_backup.json")
            .read_text(encoding="utf-8")
        )

Notes

This implementation assumes that the LITELLM_MODEL_COST_MAP_PATH environment variable is set to the path of the JSON file containing the model cost map. The implementation also assumes that the JSON file is in the correct format and can be loaded using the json.load method.

Recommendation

Apply the proposed workaround by implementing the load_local_model_cost_map method and updating the LiteLLM configuration to use it. This will allow users to provide a local source for the model cost map, making LiteLLM more reliable in offline/firewalled and packaged environments.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - ✅(Solved) Fix [Feature]: Allow loading model cost map from external path / injected JSON [1 pull requests, 1 comments, 2 participants]