> ## Documentation Index
> Fetch the complete documentation index at: https://openrouter.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# KeyBudget

One budget layer that applies to requests made with this key, with the spend enforcement compares against it.

## Example Usage

```typescript theme={null}
import { KeyBudget } from "@openrouter/sdk/models";

let value: KeyBudget = {
  budgetId: null,
  guardrailId: "0df9e665-d932-5740-b2c7-b52af166bc11",
  includeByok: false,
  limitUsd: 50,
  remainingUsd: 17.5,
  resetInterval: "weekly",
  resetsAt: new Date("2026-10-12T00:00:00.000Z"),
  scope: "member",
  spendUsd: 32.5,
};
```

## Fields

| Field | Type | Required | Description | Example |
| - | - | - | - | - |
| `budgetId` | *string* | ✔️ | ID of the workspace budget for the `workspace` scope; null for other scopes. | null |
| `guardrailId` | *string* | ✔️ | ID of the guardrail policy whose budget applies at this layer. A budget still managed through v1 guardrails reports its synced policy ID, not its guardrail ID. Null for the `workspace` and `key_limit` scopes. Look up a policy ID with a management key that has guardrail read access (for a Custom key, select the `guardrails:read` grant): `GET /api/v1/guardrails/policies/budget/{id}` (an organization-wide key must add `?workspace_id=`, for example the `workspace_id` this endpoint returns), or find an account-level policy in `GET /api/v1/guardrails/policies/account` (organization-wide key only). A workspace-scoped key can read only policies its workspace owns, so it gets 404 for an account-level policy, such as an inherited account default or a policy synced from a v1 guardrail assigned only to members or API keys; look those up with an organization-wide key and `?workspace_id=`. Policies synced from v1 guardrails assigned only to members or API keys can be missing from the account-level list. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
| `includeByok` | *boolean* | ✔️ | Whether external BYOK inference spend counts toward this budget. | false |
| `limitUsd` | *number* | ✔️ | Budget limit in USD for the current window. | 50 |
| `remainingUsd` | *number* | ✔️ | `limit_usd - spend_usd`. Zero or negative means this layer rejects requests with a 403 until it resets. | 17.5 |
| `resetInterval` | [models.KeyBudgetResetInterval](../models/keybudgetresetinterval.mdx) | ✔️ | UTC window the spend is counted over (weeks start Monday); null for a lifetime budget that never resets. | weekly |
| `resetsAt` | [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) | ✔️ | ISO 8601 UTC instant at which the window rolls over and spend returns to zero; null for a lifetime budget. | 2026-10-12T00:00:00.000Z |
| `scope` | [models.KeyBudgetScope](../models/keybudgetscope.mdx) | ✔️ | Which budget layer this is, in the order enforcement checks them: the workspace default guardrail against the member aggregate (`workspace_default_member`) and against this key (`workspace_default_key`), the member guardrail (`member`), the API key guardrail (`api_key`), a workspace budget (`workspace`), or the key's own limit (`key_limit`). | member |
| `spendUsd` | *number* | ✔️ | Spend in USD that enforcement counts against this limit in the current window: the member aggregate for member-scoped layers, otherwise this key or workspace. | 32.5 |
