← Back to Skills Marketplace
Api Consumption Optimizer
by
GarfieldQin
· GitHub ↗
· v1.0.0
· MIT-0
99
Downloads
0
Stars
1
Active Installs
1
Versions
Install in OpenClaw
/install api-consumption-optimizer
Description
Dynamically adjusts API call frequency based on remaining quota and time to maximize usage without exceeding limits.
README (SKILL.md)
API 消耗优化器 Skill
功能
根据 API 剩余调用次数动态调整消耗策略,最大化利用 API 额度。
触发场景
- 需要智能消耗 API 调用次数时
- 需要根据剩余次数和时间动态调整调用频率时
输入参数
{
"current_usage": "当前已使用次数",
"time_window": "时间窗口(如10:00-15:00)",
"total_quota": "总配额(默认1600)",
"target_usage": "目标消耗比例(默认0.9,即90%)"
}
核心逻辑
1. 计算重置时间
def get_reset_time(time_window):
"""从时间窗口计算下次重置时间"""
start_hour = int(time_window.split('-')[0])
now = datetime.now()
# 下次重置时间
if now.hour >= start_hour:
next_reset = now.replace(hour=start_hour) + timedelta(hours=5)
else:
next_reset = now.replace(hour=start_hour)
return next_reset
2. 计算消耗策略
def calculate_consumption_strategy(current_usage, total_quota, time_until_reset):
"""
根据剩余次数和时间计算最佳消耗策略
策略:
- 剩余>50%: 保守消耗,保持一定调用
- 剩余20-50%: 正常消耗
- 剩余\x3C20%: 冲刺消耗,最大化调用
- 最后10%时间: 疯狂消耗模式
"""
remaining = total_quota - current_usage
remaining_ratio = remaining / total_quota
# 剩余时间比例
time_ratio = time_until_reset / (5 * 3600) # 5小时
if time_ratio \x3C 0.1: # 最后10%时间
# 疯狂模式 - 每分钟调用
return {"mode": "crazy", "interval_seconds": 60}
elif remaining_ratio \x3C 0.2: # 剩余\x3C20%
# 冲刺模式 - 每3分钟调用
return {"mode": "sprint", "interval_seconds": 180}
elif remaining_ratio \x3C 0.5: # 剩余\x3C50%
# 正常模式 - 每10分钟调用
return {"mode": "normal", "interval_seconds": 600}
else:
# 保守模式 - 每30分钟调用
return {"mode": "conservative", "interval_seconds": 1800}
3. 动态调整
def adjust_strategy(current_usage, total_quota, elapsed_time):
"""
实时调整策略
如果当前消耗速度过快/过慢,动态调整
"""
expected_usage = (elapsed_time / (5*3600)) * total_quota
speed_ratio = current_usage / max(expected_usage, 1)
if speed_ratio \x3C 0.5:
# 消耗太慢,加快
return {"action": "increase_frequency", "factor": 2}
elif speed_ratio > 1.5:
# 消耗太快,减缓
return {"action": "decrease_frequency", "factor": 0.5}
else:
return {"action": "maintain"}
使用示例
Python 调用
from api_consumption_optimizer import (
get_reset_time,
calculate_consumption_strategy,
adjust_strategy
)
from datetime import datetime, timedelta
# 获取重置时间
time_window = "10:00-15:00" # 从MiniMax状态获取
reset_time = get_reset_time(time_window)
# 计算当前剩余
current_usage = 800 # 从API获取
total_quota = 1600
time_until_reset = (reset_time - datetime.now()).total_seconds()
# 获取最佳策略
strategy = calculate_consumption_strategy(
current_usage,
total_quota,
time_until_reset
)
print(f"当前模式: {strategy['mode']}")
print(f"调用间隔: {strategy['interval_seconds']}秒")
# 启动智能消耗
while True:
time.sleep(strategy['interval_seconds'])
do_api_call()
# 每次调用后重新计算
current_usage += 1
strategy = calculate_consumption_strategy(...)
与游戏系统集成
def intelligent_ai_consumer():
"""游戏AI智能消耗器"""
while True:
# 获取当前用量
status = get_minimax_status()
current_usage = status['today_usage']
# 获取重置时间
time_window = status['time_window']
reset_time = get_reset_time(time_window)
# 计算策略
strategy = calculate_consumption_strategy(
current_usage=current_usage,
total_quota=1600,
time_until_reset=(reset_time - datetime.now()).seconds
)
# 执行AI调用
do_game_ai_call()
# 根据策略等待
time.sleep(strategy['interval_seconds'])
优势
- 自适应: 根据实际剩余次数动态调整
- 最大化: 确保在重置前尽可能消耗
- 不过度: 不会一次性耗尽,留有余地
- 可预测: 用户可以预估消耗速度
注意事项
- 需要配合 MiniMax 状态查询使用
- 重置周期默认5小时,可配置
- 建议保留10%缓冲避免突发需求
Usage Guidance
Before installing, be aware this skill executes a hardcoded local binary (/home/garfield/.local/bin/minimax-status-clean) to obtain usage info. That binary will run with the agent's user privileges and could perform any local action — the skill does not declare this dependency or provide a configurable path. If you need this functionality: (1) review the target binary's source and behavior or replace it with a trusted, documented status endpoint; (2) request/modify the skill to accept a configurable path or API call instead of a hardcoded /home/... path; (3) run the skill in a restricted/sandboxed environment first; (4) add explicit checks and rate limits to avoid runaway loops. If you cannot verify the local CLI, do not install or run this skill on sensitive systems.
Capability Analysis
Type: OpenClaw Skill
Name: api-consumption-optimizer
Version: 1.0.0
The skill is designed to optimize API usage by dynamically adjusting request intervals based on remaining quotas. However, the file `api_consumption_optimizer.py` contains a hardcoded call to an external binary located at `/home/garfield/.local/bin/minimax-status-clean` using `subprocess.run`. While this capability is plausibly needed to retrieve API status as described in the documentation, the reliance on a specific local file path and the execution of unverified external processes represent risky behaviors and potential vulnerabilities, although no clear evidence of malicious intent or data exfiltration was found.
Capability Assessment
Purpose & Capability
The skill's stated goal (dynamically adjusting API call frequency) is consistent with the provided logic and examples. However, the runtime code depends on a local MiniMax status CLI at a hardcoded user path (/home/garfield/.local/bin/minimax-status-clean) while the registry metadata and SKILL.md declare no required binaries or config — a mismatch that should have been declared.
Instruction Scope
SKILL.md describes obtaining MiniMax status but does not document the local CLI call. The Python code uses subprocess.run to execute a binary at a fixed filesystem location; that effectively gives the skill permission to run arbitrary local code (whatever that binary does). The instructions also include endless loops that call do_api_call/do_game_ai_call without safeguards; the runtime could cause high-frequency actions if misconfigured.
Install Mechanism
There is no install spec (instruction-only), so nothing will be automatically downloaded or written during install. That lowers supply-chain risk, but means the code expects existing local tooling which isn't documented.
Credentials
The skill declares no required environment variables or credentials, which is reasonable. But the code relies on a user-specific filesystem path for an external CLI and implicitly expects access to run it — this implicit requirement (and the ability to execute it) is not reflected in the declared environment/dependencies and expands the effective privileges without notification.
Persistence & Privilege
The skill is not always-enabled and uses normal autonomous-invocation defaults. It does not request to modify other skills or system-wide settings. No elevated persistence is requested.
How to Use
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install api-consumption-optimizer - After installation, invoke the skill by name or use
/api-consumption-optimizer - Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
API 消耗优化器 Skill 1.0.0 – 首次发布
- 支持根据API剩余调用次数和时间窗口动态调整消耗策略
- 提供四种消耗模式:保守、正常、冲刺、疯狂
- 实现策略自动调整:根据用量和时间比率调整调用频率
- 可集成Python脚本或游戏系统,智能消耗API额度
- 支持自适应,最大化配额利用并留有安全缓冲
Metadata
Frequently Asked Questions
What is Api Consumption Optimizer?
Dynamically adjusts API call frequency based on remaining quota and time to maximize usage without exceeding limits. It is an AI Agent Skill for Claude Code / OpenClaw, with 99 downloads so far.
How do I install Api Consumption Optimizer?
Run "/install api-consumption-optimizer" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is Api Consumption Optimizer free?
Yes, Api Consumption Optimizer is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does Api Consumption Optimizer support?
Api Consumption Optimizer is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created Api Consumption Optimizer?
It is built and maintained by GarfieldQin (@qinthqod); the current version is v1.0.0.
More Skills