Layers

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

1 credit = $0.01 USD worth of AI usage (before margin)
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

1

You make API request

POST /api/v1/chat
{ "model": "claude-3-5-sonnet", "messages": [...] }
2

Hustle Together AI SDK processes request

Returns token counts only:

  • prompt_tokens: 12
  • completion_tokens: 8
3

Layers calculates costs (YOUR BILLING)

Looks up model pricing from registry
Calculates base cost in USD
(12 × $3/1M) + (8 × $15/1M) = $0.00024
Applies 60% margin
$0.00024 × 1.6 = $0.000384
Converts to credits
$0.000384 / $0.01 = 0.0384 credits
4

Response includes both

Standard 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

The SDK only provides token counts. Layers does all the pricing math:
• 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.60

Example Calculation

Using Claude Sonnet 4.5 with 1,000 input tokens and 500 output tokens:

ComponentCalculationValue
Input Cost1,000 tokens × $3.00/1M$0.003
Output Cost500 tokens × $15.00/1M$0.0075
Base Cost$0.003 + $0.0075$0.0105
Credits (before margin)$0.0105 / $0.011.05
Margin (60%)1.05 × 0.600.63
Total Credits1.05 + 0.631.68 credits

Model Pricing Reference#

Dynamic Pricing

For current pricing on all 40 models, see the Pricing Dashboard which pulls real-time data from the Hustle Together AI SDK. The examples below are for illustration.

Example prices per 1,000 tokens:

ModelProviderInput USDOutput USDCredits (60%)
GPT-4o MiniOpenAI$0.0001$0.0006~0.01
Gemini 2.5 FlashGoogle$0.0003$0.0025~0.05
Claude 4.5 HaikuAnthropic$0.001$0.005~0.10
Claude 4.5 SonnetAnthropic$0.003$0.015~0.29
GPT-4oOpenAI$0.0025$0.01~0.20
Claude 4.5 OpusAnthropic$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.0010.16 credits
$0.0050.80 credits
$0.011.60 credits
$0.058.00 credits
$0.1016.00 credits

Subscription Tiers#

TierMonthly PriceCreditsRate LimitOverage
Free$05010/minN/A
Starter$20/mo50060/min$0.05/credit
Pro$100/mo3,000300/min$0.04/credit
Team$200/mo7,5001,000/min$0.033/credit

What Can You Do With Credits?

CreditsApproximate 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

Dashboard
Checkout
Stripe
Checkout
Payment
Complete
Webhook
Handler
Update
Credits

Webhook Events

EventAction
checkout.session.completedCreate subscription, link customer
customer.subscription.createdGrant initial credits
customer.subscription.updatedUpdate tier (upgrade/downgrade)
customer.subscription.deletedRevert to free tier
invoice.paidAdd 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)
For current pricing on all models, see the Pricing Dashboard which displays real-time data from the Hustle Together AI SDK.

Pricing API Endpoints

EndpointMethodPurpose
/api/v1/pricingGETView current pricing and sync status
/api/v1/pricingPOSTForce refresh from Hustle Together AI

Credit Deduction Flow#

Request Flow

1

Pre-Flight Estimate

estimateCredits(model, max_tokens)
→ Check user balance ≥ estimate
→ Return 402 if insufficient
2

AI Gateway Call

→ Call AI provider
→ Get actual token usage
3

Actual Calculation

calculateCreditsWithBreakdown(model, input_tokens, output_tokens)
4

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.

Next Steps#