← 返回 Skills 市场
qinthqod

Api Consumption Optimizer

作者 GarfieldQin · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ suspicious
99
总下载
0
收藏
1
当前安装
1
版本数
在 OpenClaw 中安装
/install api-consumption-optimizer
功能描述
Dynamically adjusts API call frequency based on remaining quota and time to maximize usage without exceeding limits.
使用说明 (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'])

优势

  1. 自适应: 根据实际剩余次数动态调整
  2. 最大化: 确保在重置前尽可能消耗
  3. 不过度: 不会一次性耗尽,留有余地
  4. 可预测: 用户可以预估消耗速度

注意事项

  • 需要配合 MiniMax 状态查询使用
  • 重置周期默认5小时,可配置
  • 建议保留10%缓冲避免突发需求
安全使用建议
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.
功能分析
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.
能力评估
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.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install api-consumption-optimizer
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /api-consumption-optimizer 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
API 消耗优化器 Skill 1.0.0 – 首次发布 - 支持根据API剩余调用次数和时间窗口动态调整消耗策略 - 提供四种消耗模式:保守、正常、冲刺、疯狂 - 实现策略自动调整:根据用量和时间比率调整调用频率 - 可集成Python脚本或游戏系统,智能消耗API额度 - 支持自适应,最大化配额利用并留有安全缓冲
元数据
Slug api-consumption-optimizer
版本 1.0.0
许可证 MIT-0
累计安装 1
当前安装数 1
历史版本数 1
常见问题

Api Consumption Optimizer 是什么?

Dynamically adjusts API call frequency based on remaining quota and time to maximize usage without exceeding limits. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 99 次。

如何安装 Api Consumption Optimizer?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install api-consumption-optimizer」即可一键安装,无需额外配置。

Api Consumption Optimizer 是免费的吗?

是的,Api Consumption Optimizer 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Api Consumption Optimizer 支持哪些平台?

Api Consumption Optimizer 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Api Consumption Optimizer?

由 GarfieldQin(@qinthqod)开发并维护,当前版本 v1.0.0。

💬 留言讨论