Get the FREE Ultimate OpenClaw Setup Guide →

quota-management

npx machina-cli add skill athola/claude-night-market/quota-management --openclaw
Files (1)
SKILL.md
3.7 KB

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:

LevelUsageAction
Healthy<80%Proceed normally
Warning80-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

Troubleshooting

Common Issues

Command not found Ensure all dependencies are installed and in PATH

Permission errors Check file permissions and run with appropriate privileges

Unexpected behavior Enable verbose logging with --verbose flag

Source

git clone https://github.com/athola/claude-night-market/blob/master/plugins/leyline/skills/quota-management/SKILL.mdView on GitHub

Overview

Quota management patterns track quotas across rate-limited services and provide infrastructure for consistent quota handling. It enables threshold monitoring, usage estimation, and graceful degradation so integrations stay reliable under pressure.

How This Skill Works

The skill uses a shared QuotaTracker per service to monitor usage and enforce limits. It defines three-tier thresholds (Healthy, Warning, Critical) and exposes APIs like get_quota_status, can_handle_task, and record_request to guide execution and logging. Integration patterns show how to wire the tracker into calls, check quotas before operations, and handle threshold warnings gracefully.

When to Use It

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

Quick Start

  1. Step 1: Initialize and check quota status for your service, using QuotaTracker and get_quota_status
  2. Step 2: Record usage after each operation with tracker.record_request and relevant metrics
  3. Step 3: Before execution, call tracker.can_handle_task(estimated_tokens) to decide if you may proceed

Best Practices

  • Initialize a single shared QuotaTracker per service to centralize quota state
  • Check quota status before performing operations to avoid overruns
  • Record usage after each operation or batch to keep accurate accounting
  • Respond to Threshold warnings by batching requests or deferring non-urgent calls
  • Use can_handle_task to estimate feasibility and surface issues before execution

Example Use Cases

  • A microservice calling a third-party API with per-minute and per-day quotas uses the tracker to prevent bursts
  • A customer-facing widget tracks user session quotas to avoid overages across visits
  • API calls are batched or routed to a secondary service when in the 80-95% warning band
  • Before executing expensive requests, the system calls can_handle_task to estimate feasibility
  • Multi-tenant apps enforce separate quotas per customer and log usage for cost-tracking

Frequently Asked Questions

Add this skill to your agents

Related Skills

Sponsor this space

Reach thousands of developers