Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Use when working with the internal billing library for cost allocation, invoice processing, or revenue recognition. Documents API usage, data models, common patterns, and integration methods for billing operations across services.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 121% | 0% |
| case-02 | ✗→✓ | ▲ Improved | -6% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 57% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 95% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 108% | 0% |
Comprehensive reference for the internal billing library, documenting API usage, data models, integration patterns, and common operations for cost allocation and revenue recognition.
Main client for interacting with the billing system:
pythonfrom billing_lib import BillingClient client = BillingClient( api_url="https://billing.internal.company.com", api_key="your-api-key", timeout=30 )
Tracks and aggregates service usage:
pythonfrom billing_lib import UsageTracker tracker = UsageTracker(client) usage = tracker.get_usage( service_id="web-api", customer_id="cust-123", period="2024-01" )
Calculates costs based on usage and pricing rules:
pythonfrom billing_lib import PriceCalculator calculator = PriceCalculator() cost = calculator.calculate_cost( usage_record=usage, pricing_tier="enterprise" )
pythoncustomer = client.create_customer( name="Acme Corp", billing_email="billing@acme.com", address={ "street": "123 Business St", "city": "San Francisco", "state": "CA", "zip": "94105", "country": "US" }, metadata={"industry": "technology", "size": "enterprise"} )
pythoncustomer = client.get_customer(customer_id="cust-123")
pythoncustomer = client.update_customer( customer_id="cust-123", billing_email="new-billing@acme.com" )
pythonusage_record = tracker.record_usage( service_id="web-api", customer_id="cust-123", usage_type="api_calls", quantity=1000, unit="calls", timestamp="2024-01-15T10:00:00Z", metadata={"endpoint": "/api/v1/users"} )
pythonsummary = tracker.get_usage_summary( customer_id="cust-123", start_date="2024-01-01", end_date="2024-01-31", group_by=["service_id", "usage_type"] )
pythoninvoice = client.generate_invoice( customer_id="cust-123", period="2024-01", due_date="2024-02-15", line_items=[ { "description": "API Usage", "quantity": 100000, "unit_price": 0.001, "total": 100.00 } ] )
pythoninvoice = client.get_invoice(invoice_id="inv-456")
python@dataclass class Customer: id: str name: str billing_email: str address: Address created_at: datetime updated_at: datetime metadata: Dict[str, Any] status: CustomerStatus # ACTIVE, SUSPENDED, CANCELLED
python@dataclass class UsageRecord: id: str service_id: str customer_id: str usage_type: str quantity: Decimal unit: str timestamp: datetime metadata: Dict[str, Any]
python@dataclass class Invoice: id: str customer_id: str period: str status: InvoiceStatus # DRAFT, SENT, PAID, OVERDUE total_amount: Decimal due_date: date line_items: List[LineItem] created_at: datetime
python# Example: Integrating a new service from billing_lib import UsageTracker, BillingClient class MyServiceBilling: def __init__(self): self.client = BillingClient.from_config() self.tracker = UsageTracker(self.client) def track_api_usage(self, customer_id, endpoint, count): return self.tracker.record_usage( service_id="my-service", customer_id=customer_id, usage_type="api_calls", quantity=count, unit="calls", metadata={"endpoint": endpoint} )
python# Example: Processing usage in batches def process_daily_usage(): tracker = UsageTracker(BillingClient.from_config()) # Get usage from monitoring system usage_data = get_usage_from_monitoring("2024-01-15") # Batch record usage batch_results = [] for record in usage_data: try: result = tracker.record_usage(**record) batch_results.append(result) except Exception as e: logger.error(f"Failed to record usage: {e}") return batch_results
bashBILLING_API_URL=https://billing.internal.company.com BILLING_API_KEY=your-api-key BILLING_TIMEOUT=30 BILLING_RETRY_ATTEMPTS=3 BILLING_BATCH_SIZE=100
yamlbilling: api_url: "https://billing.internal.company.com" api_key: "${BILLING_API_KEY}" timeout: 30 retry_attempts: 3 batch_size: 100 pricing: default_currency: "USD" tax_inclusive: false reporting: timezone: "UTC" fiscal_month_start_day: 1
pythonimport pytest from billing_lib import BillingClient, UsageTracker from unittest.mock import Mock, patch class TestBillingClient: @pytest.fixture def client(self): return BillingClient( api_url="https://test.billing.com", api_key="test-key" ) def test_create_customer(self, client): with patch.object(client, 'post') as mock_post: mock_post.return_value.json.return_value = { "id": "cust-123", "name": "Test Customer" } customer = client.create_customer(name="Test Customer") assert customer.id == "cust-123" assert customer.name == "Test Customer"
pythonclass TestBillingIntegration: def test_end_to_end_billing(self): # Setup test customer customer = client.create_customer( name="Test Customer", billing_email="test@example.com" ) # Record usage usage = tracker.record_usage( service_id="test-service", customer_id=customer.id, usage_type="api_calls", quantity=100 ) # Generate invoice invoice = client.generate_invoice( customer_id=customer.id, period="2024-01" ) assert invoice.total_amount > 0 assert len(invoice.line_items) > 0
Load these files when needed:
scripts/billing-integration.py - Integration helpers and utilitiesscripts/usage-aggregator.py - Usage data aggregation and processingreferences/billing-api-spec.md - Complete API specificationassets/pricing-rules.yaml - Pricing rule definitions and examplesexamples/integration-patterns/ - Service integration examples and patternsOther measured skills in the registry, with their headline benchmark lift.