⚠️ Agent failed before reply: All models failed (3): dmxapi/MiniMax-M2.5-free: 5...
错误信息
⚠️ Agent failed before reply: All models failed (3): dmxapi/MiniMax-M2.5-free: 503 所有令牌分组
AI 解决方案
报错分析报告
1.错误翻译
原文:All models failed (3): dmxapi/MiniMax-M2.5-free: 503
译文:所有模型均失败(3次):dmxapi/MiniMax-M2.5-free:503
2. 原因分析
dmxapi/MiniMax-M2.5-free模型时,服务返回503错误(服务不可用)。3.解决方案
import requests
import time
def call_dmxapi_model(api_key: str, model: str, prompt: str, retries: int = 3) -> dict:
url = "https://api.dmxapi.com/v1/chat/completions"
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
payload = {"model": model, "messages": [{"role": "user", "content": prompt}]}
for i in range(retries):
try:
resp = requests.post(url, headers=headers, json=payload, timeout=10)
resp.raise_for_status() # 抛出HTTP错误
return resp.json()
except requests.exceptions.HTTPError as e:
if e.response.status_code == 503 and i < retries - 1:
time.sleep(2 ** i) # 指数退避重试
continue
raise Exception(f"模型调用失败 [{e.response.status_code}]: {e.response.text}")
except Exception as e:
raise Exception(f"请求异常: {str(e)}")
# 使用示例(替换为可用模型/检查令牌)
try:
result = call_dmxapi_model(
api_key="YOUR_API_KEY",
model="dmxapi/alternative-available-model", # 切换至可用模型
prompt="你的输入内容"
)
except Exception as e:
print(f"错误: {e}")
4. 预防措施
/v1/billing/usage接口检查令牌配额,避免耗尽。Postman预测试模型接口可用性,或用Prometheus监控API错误率。注:若令牌确实耗尽,需登录DMXAPI控制台充值或升级套餐。