360 Secure SkillHub
360 安全技能中心

quota-management

为受速率或成本限制的外部 API 集成提供配额管理基础设施:三段阈值(健康、警告、临界)、配额类型配置、查看配额状态、记录用量、执行前预估可用性,并给出降级策略,供其他插件引用复用。

athola
athola
热度 62.42
最近更新 2026-08-26 21:16:39
分类:开发依赖:代码执行应用场景:API 集成 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add nm-leyline-quota-management
Metadata
name
quota-management
description
Tracks quotas, monitors thresholds, and degrades gracefully for rate-limited APIs
version
1.9.8
triggers
["quota","rate-limiting","resource-management","cost-tracking","thresholds","integrating external services that impose rate or cost limits"]
metadata
{"openclaw":{"homepage":"https://github.com/athola/claude-night-market/tree/master/plugins/leyline","emoji":"🦞"}}
source
claude-night-market
source_plugin
leyline

Night Market Skill — ported from claude-night-market/leyline. For the full experience with agents, hooks, and commands, install the Claude Code plugin.

Table of Contents

Quota Management

Overview

Patterns for tracking and enforcing resource quotas across rate-limited services. This skill provides the infrastructure that other plugins use for consistent quota handling.

When To Use

  • Building integrations with rate-limited APIs
  • Need to track usage across sessions
  • Want graceful degradation when limits approached
  • Require cost estimation before operations

When NOT To Use

  • Project doesn't use the leyline infrastructure patterns
  • Simple scripts without service architecture needs

Core Concepts

Quota Thresholds

Three-tier threshold system for proactive management:

Level Usage Action
Healthy <80% Proceed normally
Warning 80-95% Alert, consider batching
Critical >95% Defer non-urgent, use secondary services

Quota Types

@dataclass
class QuotaConfig:
    requests_per_minute: int = 60
    requests_per_day: int = 1000
    tokens_per_minute: int = 100000
    tokens_per_day: int = 1000000

Quick Start

Check Quota Status

from leyline.quota_tracker import QuotaTracker

tracker = QuotaTracker(service="my-service")
status, warnings = tracker.get_quota_status()

if status == "CRITICAL":
    # Defer or use secondary service
    pass

Record Usage

tracker.record_request(
    tokens=estimated_tokens,
    success=True,
    duration=elapsed_seconds
)

Estimate Before Execution

can_proceed, issues = tracker.can_handle_task(estimated_tokens)
if not can_proceed:
    print(f"Quota issues: {issues}")

Integration Pattern

Other plugins reference this skill:

# In your skill's frontmatter
dependencies: [leyline:quota-management]

Then use the shared patterns:

  1. Initialize tracker for your service
  2. Check quota before operations
  3. Record usage after operations
  4. Handle threshold warnings gracefully

Detailed Resources

  • Threshold Strategies: See modules/threshold-strategies.md for degradation patterns
  • Estimation Patterns: See modules/estimation-patterns.md for token/cost estimation

Exit Criteria

  • Quota status checked before operation
  • Usage recorded after operation
  • Threshold warnings handled appropriately