> For the list of every page, fetch /llms.txt. The API contract is the OpenAPI file linked from the API reference.

# Set the budget of the account

PUT https%3A%2F%2Fapi.usemeadow.ai/v1/budget
Content-Type: application/json

Sets or replaces the budget of the account. A budget is an amount
to watch. It never refuses a call: use `limit` on a key for that. When spend
in the window first reaches each of `alert_thresholds`, Meadow sends one
`budget.threshold_crossed` webhook event and one email, once per threshold
per window. See the `budgetEvent` webhook.

The body replaces the whole budget. Thresholds already crossed in the current
window do not alert again.

Scope: `admin`.


Reference: https://docs.usemeadow.ai/api-endpoints/budgets/put-account-budget

## Authentication

- `Authorization` header (bearer token, required) — A Meadow API key, sent as `Authorization: Bearer mdw_...`. The header `x-api-key: mdw_...` is accepted in its place.

## Request

### Body (application/json)

This endpoint expects a BudgetWrite.

- `limit_usd` (double, required) — The amount to watch in one window, in US dollars. The name is the one on OpenRouter budgets. A plain JSON number above 0 and below 10^12 with at most 12 decimal places, read as written.
- `reset_interval` (enum, required) — The window. `daily` starts at midnight UTC, `weekly` on Monday at midnight UTC, `monthly` on the first of the month at midnight UTC: the clock of `limit_reset` on keys.
  - Allowed values: `daily`, `weekly`, `monthly`
- `hard_limit` (boolean, optional, default: false) — False, the default: the budget only alerts and never refuses a call. True makes `limit_usd` a ceiling for the window. Once the dollars counted for the budget reach it, model calls and sandbox creates in its scope are refused with 402 `budget_exceeded`, and a call whose reserved estimate does not fit what is left is refused the same way. A key in the scope of a hard budget is held to the rules of a key with a dollar `limit`: a model call must send an output cap, and a route that includes a provider with no price is refused with 403 `key_spend_price_unknown`. When it is switched on, the count starts at the window's `spend_usd` so far. Sandboxes that are running keep running. Left out of a `PUT`, it is false: a `PUT` replaces the whole budget.
- `alert_thresholds` (list of integer, optional, default: [50,75,100]) — Percentages of `limit_usd` that send an alert when spend first reaches them. Whole numbers from 1 to 100, no repeats. Left out, `[50, 75, 100]`. An empty list sends no alerts.
- `notification_channel` (BudgetWriteNotificationChannel, optional, nullable) — Where alert emails go, shaped as on OpenAI spend alerts. Null or left out sends no email. Webhook events are sent either way.

## Response

### 200

The budget as stored, with its spend.

- `limit_usd` (double, required) — The amount to watch in one window, in US dollars. The name is the one on OpenRouter budgets. A plain JSON number above 0 and below 10^12 with at most 12 decimal places, read as written.
- `reset_interval` (enum, required) — The window. `daily` starts at midnight UTC, `weekly` on Monday at midnight UTC, `monthly` on the first of the month at midnight UTC: the clock of `limit_reset` on keys.
  - Allowed values: `daily`, `weekly`, `monthly`
- `id` (string, required) — The budget id (`bud_...`).
- `object` (enum, required) — Always `budget`.
  - Allowed values: `budget`
- `scope` (enum, required) — Whether the budget covers the whole account or one project.
  - Allowed values: `account`, `project`
- `spend_usd` (double, required) — What was spent in the current window, from the usage records: model calls and sandboxes with a known cost. The name is OpenRouter's.
- `remaining_usd` (double, required) — `limit_usd` minus `spend_usd`. It can be negative: an alert-only budget does not stop spend, and one call may end above a hard limit.
- `resets_at` (datetime, required) — When the current window ends.
- `unknown_cost_records` (integer, required) — Records in the window with no cost: calls on a provider Meadow has no price for, calls with estimated tokens, sandboxes with no price. When this is above 0, `spend_usd` is lower than what you were billed.
- `created_at` (datetime, required) — When the budget was first set.
- `updated_at` (datetime, required) — When it was last replaced.
- `hard_limit` (boolean, optional, default: false) — False, the default: the budget only alerts and never refuses a call. True makes `limit_usd` a ceiling for the window. Once the dollars counted for the budget reach it, model calls and sandbox creates in its scope are refused with 402 `budget_exceeded`, and a call whose reserved estimate does not fit what is left is refused the same way. A key in the scope of a hard budget is held to the rules of a key with a dollar `limit`: a model call must send an output cap, and a route that includes a provider with no price is refused with 403 `key_spend_price_unknown`. When it is switched on, the count starts at the window's `spend_usd` so far. Sandboxes that are running keep running. Left out of a `PUT`, it is false: a `PUT` replaces the whole budget.
- `alert_thresholds` (list of integer, optional, default: [50,75,100]) — Percentages of `limit_usd` that send an alert when spend first reaches them. Whole numbers from 1 to 100, no repeats. Left out, `[50, 75, 100]`. An empty list sends no alerts.
- `notification_channel` (BudgetNotificationChannel, optional, nullable) — Where alert emails go, shaped as on OpenAI spend alerts. Null or left out sends no email. Webhook events are sent either way.
- `project_id` (string, optional, nullable) — The project
- `enforced_spend_usd` (double, optional, nullable) — The dollars counted against a budget with `hard_limit` in the current window: the number the 402 is decided on. Null when `hard_limit` is false. It can be above `spend_usd`: a call whose cost could not be measured is counted at the estimate that was held for it, and the usage records arrive a little later than the count.

## Errors

### 400 Bad Request Error

A field is missing or has a value Meadow does not accept. `param` names it.

- `error` (ErrorError, required)
- `request_id` (string, optional) — The same id as the `x-request-id` response header. Quote it when you report a problem.

### 401 Unauthorized Error

The key is missing, malformed, unknown, revoked, or expired, or a key it was minted from no longer exists. Check the key and the header.

- `error` (ErrorError, required)
- `request_id` (string, optional) — The same id as the `x-request-id` response header. Quote it when you report a problem.

### 403 Forbidden Error

The key does not have the `admin` scope. Use an admin key.

- `error` (ErrorError, required)
- `request_id` (string, optional) — The same id as the `x-request-id` response header. Quote it when you report a problem.

### 429 Too Many Requests Error

More than 20 failed authentications came from your address in one minute, and this request also failed to authenticate: fix the key, wait for `retry-after` seconds, then retry. Or the server instance was full and no slot came free for the account within 3 seconds (`error.code` `account_in_flight_limit_exceeded`): wait for `retry-after` seconds, then retry.

- `error` (ErrorError, required)
- `request_id` (string, optional) — The same id as the `x-request-id` response header. Quote it when you report a problem.

### 500 Internal Server Error

Meadow failed. Retry with backoff, and tell us if it persists.

- `error` (ErrorError, required)
- `request_id` (string, optional) — The same id as the `x-request-id` response header. Quote it when you report a problem.

## Types

### BudgetWriteNotificationChannel

Where alert emails go, shaped as on OpenAI spend alerts. Null or left out sends no email. Webhook events are sent either way.

- `type` (enum, required) — Always `email`.
  - Allowed values: `email`
- `recipients` (list of string, required) — Addresses that get the alert. At most 20.

### BudgetNotificationChannel

Where alert emails go, shaped as on OpenAI spend alerts. Null or left out sends no email. Webhook events are sent either way.

- `type` (enum, required) — Always `email`.
  - Allowed values: `email`
- `recipients` (list of string, required) — Addresses that get the alert. At most 20.

### ErrorError

- `type` (enum, required) — The class of the failure. - `invalid_request`: the request is malformed or breaks a rule (400), or is too large (413). - `conflict`: the request is valid and the current state refuses it (409). Before 2026-11-24 a 409 used `invalid_request`. - `unauthorized`: the key is missing, unknown, revoked, or expired (401). - `forbidden`: the key's scope or limit does not allow this, or the project's routing is locked (403). - `not_found`: no such resource or route (404). - `no_provider_key`: no stored credential can serve this request (422). - `all_providers_failed`: every vendor in the route was tried (502). - `provider_error`: a vendor failed and no fallback was possible (502). - `rate_limited`: too many requests (429). - `insufficient_quota`: a dollar `limit` on the key, or on a key above it, is spent (402). The name is OpenAI's. - `unavailable`: a dependency Meadow needs is not set up (503). - `internal`: Meadow failed (500), or the feature is not set up (501).
  - Allowed values: `invalid_request`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `no_provider_key`, `all_providers_failed`, `provider_error`, `rate_limited`, `insufficient_quota`, `unavailable`, `internal`
- `message` (string, required) — A sentence for people. It can change, so do not match on it.
- `code` (string, optional) — A stable name for the specific failure. Every Meadow error carries one. `type` stays the general class, and several codes share a type. Branch on `code` when you need to tell two failures of one type apart, for example `api_key_expired` from `api_key_revoked`. The full list is in the Errors guide. A new code can be added at any time, so treat a code you do not know as its `type`. A spent limit (`key_request_limit_exceeded`, `key_token_limit_exceeded`) stays a 403 and not a 429, so a client that retries a 429 does not resend a call a spent key can never make. A spent dollar `limit` (`key_spend_limit_exceeded`) is a 402 for the same reason.
- `param` (string, optional) — The request field, query parameter or header the error is about, when there is one. A nested field is written with dots, such as `credentials.api_key`. Set on most validation errors (400).
- `attempts` (list of Attempt, optional) — The vendors Meadow tried for this request, in order. Present only when it tried at least one.
- `retry` (enum, optional) — Whether to send the same request again. Set on routes under `/v1/sandboxes` only. The values are BoxRouter's (https://boxrouter.ai/docs/error-codes). - `safe`: send the same request again, after `retry-after` seconds when the response has that header. A 429, a 409 `exec_start_in_progress` or `idempotency_request_in_progress`, a 502 `sandbox_unreachable`, and a 5xx on a `GET`, `PUT` or `DELETE`, on `POST /v1/sandboxes/route`, or on a sandbox create or background command start sent with `Idempotency-Key`. - `after_fix`: change the request, the key or the account first. Any other 4xx. - `check_outcome`: read the sandbox or the command before you send it again, because the work may have happened. A 5xx on any other `POST`, which includes a blocking command. - `never`: do not send it again. A 501. When the response has `x-should-retry`, `retry` is `safe` exactly when the header is `true`.
  - Allowed values: `safe`, `after_fix`, `check_outcome`, `never`
- `outcome` (enum, optional) — What happened to the work. Set on routes under `/v1/sandboxes` only. The values are BoxRouter's (https://boxrouter.ai/docs/error-codes). - `not_started`: nothing was changed. Every 4xx, a 501, and a 502 `sandbox_unreachable`. - `unknown`: the work may have happened. Any other 5xx. - `completed` and `partial`: the work happened, in whole or in part. Meadow does not send them today. Handle them as `unknown`. A sandbox create that fails after Meadow accepted it is not an error response: the create returns 202, and the sandbox later has `status` `failed` and a `failure_reason`.
  - Allowed values: `not_started`, `completed`, `partial`, `unknown`

### Attempt

One try at one vendor, for a model call or a sandbox create.

- `provider` (enum, required) — The name of a vendor. Model providers and sandbox providers share one list. Model providers: `anthropic`, `openai`, `google`, `xai`, `azure`, `bedrock`, `vertex`, `openrouter`, `fireworks`, `deepseek`. Sandbox providers: `daytona`, `modal`.
  - Allowed values: `anthropic`, `openai`, `google`, `xai`, `azure`, `bedrock`, `vertex`, `openrouter`, `fireworks`, `deepseek`, `daytona`, `modal`
- `outcome` (enum, required) — How the try ended. - `served`: this vendor served the request. - `unsupported`: the vendor cannot do what was asked, such as a resource size, a network rule, or a model it does not offer. - `refused`: the vendor rejected the request or the stored credential. - `no_capacity`: the vendor had no capacity. - `timeout`: the vendor did not answer in time. - `rate_limited`: the vendor answered 429. - `error`: any other failure.
  - Allowed values: `served`, `unsupported`, `refused`, `no_capacity`, `timeout`, `rate_limited`, `error`
- `reason` (enum, optional) — A stable code for why the try ended as it did. It is narrower than `outcome`, and it is the code to branch on or to count. More values can be added: treat one you do not know like `vendor_error`. - `served`: this vendor served the request. - `no_capacity`: the vendor had no capacity. - `quota_exceeded`: the vendor account is out of quota or credit. - `rate_limited`: the vendor answered 429. - `timeout`: the vendor did not answer in time. - `auth_failed`: the vendor rejected the stored vendor key. - `invalid_request`: the vendor rejected the request itself. - `refused`: the vendor refused for another reason. - `unsupported`: the vendor cannot do what was asked, such as a model, a GPU type, a size or a network rule. - `no_provider_key`: skipped, because no usable vendor key was stored. - `image_pull_failed`, `build_failed`: the vendor could not pull or build the image (sandboxes). - `provider_lost`: the vendor lost the sandbox while it was starting. - `vendor_error`: any other failure.
  - Allowed values: `served`, `no_capacity`, `quota_exceeded`, `rate_limited`, `timeout`, `auth_failed`, `invalid_request`, `refused`, `unsupported`, `no_provider_key`, `image_pull_failed`, `build_failed`, `provider_lost`, `vendor_error`
- `started_at` (datetime, optional) — When Meadow started this try. Absent on attempts recorded before 2026-11-24.
- `finished_at` (datetime, optional) — When this try ended.
- `detail` (string, optional) — A short description of what happened, written by Meadow, such as `provider returned HTTP 404`. On a `served` sandbox attempt it reports resources the vendor granted that differ from the request, such as `provider granted cpu 2 instead of 1.5` or `gpu type H200 instead of H100`. It says `provider built a copy of the image for this size` when this create made a new Daytona snapshot for an `image_id`. On an `unsupported` attempt it carries the vendor's size limit, such as `daytona cannot serve this size: CPU request 8 exceeds maximum allowed per sandbox (4)`. Absent when there is nothing to say.
- `duration_ms` (integer, optional) — How long the try took, in milliseconds.

## Examples

**Request**

```json
{
  "limit_usd": 500,
  "reset_interval": "monthly",
  "alert_thresholds": [
    50,
    75,
    100
  ],
  "notification_channel": {
    "type": "email",
    "recipients": [
      "ops@example.com"
    ]
  }
}
```

**Response**

```json
{
  "limit_usd": 500,
  "reset_interval": "daily",
  "id": "string",
  "object": "budget",
  "scope": "account",
  "spend_usd": 1.1,
  "remaining_usd": 1.1,
  "resets_at": "2024-01-15T09:30:00Z",
  "unknown_cost_records": 1,
  "created_at": "2024-01-15T09:30:00Z",
  "updated_at": "2024-01-15T09:30:00Z",
  "hard_limit": true,
  "alert_thresholds": [
    1
  ],
  "notification_channel": {
    "type": "email",
    "recipients": [
      "string"
    ]
  },
  "project_id": "string",
  "enforced_spend_usd": 1.1
}
```

**SDK Code**

```python 500 dollars a month, alerts at 50, 75 and 100 percent
import requests

url = "https://api.example.com/v1/budget"

payload = {
    "limit_usd": 500,
    "reset_interval": "monthly",
    "alert_thresholds": [50, 75, 100],
    "notification_channel": {
        "type": "email",
        "recipients": ["ops@example.com"]
    }
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.put(url, json=payload, headers=headers)

print(response.json())
```

```javascript 500 dollars a month, alerts at 50, 75 and 100 percent
const url = 'https://api.example.com/v1/budget';
const options = {
  method: 'PUT',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"limit_usd":500,"reset_interval":"monthly","alert_thresholds":[50,75,100],"notification_channel":{"type":"email","recipients":["ops@example.com"]}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go 500 dollars a month, alerts at 50, 75 and 100 percent
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.example.com/v1/budget"

	payload := strings.NewReader("{\n  \"limit_usd\": 500,\n  \"reset_interval\": \"monthly\",\n  \"alert_thresholds\": [\n    50,\n    75,\n    100\n  ],\n  \"notification_channel\": {\n    \"type\": \"email\",\n    \"recipients\": [\n      \"ops@example.com\"\n    ]\n  }\n}")

	req, _ := http.NewRequest("PUT", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby 500 dollars a month, alerts at 50, 75 and 100 percent
require 'uri'
require 'net/http'

url = URI("https://api.example.com/v1/budget")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"limit_usd\": 500,\n  \"reset_interval\": \"monthly\",\n  \"alert_thresholds\": [\n    50,\n    75,\n    100\n  ],\n  \"notification_channel\": {\n    \"type\": \"email\",\n    \"recipients\": [\n      \"ops@example.com\"\n    ]\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java 500 dollars a month, alerts at 50, 75 and 100 percent
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://api.example.com/v1/budget")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"limit_usd\": 500,\n  \"reset_interval\": \"monthly\",\n  \"alert_thresholds\": [\n    50,\n    75,\n    100\n  ],\n  \"notification_channel\": {\n    \"type\": \"email\",\n    \"recipients\": [\n      \"ops@example.com\"\n    ]\n  }\n}")
  .asString();
```

```php 500 dollars a month, alerts at 50, 75 and 100 percent
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api.example.com/v1/budget', [
  'body' => '{
  "limit_usd": 500,
  "reset_interval": "monthly",
  "alert_thresholds": [
    50,
    75,
    100
  ],
  "notification_channel": {
    "type": "email",
    "recipients": [
      "ops@example.com"
    ]
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp 500 dollars a month, alerts at 50, 75 and 100 percent
using RestSharp;

var client = new RestClient("https://api.example.com/v1/budget");
var request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"limit_usd\": 500,\n  \"reset_interval\": \"monthly\",\n  \"alert_thresholds\": [\n    50,\n    75,\n    100\n  ],\n  \"notification_channel\": {\n    \"type\": \"email\",\n    \"recipients\": [\n      \"ops@example.com\"\n    ]\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 500 dollars a month, alerts at 50, 75 and 100 percent
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "limit_usd": 500,
  "reset_interval": "monthly",
  "alert_thresholds": [50, 75, 100],
  "notification_channel": [
    "type": "email",
    "recipients": ["ops@example.com"]
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/budget")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```