":"You need positive balance to do inference. Please add balance manually or set...
错误信息
Failed to get response: 402 {"detail":{"error":"You need positive balance to do inference. Please add balance manually or setup top-up"}}
AI 解决方案
报错分析报告
1.错误翻译
原文:You need positive balance to do inference. Please add balance manually or setup top-up
译文:您需要正余额才能进行推理操作,请手动添加余额或设置自动充值。
2. 原因分析
3.解决方案
#### 操作步骤
#### 代码示例(余额检查逻辑)
import requests
def safe_inference(api_key: str, input_data: dict):
# 1. 检查余额(示例接口,以实际文档为准)
balance_res = requests.get(
"https://api.dmxapi.com/v1/balance",
headers={"Authorization": f"Bearer {api_key}"}
)
if balance_res.json()["balance"] <= 0:
raise ValueError("余额不足!请先充值或设置自动续费")
# 2. 执行推理
infer_res = requests.post(
"https://api.dmxapi.com/v1/inference",
headers={"Authorization": f"Bearer {api_key}"},
json={"input": input_data}
)
return infer_res.json()
4. 预防措施
cron定时任务监控余额。