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
- Go to Dashboard → Spending
- Set your monthly spending limit (in USD)
- 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:- Go to the Spending Limits tab
- Set a limit amount (USD)
- Choose a period:
monthlyordaily - Choose enforcement:
alert_onlyorblock
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
suspendeduntil 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.)
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:| Tier | Behavior |
|---|---|
| Soft limit | Request proceeds. Warning header returned so your code can react. |
| Hard limit | Request rejected (HTTP 402). Session blocked from further requests. |