---
title: "Spend limits API: cap a key before automation runs"
description: "Give each key a daily, weekly or monthly cap and a prepaid budget, cap end users and sessions, read the spendable balance and price a call before sending."
canonical: https://pentestllm.ai/docs/spend-limits
generated: 2026-11-27T06:25:48.880Z
source: https://pentestllm.ai/docs/spend-limits
base_url: https://api.pentestllm.ai/v1
---

[Docs](https://pentestllm.ai/docs) / API reference

# Spend limits, budgets and balance

Updated 2026-11-22. Published by PentestLLM.

Put the ceilings in place before a scanner or agent runs unattended. Limits live on each key, so you set them through the key routes, and under `https://api.pentestllm.ai/v1` two read-only routes report what the organization can still spend while a third, kept for older clients, always answers zero. A fourth prices a request on every model without sending it. The OpenAPI document has no separate budget route.

## Routes

| Route | Credential | Statuses |
| --- | --- | --- |
| `GET /v1/credits` | API key | 200, 401 |
| `GET /v1/dashboard/billing/subscription` | API key | 200, 401 |
| `GET /v1/dashboard/billing/usage` | API key | 200, 401 |
| `POST /v1/estimate` | none, or an API key | 200, 400, 401, 413 |

The three balance reads fall back on the document-wide credentials, meaning any ordinary key sent the way your SDK already sends it. On console sessions for them, the OpenAPI document does not say either way. The estimate also runs with no credential at all. Limits are written with an admin key through `POST /v1/keys` and `PATCH /v1/keys/{key_id}`, whose statuses are on [Keys and scopes](https://pentestllm.ai/docs/keys).

## Settings on a key

You write dollars; a key reads back in micro-dollars, a millionth of a dollar each. On a PATCH, null clears a cap.

| Write | Read back as | Behaviour |
| --- | --- | --- |
| `monthly_cap_usd` | monthly_spend_limit_micro, period_spend_micro | A recurring dollar cap. Despite the name, it applies to whatever spend_limit_period says. |
| `spend_limit_period` | spend_limit_period | daily restarts at 00:00 UTC, weekly at Monday 00:00 UTC, monthly (the default) on the first of the UTC month. |
| `budget_usd` | budget_micro, budget_spent_micro, budget_remaining_micro | A prepaid allowance for this key. Its charges plus open holds are checked against it, and the organization balance is still what pays. |
| `user_budget_usd` | user_budget_micro | A cap per end user on this key; only the user who reaches it is stopped. |
| `user_budget_period` | user_budget_period | daily, weekly or monthly, monthly unless set. |
| `session_max_requests` | session_max_requests | Calls per session in any sliding hour, 1 to 100,000. |
| `session_max_spend_usd` | session_max_spend_micro | Dollars per session per UTC day. |
| `loop_guard` | loop_guard | Refuses a session’s sixth identical tool call or identical body inside 10 minutes. |
| `concurrency` | concurrency_limit | Calls in flight at once. Independent of any dollar cap. |

A budget cannot be lowered under what the key has spent against it (`400 budget_below_spent`). Clearing it with null removes it; setting one again starts its count from zero. To watch a key approach its limits, read its usage on [Usage and receipts](https://pentestllm.ai/docs/usage-and-receipts).

## What a model call gets once a cap is hit

These come back from model routes, never from the balance reads. `402` carries `monthly_limit_reached`, `weekly_limit_reached` or `daily_limit_reached` for the recurring cap, `key_budget_exhausted` for the key budget, `user_budget_reached` for one end user, `insufficient_balance` when the organization is out of funds, and `spend_cap_reached` for a new account whose first payment has not settled. `429` carries `session_cap`, `loop_detected` or `rate_limited`.

## Read the balance

None of the three takes a body or a parameter. `GET /v1/credits` returns `data.total_credits`, the available balance in dollars after subtracting what in-flight requests hold, and `data.total_usage`, which is always 0. `GET /v1/dashboard/billing/subscription` returns `object`, `has_payment_method` (always true), `soft_limit_usd`, `hard_limit_usd` and `system_hard_limit_usd`, all three equal to that same available balance rather than a recurring quota, and `access_until`, the key’s expiry in Unix seconds or 0 for none. `GET /v1/dashboard/billing/usage` returns `object` list and `total_usage` 0, for compatibility only. A failed credential is `401 invalid_api_key`.

## Estimate before sending

`POST /v1/estimate` takes `input_tokens`, or text to count in any mix of `prompt`, `system` and `messages`; `output_tokens`, 1000 when omitted; and an optional `models` list to narrow the answer. Text is counted at four characters a token plus four per message. The reply states `prices` (public, or your organization when a key was sent), the token counts, a `basis` line, and `data`, cheapest first, with each model’s `cost_usd`, `list_cost_usd`, `saved_usd` and `saved_pct`. No model is called and nothing is charged, and real token counts can differ. Errors: `400 invalid_request` for nothing to count or a bad models list, `401 invalid_api_key` when a key was sent and fails, `413 invalid_request` for an oversized body.

## Example

```bash
curl "https://api.pentestllm.ai/v1/credits" \
  -H "Authorization: Bearer sk-ptl-live-…"
```

## Questions

### Does monthly_cap_usd only work per month?

No. Its sibling spend_limit_period picks the reset: each UTC day, each week from Monday, or each UTC month, which is the default.

### Can billing/usage show what I spent last month?

No. It returns zero on purpose, so balance clients written for another provider keep working. For history, read key usage, request records or the usage CSV.

### Does a key budget hold money apart from my balance?

No. It is a ceiling on one key. Every charge is still taken from the organization’s prepaid balance, and the budget stops the key once its charges plus open holds reach it.

## Read next

- [MCP servers](https://pentestllm.ai/docs/mcp-servers)
- [Log export](https://pentestllm.ai/docs/exports)
- [Invoices](https://pentestllm.ai/docs/invoices)
- [Billing details](https://pentestllm.ai/docs/billing-details)
- [Statement signing key](https://pentestllm.ai/docs/statements-public-key)
- [Keys and scopes](https://pentestllm.ai/docs/keys)
- [Usage and signed receipts](https://pentestllm.ai/docs/usage-and-receipts)
- [Redaction and guardrails](https://pentestllm.ai/docs/redaction-and-guardrails)
- [Sessions](https://pentestllm.ai/docs/sessions)
- [Embeddings, rerank and moderation](https://pentestllm.ai/docs/retrieval-and-moderation)
- [Batch files](https://pentestllm.ai/docs/files)
- [Batches](https://pentestllm.ai/docs/batches)
- [Status and proof feeds](https://pentestllm.ai/docs/status-and-proof)
- [Count tokens](https://pentestllm.ai/docs/count-tokens)
- [Usage by app](https://pentestllm.ai/docs/stats-apps)
- [App sign-in keys](https://pentestllm.ai/docs/auth-keys)
- [Webhook deliveries](https://pentestllm.ai/docs/webhooks-deliveries)
- [Docs: connect in two minutes](https://pentestllm.ai/docs)
- [Pricing](https://pentestllm.ai/pricing)
- [Sessions, usage export and log streaming](https://pentestllm.ai/features/observability)
