OpenAI / Anthropic Token-Based Billing
How to implement API token usage billing with tiered overage pricing using Billerang.
Business Model
| Component | Description |
|---|---|
| Base fee | $20/month platform access |
| Included tokens | 1M tokens/month (free) |
| Overage pricing | Tiered by model and volume |
| Billing cycle | Monthly |
Overage rates:
| Model | 0-5M overage | 5M+ overage |
|---|---|---|
| GPT-4 | $0.030/1K tokens | $0.020/1K tokens |
| GPT-3.5 | $0.002/1K tokens | $0.0015/1K tokens |
| Claude Opus | $0.025/1K tokens | $0.018/1K tokens |
Catalog Structure
Step-by-Step Implementation
1. Create Counter Template (Included Tokens)
POST /api/rest/catalog/counterTemplate/createOrUpdate
{
"code": "CTR_MONTHLY_TOKENS",
"description": "Monthly included tokens (1M)",
"counterType": "USAGE",
"ceiling": 1000000,
"ceilingExpressionEl": null,
"calendar": "MONTHLY",
"counterLevel": "UA"
}
2. Create Base Fee Charge
POST /api/rest/v2/chargeTemplate/RC_DEV_BASE
{
"chargeType": "RECURRING",
"description": "Monthly Developer Plan Base Fee",
"calendar": "MONTHLY",
"applyInAdvance": true,
"subscriptionProrata": true,
"invoiceSubCategoryCode": "ISC_SUBSCRIPTION",
"taxClassCode": "TAX_DIGITAL_SERVICES",
"pricing": {
"mode": "FLAT",
"baseCurrency": "USD",
"price": 20.00,
"autoPublish": true
}
}
3. Create Usage Charge with Tiered Matrix Pricing
POST /api/rest/v2/chargeTemplate/UC_TOKEN_USAGE
{
"chargeType": "USAGE",
"description": "Token Usage Overage",
"invoiceSubCategoryCode": "ISC_USAGE",
"taxClassCode": "TAX_DIGITAL_SERVICES",
"filterExpression": "#{edr.parameter1 != null}",
"priority": 1,
"inputUnitOfMeasureCode": "TOKEN",
"ratingUnitOfMeasureCode": "KILO_TOKEN",
"unitNbDecimal": 6,
"pricing": {
"mode": "MATRIX",
"baseCurrency": "USD",
"applicationLevel": "SINGLE_EVENT",
"dimensions": [
{ "code": "MODEL", "type": "String", "label": "AI Model", "position": 1 },
{ "code": "QUANTITY_TIER", "type": "Range_Numeric", "label": "Volume Tier", "position": 2 }
],
"rows": [
{
"priority": 1,
"description": "GPT-4, 0-5M overage",
"values": [
{ "dimensionCode": "MODEL", "stringValue": "gpt-4" },
{ "dimensionCode": "QUANTITY_TIER", "fromDoubleValue": 0, "toDoubleValue": 5000000 }
],
"price": 0.030
},
{
"priority": 2,
"description": "GPT-4, 5M+ overage",
"values": [
{ "dimensionCode": "MODEL", "stringValue": "gpt-4" },
{ "dimensionCode": "QUANTITY_TIER", "fromDoubleValue": 5000001, "toDoubleValue": null }
],
"price": 0.020
},
{
"priority": 3,
"description": "GPT-3.5, 0-5M overage",
"values": [
{ "dimensionCode": "MODEL", "stringValue": "gpt-3.5-turbo" },
{ "dimensionCode": "QUANTITY_TIER", "fromDoubleValue": 0, "toDoubleValue": 5000000 }
],
"price": 0.002
},
{
"priority": 4,
"description": "GPT-3.5, 5M+ overage",
"values": [
{ "dimensionCode": "MODEL", "stringValue": "gpt-3.5-turbo" },
{ "dimensionCode": "QUANTITY_TIER", "fromDoubleValue": 5000001, "toDoubleValue": null }
],
"price": 0.0015
},
{
"priority": 5,
"description": "Claude Opus, 0-5M overage",
"values": [
{ "dimensionCode": "MODEL", "stringValue": "claude-opus" },
{ "dimensionCode": "QUANTITY_TIER", "fromDoubleValue": 0, "toDoubleValue": 5000000 }
],
"price": 0.025
},
{
"priority": 6,
"description": "Claude Opus, 5M+ overage",
"values": [
{ "dimensionCode": "MODEL", "stringValue": "claude-opus" },
{ "dimensionCode": "QUANTITY_TIER", "fromDoubleValue": 5000001, "toDoubleValue": null }
],
"price": 0.018
},
{
"priority": 99,
"description": "Default fallback",
"price": 0.010
}
],
"autoPublish": true
}
}
4. Create Product and Offer
# Create product
POST /api/rest/catalog/products
{ "code": "API_PLATFORM", "description": "AI API Platform Access" }
# Add charges
POST /api/rest/catalog/products/API_PLATFORM/addCharges
{
"productCharges": [
{ "chargeTemplateCode": "RC_DEV_BASE" },
{ "chargeTemplateCode": "UC_TOKEN_USAGE", "counterTemplateCode": "CTR_MONTHLY_TOKENS" }
]
}
# Create offer
POST /api/rest/catalog/offerTemplate/createOrUpdate
{
"code": "OPENAI_DEVELOPER_PLAN",
"description": "Developer Plan - $20/mo + token overage",
"offerProductTemplates": [{ "productTemplate": { "code": "API_PLATFORM" }, "mandatory": true }]
}
5. Submit API Usage (CDR)
Each API call from the customer submits a CDR:
POST /api/rest/billing/mediation/chargeCdr
{
"accessCode": "SUB_DEV_001",
"parameter1": "gpt-4",
"parameter2": "completion",
"quantity": 1500,
"eventDate": "2026-03-15T10:30:00Z"
}
CDR fields mapping:
| CDR Field | Value | Purpose |
|---|---|---|
accessCode | Subscription code | Links to customer subscription |
parameter1 | Model name | Matrix dimension: MODEL |
parameter2 | Operation type | For reporting (not pricing) |
quantity | Token count | Rated quantity |
6. Batch CDR Registration (High Volume)
For high-throughput scenarios, use batch registration:
POST /api/rest/billing/mediation/registerCdrList
{
"cdrs": [
"SUB_DEV_001;2026-03-15T10:30:00Z;gpt-4;completion;1500",
"SUB_DEV_001;2026-03-15T10:31:00Z;gpt-3.5-turbo;chat;5000",
"SUB_DEV_001;2026-03-15T10:32:00Z;claude-opus;analysis;2000"
]
}
Monthly Billing Flow
Pricing Preview
Before subscribing, preview the expected costs:
POST /api/rest/orderManagement/commercialOrders/preview
{
"billingAccountCode": "BA_DEVELOPER",
"offerCode": "OPENAI_DEVELOPER_PLAN",
"subscriptionDate": "2026-04-01",
"items": [{
"productCode": "API_PLATFORM",
"quantity": 1
}]
}
Response:
{
"billingDocs": [{
"invoiceDate": "2026-04-01",
"currency": "USD",
"amountWithoutTax": 20.00,
"invoiceItems": [{
"chargeTemplateCode": "RC_DEV_BASE",
"chargeType": "R",
"unitAmountWithoutTax": 20.00,
"quantity": 1,
"amountWithoutTax": 20.00
}]
}],
"totalMonthly": 20.00,
"totalMRR": 20.00,
"currency": "USD"
}
Key Billerang Features Used
| Feature | Purpose |
|---|---|
| Counter template | 1M included tokens per month |
| Usage charge | Per-CDR rating for API calls |
| Matrix pricing | 2D pricing by model and volume tier |
| Tiered ranges | Volume brackets for overage |
| Batch CDR | High-throughput event ingestion |
| Unit conversion | Tokens -> KiloTokens for pricing |
Scaling Considerations
- CDR throughput: Use
registerCdrListfor batch processing (1000+ CDRs per call) - Counter performance: Counter decrements are atomic; safe for concurrent API calls
- Prepaid option: Use wallet reservations for real-time balance checking (see Prepaid Wallets)