Billing & Credits
Everything about how Layers billing works: the credit system, cost calculations, margins, Stripe subscriptions, and pricing synchronization.
Powered by Hustle Together AI SDK - All model pricing data is synced from the Hustle Together AI SDK every 24 hours. The SDK aggregates real-time pricing from all AI providers to ensure accurate cost calculations.
Credit System Overview#
Layers uses a unified credit system that abstracts away the complexity of different AI provider pricing models into a single balance.
Core Concept
With the default 60% margin, each credit costs you ~$0.016.
How Token Counting Works#
Understanding the separation between what the AI SDK provides and what Layers calculates is key to understanding your billing.
The Flow
You make API request
POST /api/v1/chat
{ "model": "claude-3-5-sonnet", "messages": [...] }Hustle Together AI SDK processes request
Returns token counts only:
- •
prompt_tokens: 12 - •
completion_tokens: 8
Layers calculates costs (YOUR BILLING)
(12 × $3/1M) + (8 × $15/1M) = $0.00024$0.00024 × 1.6 = $0.000384$0.000384 / $0.01 = 0.0384 creditsResponse includes both
usage field (SDK data)layers field (your cost breakdown)Complete API Response
Every Layers API response includes both the standard OpenAI-compatible usage field and a detailed Layers cost breakdown:
{
"id": "msg_01ABC123...",
"model": "claude-3-5-sonnet-20241022",
"role": "assistant",
"content": [
{
"type": "text",
"text": "The capital of France is Paris."
}
],
"stop_reason": "end_turn",
// Standard usage field (from Hustle Together AI SDK)
"usage": {
"prompt_tokens": 12, // ← SDK provides this
"completion_tokens": 8, // ← SDK provides this
"total_tokens": 20
},
// Layers cost breakdown (calculated by Layers)
"layers": {
"credits_used": 0.00048, // ← Your actual charge
"latency_ms": 847,
"cost_breakdown": {
"model": "claude-3-5-sonnet-20241022",
"input_tokens": 12, // ← Used for calculation
"output_tokens": 8, // ← Used for calculation
"base_cost_usd": 0.0003, // ← Calculated by Layers
"margin_percent": 60, // ← Your margin
"margin_cost_usd": 0.00018, // ← Calculated by Layers
"total_cost_usd": 0.00048, // ← Calculated by Layers
"credits": 0.00048 // ← What you pay
}
}
}Key Takeaway
• Looks up model pricing (synced from Hustle Together AI)
• Calculates USD cost from tokens
• Applies your margin
• Converts to credits
• Provides transparent cost breakdown
Cost Calculation#
The Formula
credits = (base_cost_usd / $0.01) × (1 + margin_percent / 100)
With the default 60% margin:
credits = (base_cost_usd / $0.01) × 1.60Example Calculation
Using Claude Sonnet 4.5 with 1,000 input tokens and 500 output tokens:
| Component | Calculation | Value |
|---|---|---|
| Input Cost | 1,000 tokens × $3.00/1M | $0.003 |
| Output Cost | 500 tokens × $15.00/1M | $0.0075 |
| Base Cost | $0.003 + $0.0075 | $0.0105 |
| Credits (before margin) | $0.0105 / $0.01 | 1.05 |
| Margin (60%) | 1.05 × 0.60 | 0.63 |
| Total Credits | 1.05 + 0.63 | 1.68 credits |
Model Pricing Reference#
Dynamic Pricing
Example prices per 1,000 tokens:
| Model | Provider | Input USD | Output USD | Credits (60%) |
|---|---|---|---|---|
| GPT-4o Mini | OpenAI | $0.0001 | $0.0006 | ~0.01 |
| Gemini 2.5 Flash | $0.0003 | $0.0025 | ~0.05 | |
| Claude 4.5 Haiku | Anthropic | $0.001 | $0.005 | ~0.10 |
| Claude 4.5 Sonnet | Anthropic | $0.003 | $0.015 | ~0.29 |
| GPT-4o | OpenAI | $0.0025 | $0.01 | ~0.20 |
| Claude 4.5 Opus | Anthropic | $0.005 | $0.025 | ~0.48 |
View live pricing at /dashboard/pricing.
Margin System#
The margin is the markup Layers applies on top of base AI provider costs. The default margin is 60%.
Margin Breakdown in API Response
Every API response includes both standard usage and a detailed Layers cost breakdown:
{
// ... message content ...
"usage": {
"prompt_tokens": 1000,
"completion_tokens": 500,
"total_tokens": 1500
},
"layers": {
"credits_used": 1.68,
"latency_ms": 1243,
"cost_breakdown": {
"model": "claude-3-5-sonnet-20241022",
"input_tokens": 1000,
"output_tokens": 500,
"base_cost_usd": 0.0105,
"margin_percent": 60,
"margin_cost_usd": 0.0063,
"total_cost_usd": 0.0168,
"credits": 1.68
}
}
}Credit-to-Cost Quick Reference
| Base Cost (USD) | Credits @ 60% margin |
|---|---|
| $0.001 | 0.16 credits |
| $0.005 | 0.80 credits |
| $0.01 | 1.60 credits |
| $0.05 | 8.00 credits |
| $0.10 | 16.00 credits |
Subscription Tiers#
| Tier | Monthly Price | Credits | Rate Limit | Overage |
|---|---|---|---|---|
| Free | $0 | 50 | 10/min | N/A |
| Starter | $20/mo | 500 | 60/min | $0.05/credit |
| Pro | $100/mo | 3,000 | 300/min | $0.04/credit |
| Team | $200/mo | 7,500 | 1,000/min | $0.033/credit |
What Can You Do With Credits?
| Credits | Approximate Usage |
|---|---|
| 50 (Free) | ~15 Claude Haiku conversations |
| 500 (Starter) | ~100 GPT-4o queries or ~160 Gemini Flash |
| 3,000 (Pro) | ~600 Claude Sonnet or ~1,000 GPT-4o |
| 7,500 (Team) | ~1,500 Claude Sonnet or ~2,500 GPT-4o |
Stripe Integration#
Layers uses Stripe for all subscription management and billing.
Subscription Flow
Webhook Events
| Event | Action |
|---|---|
checkout.session.completed | Create subscription, link customer |
customer.subscription.created | Grant initial credits |
customer.subscription.updated | Update tier (upgrade/downgrade) |
customer.subscription.deleted | Revert to free tier |
invoice.paid | Add monthly credits |
Pricing Sync#
Layers automatically syncs pricing from Hustle Together AI to ensure costs match the latest rates:
Source: https://ai.hustletogether.com/api/pricing
Frequency: Daily sync via GitHub Actions
Cache: 24-hour in-memory cache
Models: 40 total (19 language, 21 image/multimodal)
Providers: 6 (Anthropic, OpenAI, Google, Perplexity, Morph, BFL, Recraft)Pricing API Endpoints
| Endpoint | Method | Purpose |
|---|---|---|
/api/v1/pricing | GET | View current pricing and sync status |
/api/v1/pricing | POST | Force refresh from Hustle Together AI |
Credit Deduction Flow#
Request Flow
Pre-Flight Estimate
estimateCredits(model, max_tokens)AI Gateway Call
Actual Calculation
calculateCreditsWithBreakdown(model, input_tokens, output_tokens)Deduction & Logging
deductCredits(userId, credits)logUsage(userId, model, tokens, credits)External Cost Validation#
If you calculate your own base costs, you can pass them to Layers for validation:
{
"model": "anthropic/claude-sonnet-4.5",
"messages": [...],
"mirror_factory": {
"base_cost_usd": 0.0105
}
}Layers validates your cost against its own calculation and flags discrepancies>5% as warnings.