#40741·litellm

[错误]: model_info 关键字存在,但 None 块无法生成成本映射,因此默认禁用预算预留

作者: mwill-pub创建于 2026年9月11日更新于 2026年9月29日
标签llm translation

import os os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True" import litellm from litellm.proxy._types import ModelInfo as ProxyModelInfo from litellm.proxy.proxy_server import _enrich_model_info_with_litellm_data from litellm.proxy.spend_tracking.budget_reservation import estimate_request_max_cost from litellm.router import Router BACKEND = "bedrock/eu.Anthropic.Claude-opus-5" # priced at 5.5e-06 in the built-in map BODY = {"model": "m", "messages": [{"role": "user", "content": "x " * 500}], "max_tokens": 8} for label, model_info in ( ("absent cost keys", {"id": "d1"}), ("proxy ModelInfo", ProxyModelInfo(id="d1").model_dump()), ): model = {"model_name": "m", "litellm_params": {"model": BACKEND}, "model_info": dict(model_info)} mi = _enrich_model_info_with_litellm_data(model=model, llm_router=None)["model_info"] router = Router(model_list=[{"model_name": "m", "litellm_params": {"model": BACKEND}, "model_info": dict(model_info)}]) est = estimate_request_max_cost(request_body=dict(BODY), route="/chat/completions", llm_router=router) print(label, "->", mi.get("input_cost_per_token"), "| estimate:", est) Output: proxy ModelInfo(id=...).model_dump() {'id': 'd1', 'mode': None, 'input_cost_per_token': None, 'output_cost_per_token': None, 'max_tokens': None, 'base_model': …

内容来源: BerriAI/litellm