quota-management
npx machina-cli add skill athola/claude-night-market/quota-management --openclawTable of Contents
- Overview
- When to Use
- Core Concepts
- Quota Thresholds
- Quota Types
- Quick Start
- Check Quota Status
- Record Usage
- Estimate Before Execution
- Integration Pattern
- Detailed Resources
- Exit Criteria
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:
- Initialize tracker for your service
- Check quota before operations
- Record usage after operations
- Handle threshold warnings gracefully
Detailed Resources
- Threshold Strategies: See
modules/threshold-strategies.mdfor degradation patterns - Estimation Patterns: See
modules/estimation-patterns.mdfor 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
- Step 1: Initialize and check quota status for your service, using QuotaTracker and get_quota_status
- Step 2: Record usage after each operation with tracker.record_request and relevant metrics
- 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
Related Skills
terraform
chaterm/terminal-skills
Terraform 基础设施即代码
makefile-generation
athola/claude-night-market
Generate language-specific Makefiles with testing, linting, and automation targets. Use for project initialization and workflow standardization. Skip if Makefile exists.
precommit-setup
athola/claude-night-market
Configure three-layer pre-commit system with linting, type checking, and testing hooks. Use for quality gate setup and code standards. Skip if pre-commit is optimally configured.
error-patterns
athola/claude-night-market
'Standardized error handling patterns with classification, recovery,
risk-classification
athola/claude-night-market
'Inline risk classification for agent tasks using a 4-tier model. Hybrid
workflow-setup
athola/claude-night-market
Configure GitHub Actions CI/CD workflows for automated testing, linting, and deployment. Use for CI/CD setup and quality automation. Skip if CI/CD configured or using different platform.