Skip to main content

Overview

Layer tracks the cost of every request in real-time, giving you visibility into how much you’re spending across all your gates. You can set spending limits at both the account level and per-gate level.

Account-Level Spending

Viewing Your Spending

Go to Dashboard → Spending to see:
  • Current spending — Total cost in the current billing period
  • Spending limit — Your configured cap (if set)
  • Percentage used — How close you are to your limit
  • Period start — When the current 30-day rolling period began

Setting a Spending Limit

  1. Go to Dashboard → Spending
  2. Set your monthly spending limit (in USD)
  3. Choose an enforcement type:
    • Alert only — You’re warned when you exceed the limit, but requests continue
    • Block — Requests are rejected once the limit is hit

Alert Threshold

By default, Layer alerts you when spending reaches 80% of your limit. This gives you time to react before hitting the cap.

Gate-Level Spending

Each gate can have its own independent spending limit, separate from your account limit.

Configuration

When creating or editing a gate:
  1. Go to the Spending Limits tab
  2. Set a limit amount (USD)
  3. Choose a period: monthly or daily
  4. Choose enforcement: alert_only or block

How It Works

  • Each request through a gate increments that gate’s spending counter
  • When the counter exceeds the limit:
    • Alert only: Request proceeds, but the gate’s status shows a warning
    • Block: Request is rejected. The gate’s status changes to suspended until the period resets.
  • Counters reset automatically at the start of each period

Cost Calculation

Layer calculates costs based on:
  • Token count (input + output tokens)
  • Published model pricing from each provider
  • Request type (chat, image generation, etc.)
Cost is tracked per request and aggregated into gate-level and account-level totals.
If you’re using BYOK (Bring Your Own Keys), Layer still tracks estimated costs for analytics and limit enforcement. Your actual provider bill may vary slightly from Layer’s estimates.

Session-Level Spending (Agent Gates)

Agent gates add per-session spending controls with a two-tier system:
TierBehavior
Soft limitRequest proceeds. Warning header returned so your code can react.
Hard limitRequest rejected (HTTP 402). Session blocked from further requests.
See Agent Gates for details.

Spending API

You can programmatically check and manage spending via the API:
# Get current spending
curl https://api.uselayer.ai/v1/spending \
  -H "Authorization: Bearer layer_your_key"

# Response
{
  "currentSpending": 12.45,
  "limit": 50.00,
  "periodStart": "2026-02-08T00:00:00Z",
  "status": "active",
  "limitEnforcementType": "alert_only",
  "percentUsed": 24.9
}