Skip to contentSkip to page list

Docs

Create budget

Creates an organization-owned budget across all seven scope types. Spend is counted from the moment the budget is created, so spend earlier in the current window is not included. Requires gatewayBudgets:create at the organization; a project key or an organization key may call it.

POST/api/gateway/v1/budgets
Request and response examples
request.py
import osimport requests​origin = "https://app.langwatch.ai"path = "/api/gateway/v1/budgets"api_key = os.environ["LANGWATCH_API_KEY"]headers = {    "X-Auth-Token": api_key,    "Content-Type": "application/json",}payload = {}​response = requests.post(    origin + path,    headers=headers,    json=payload,)print(response.json())

Success

application/json · Generated from schema

{  "budget": {    "id": "string",    "organization_id": "string",    "scope_type": "organization",    "scope_id": "string",    "name": "string",    "description": "string",    "window": "minute",    "on_breach": "block",    "limit_usd": "string",    "limit_nano_usd": -9007199254740991,    "spent_usd": "string",    "spent_nano_usd": -9007199254740991,    "timezone": "string",    "provider_key": "string",    "external_id": "string",    "metadata": {},    "current_period_started_at": "string",    "resets_at": "string",    "cycle_anchor_at": "string",    "last_reset_at": "string",    "archived_at": "string",    "created_at": "string",    "member_count": -9007199254740991,    "end_users_seen": -9007199254740991,    "end_users_over": -9007199254740991,    "scope_reach": "reachable"  }}
api-reference/gateway-budgets/create-budget

Authorization

X-Auth-Tokenstringheaderrequired

Project API key for sending traces and accessing project-scoped resources. Format: sk-lw-... (no underscore). Obtain one by creating a project via the Admin API or the LangWatch UI.

Headers

Idempotency-Keystring

A caller-chosen key, 8 to 255 characters, that makes this create safe to retry. The first request to use a key runs normally and its response is stored for 24 hours. A later request with the same key and the same body is not executed again: it returns the stored response, marked with X-Idempotent-Replay: true. The same key with a different body is refused 409 idempotency_error, as is a retry sent while the original is still running. Only successful responses are stored, so a create that failed can simply be retried with the same key.

At least 8 charactersUp to 255 characters

Request body

application/json · Required

scopeobjectrequired
Option 1kind: "organization"object
kindstringrequired
Always"organization"
organization_idstringrequired
Option 2kind: "team"object
kindstringrequired
Always"team"
team_idstringrequired
Option 3kind: "project"object
kindstringrequired
Always"project"
project_idstringrequired
Option 4kind: "virtual_key"object
kindstringrequired
Always"virtual_key"
virtual_key_idstringrequired
Option 5kind: "principal"object
kindstringrequired
Always"principal"
principal_user_idstringrequired
Option 6kind: "group"object
kindstringrequired
Always"group"
group_idstringrequired
Option 7kind: "attributed_user"object
kindstringrequired
Always"attributed_user"
anchor_virtual_key_idstring
anchor_project_idstring
namestringrequired
At least 1 characterUp to 128 characters
descriptionstring
windowstringrequired
One of"minute""hour""day""week""month""total""manual"
limit_usdnumber | stringrequired
Option 1number
Option 2string
on_breachstring
One of"block""warn"
timezonestring | null
provider_keystring | null
external_idstring | null
Option 1string
Option 2null
metadataobject
cycle_anchor_atstring (date-time)
Pattern ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|([+-](?:[01]\d|2[0-3]):[0-5]\d)))$
allow_unreachableboolean

Responses

201

Success

application/json

budgetobjectrequired
idstringrequired
organization_idstringrequired
scope_typestringrequired
One of"organization""team""project""virtual_key""principal""group""attributed_user"
scope_idstringrequired
namestringrequired
descriptionstring | nullrequired
windowstringrequired
One of"minute""hour""day""week""month""total""manual"
on_breachstringrequired
One of"block""warn"
limit_usdstringrequired

Display value. Decimal string, up to 9 fractional digits, trailing zeros trimmed, never exponent notation. Use limit_nano_usd for arithmetic.

limit_nano_usdinteger | nullrequired
spent_usdstring | nullrequired
spent_nano_usdinteger | nullrequired
timezonestring | nullrequired
provider_keystring | nullrequired
external_idstring | nullrequired
metadataobjectrequired
current_period_started_atstringrequired
resets_atstringrequired
cycle_anchor_atstring | nullrequired
last_reset_atstring | nullrequired
archived_atstring | nullrequired
created_atstringrequired
member_countinteger
Minimum -9007199254740991Maximum 9007199254740991
end_users_seeninteger
Minimum -9007199254740991Maximum 9007199254740991
end_users_overinteger
Minimum -9007199254740991Maximum 9007199254740991
scope_reachstring
One of"reachable""unreachable"
400

Bad Request

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
401

Unauthorized

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
403

Forbidden

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
409

Conflict

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
500

Internal Server Error

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]

Documentation