A Simple and Universal Swarm Intelligence Engine, Predicting Anything. 简洁通用的群体智能引擎,预测万物
Python agent-memoryfinancial-forecastingfuture-predictionknowledge-graphllmsmulti-agent-simulationpublic-opinion-analysispython3social-predictionswarm-intelligence
Add balance check script for OpenRouter API
666ghj2df31048405b
diff --git "a/\344\275\231\351\242\235\346\237\245\350\257\242.py" "b/\344\275\231\351\242\235\346\237\245\350\257\242.py"new file mode 100644index 00000000..78f28747--- /dev/null+++ "b/\344\275\231\351\242\235\346\237\245\350\257\242.py"@@ -0,0 +1,36 @@+import requests++def check_openrouter_balance(api_key):+ url = "https://openrouter.ai/api/v1/credits"++ headers = {+ "Authorization": f"Bearer {api_key}",+ "Referer": "https://your-site.com",+ "X-Title": "Balance Check Script"+ }++ try:+ response = requests.get(url, headers=headers)+ response.raise_for_status() # 检查请求是否成功++ data = response.json().get("data", {})++ total_credits = data.get("total_credits", 0) # 总充值/赠送金额+ total_usage = data.get("total_usage", 0) # 总消耗金额++ # 计算剩余余额+ balance = total_credits - total_usage++ print(f"💰 总额度 (Total Credits): ${total_credits}")+ print(f"📉 已使用 (Total Usage): ${total_usage}")+ print(f"💵 剩余余额 (Balance): ${balance:.4f}")++ return balance++ except requests.exceptions.RequestException as e:+ print(f"查询失败: {e}")+ return None++# 替换你的 API Key+MY_API_KEY = ""+check_openrouter_balance(MY_API_KEY)\ No newline at end of file