[model-pricing] LiteLLM pricing fetch failed [model-pricing] OpenRouter pricing ...
错误信息
[model-pricing] LiteLLM pricing fetch failed
[model-pricing] OpenRouter pricing fetch failed
AI 解决方案
报错分析报告
1.错误翻译
原文:[model-pricing] LiteLLM pricing fetch failed
译文:[模型定价] LiteLLM 定价获取失败
原文:[model-pricing] OpenRouter pricing fetch failed
译文:[模型定价] OpenRouter 定价获取失败
2. 原因分析
3. 解决方案
import requests
import os
from tenacity import retry, stop_after_attempt, wait_exponential
@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
def fetch_provider_pricing(provider):
api_urls = {
"litellm": "https://api.litellm.com/pricing",
"openrouter": "https://openrouter.ai/api/v1/pricing"
}
headers = {"Authorization": f"Bearer {os.getenv(f'{provider.upper()}_API_KEY')}"}
response = requests.get(api_urls[provider], headers=headers, timeout=10)
response.raise_for_status()
return response.json()
# 使用示例
try:
litellm_pricing = fetch_provider_pricing("litellm")
openrouter_pricing = fetch_provider_pricing("openrouter")
except requests.exceptions.RequestException as e:
print(f"定价获取失败: {e}")
# 降级到缓存数据
pricing_data = load_cached_pricing_fallback()
4.️ 预防措施
- 推荐工具:
-
tenacity:Python重试库-
requests:带超时控制的HTTP客户端 - Redis/Memcached:分布式缓存存储
分析完成 ✅ 建议优先检查网络连接和API密钥有效性。