> To find and run AgentRouter tools, connect to https://mcp.agentrouter.to/. To search this documentation, use https://docs.agentrouter.to/_mcp/server. Append .md to a page URL for Markdown. For the documentation index, see https://docs.agentrouter.to/llms.txt.

# Create a budget

POST https://api.agentrouter.to/v1/budgets
Content-Type: application/json

Requires the `manage` scope. A budget sets a per-call maximum, a limit per period, or both.

Reference: https://docs.agentrouter.to/api-reference/agent-router-api/budgets/create-budget

## Authentication

- `Authorization` header (bearer token, required) — An AgentRouter API key or an OAuth access token issued to an MCP host or the CLI.

## Request

### Body (application/json)

This endpoint expects a BudgetRequest.

- `name` (string, optional)
- `scope` (enum, optional, default: account)
  - Allowed values: `account`, `key`, `session`
- `scope_ref` (string, optional, nullable) — Key id or session id for key and session budgets.
- `period` (enum, optional, default: month)
  - Allowed values: `day`, `week`, `month`, `total`
- `limit_usd` (string, optional, nullable) — Spend limit per period.
- `per_call_max_usd` (string, optional, nullable) — Caps max_cost_usd for every call in scope.
- `status` (enum, optional)
  - Allowed values: `active`, `disabled`

## Response

### 201

The budget

- `budget_id` (string, required)
- `name` (string, required, nullable)
- `scope` (enum, required)
  - Allowed values: `account`, `key`, `session`
- `scope_ref` (string, required, nullable)
- `period` (enum, required)
  - Allowed values: `day`, `week`, `month`, `total`
- `limit_usd` (string, required, nullable)
- `per_call_max_usd` (string, required, nullable)
- `status` (enum, required)
  - Allowed values: `active`, `disabled`
- `created_at` (string, required)

## Errors

### 400 Bad Request Error

Invalid request (for example INVALID_REQUEST, INPUT_INVALID, PRICING_VERSION_REQUIRED, PRICE_NOT_CLIENT_SETTABLE). Nothing was executed.

- `error` (ErrorError, required)
- `run` (Run, optional) — The receipt for one invocation. Run status, provider outcome and billing are separate facts.

### 403 Forbidden Error

The credential lacks a scope (INSUFFICIENT_SCOPE)

- `error` (ErrorError, required)
- `run` (Run, optional) — The receipt for one invocation. Run status, provider outcome and billing are separate facts.

## Types

### ErrorError

- `code` (string, required)
- `message` (string, required)
- `hints` (list of Hint, required)
- `details` (map from string to any, required)

### Run

The receipt for one invocation. Run status, provider outcome and billing are separate facts.

- `object` (any, required)
- `run_id` (string, required)
- `status` (enum, required)
  - Allowed values: `READY`, `RUNNING`, `STOPPING`, `COMPLETED`, `FAILED`, `BLOCKED`, `STOPPED`, `TIMED_OUT`
- `tool_id` (string, required)
- `tool_version` (string, required)
- `provider` (string, required)
- `input` (any, required) — The submitted tool input
- `session_id` (string, required, nullable)
- `caller` (RunCaller, required)
- `channel` (enum, required)
  - Allowed values: `http`, `cli`, `mcp`, `web`
- `created_at` (string, required, nullable)
- `started_at` (string, required, nullable)
- `completed_at` (string, required, nullable)
- `latency_ms` (integer, required, nullable)
- `replayed` (boolean, required) — True when an idempotency key returned an existing run.
- `stoppable` (boolean, required)
- `provider_response` (RunProviderResponse, required)
- `error` (RunError, required, nullable)
- `billing` (RunBilling, required)
- `result` (RunResult, required)
- `next_cursor` (string, required, nullable) — Pass back as the tool's cursor input for the next page (a new billed call).
- `hints` (list of Hint, required)
- `output` (any, required) — The provider's output exactly as returned

### Hint

- `code` (string, required) — Machine-readable next step, e.g. POLL_RUN, DESCRIBE_TOOL, TOP_UP, NEXT_PAGE.
- `message` (string, required)
- `params` (map from string to any, optional)

### RunCaller

- `type` (enum, required)
  - Allowed values: `api_key`, `oauth`, `session`
- `name` (string, required)

### RunProviderResponse

- `http_status` (integer, required, nullable)
- `outcome` (enum, required)
  - Allowed values: `success`, `empty`, `provider_error`, `pending`
- `status` (string, required, nullable)
- `request_id` (string, required, nullable)
- `task_id` (string, required, nullable)

### RunError

- `code` (string, required)
- `message` (string, required)
- `origin` (enum, required)
  - Allowed values: `provider`, `platform`, `client`
- `retryable` (boolean, required, nullable)
- `details` (RunErrorDetails, optional, nullable) — Sanitized provider error evidence. Absent for old runs and errors without an upstream response.

### RunBilling

- `status` (enum, required)
  - Allowed values: `none`, `reserved`, `settled`, `refunded_partial`, `refunded_full`
- `reason` (enum, required) — Why the charge is what it is. A zero charge always carries a reason.
  - Allowed values: `charged`, `charged_capped`, `free_promotion`, `zero_base`, `waived_provider_error`, `waived_platform_error`, `waived_empty_result`, `waived_stopped`, `waived_timeout`, `waived_unknown_cost`, `blocked_before_execution`
- `currency` (any, required)
- `pricing_version` (string, required)
- `price_multiplier` (string, required, nullable)
- `promotion_id` (string, required, nullable)
- `max_cost_usd` (string, required) — Exact USD amount as a decimal string.
- `reserved_usd` (string, required) — Exact USD amount as a decimal string.
- `base_charge_usd` (string, required, nullable) — Price before the multiplier.
- `customer_charge_usd` (string, required) — Exact USD amount as a decimal string.
- `customer_refund_usd` (string, required) — Exact USD amount as a decimal string.
- `net_charge_usd` (string, required) — Exact USD amount as a decimal string.
- `charge_is_new` (boolean, required) — False on an idempotent replay; nothing new was charged.
- `usage` (RunBillingUsage, required, nullable)

### RunResult

- `available` (boolean, required)
- `expired` (boolean, required) — True when a previously stored result has expired or is no longer present.
- `bytes` (integer, required, nullable)
- `expires_at` (string, required, nullable)
- `url` (string, required, nullable) — GET this to download the stored output; it never re-runs the tool.
- `inline` (boolean, required) — False when the output is too large to include; download it from url.

### RunErrorDetails

Sanitized provider error evidence. Absent for old runs and errors without an upstream response.

- `body` (string, required) — Provider response JSON text with credentials and internal pricing fields redacted; non-JSON bodies are omitted. Limited to 20000 characters.
- `truncated` (boolean, required) — True when only a prefix of the sanitized error was retained.

### RunBillingUsage

- `unit` (string, required)
- `quantity` (string, required, nullable)
- `status` (enum, required)
  - Allowed values: `known`, `none`, `unknown`

## Examples

**Request**

```json
{
  "name": "Research agent",
  "scope": "account",
  "period": "day",
  "limit_usd": "2",
  "per_call_max_usd": "0.05"
}
```

**Response**

```json
{
  "budget_id": "string",
  "name": "string",
  "scope": "account",
  "scope_ref": "string",
  "period": "day",
  "limit_usd": "string",
  "per_call_max_usd": "string",
  "status": "active",
  "created_at": "string"
}
```

**SDK Code**

```python Budgets_createBudget_example
import requests

url = "https://api.agentrouter.to/v1/budgets"

payload = {
    "name": "Research agent",
    "scope": "account",
    "period": "day",
    "limit_usd": "2",
    "per_call_max_usd": "0.05"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Budgets_createBudget_example
const url = 'https://api.agentrouter.to/v1/budgets';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"name":"Research agent","scope":"account","period":"day","limit_usd":"2","per_call_max_usd":"0.05"}'
};

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

```go Budgets_createBudget_example
package main

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

func main() {

	url := "https://api.agentrouter.to/v1/budgets"

	payload := strings.NewReader("{\n  \"name\": \"Research agent\",\n  \"scope\": \"account\",\n  \"period\": \"day\",\n  \"limit_usd\": \"2\",\n  \"per_call_max_usd\": \"0.05\"\n}")

	req, _ := http.NewRequest("POST", 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 Budgets_createBudget_example
require 'uri'
require 'net/http'

url = URI("https://api.agentrouter.to/v1/budgets")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"Research agent\",\n  \"scope\": \"account\",\n  \"period\": \"day\",\n  \"limit_usd\": \"2\",\n  \"per_call_max_usd\": \"0.05\"\n}"

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

```java Budgets_createBudget_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.agentrouter.to/v1/budgets")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Research agent\",\n  \"scope\": \"account\",\n  \"period\": \"day\",\n  \"limit_usd\": \"2\",\n  \"per_call_max_usd\": \"0.05\"\n}")
  .asString();
```

```php Budgets_createBudget_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.agentrouter.to/v1/budgets', [
  'body' => '{
  "name": "Research agent",
  "scope": "account",
  "period": "day",
  "limit_usd": "2",
  "per_call_max_usd": "0.05"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Budgets_createBudget_example
using RestSharp;

var client = new RestClient("https://api.agentrouter.to/v1/budgets");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"Research agent\",\n  \"scope\": \"account\",\n  \"period\": \"day\",\n  \"limit_usd\": \"2\",\n  \"per_call_max_usd\": \"0.05\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Budgets_createBudget_example
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "Research agent",
  "scope": "account",
  "period": "day",
  "limit_usd": "2",
  "per_call_max_usd": "0.05"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.agentrouter.to/v1/budgets")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
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()
```