API / get-postpaid-spending-limits-via-management-api

API

Get postpaid spending limits via the xAI Management API

Read the team's current postpaid monthly spending limits over HTTP when prepaid credits are low, invoiced billing is enabled, or a runbook must confirm the soft and hard caps before more API spend accrues. Official Billing Management documents GET /v1/billing/teams/{team_id}/postpaid/spending-limits on https://management-api.x.ai, authorized with a management key. The docs note the API stops serving once prepaid credits are exhausted and postpaid usage reaches the user-set soft spending limit. Create the management key first with Create a management key in the xAI Console if you do not already have one.

What you need

A management key that can call billing routes for the team, the team id from Console Settings → Team, and awareness that amounts in the response are USD cents representations under nested val fields. Neighboring spend jobs include Set postpaid spending limits via the xAI Management API, Preview a postpaid invoice via the xAI Management API, and Check prepaid credit balance via the xAI Management API. More API jobs live on the API hub.

Get the current limits

  1. Export the management key and team id outside of source control:
export XAI_MANAGEMENT_KEY="your_management_key"
export XAI_TEAM_ID="your_team_id"
  1. Get postpaid spending limits for the team:
curl "https://management-api.x.ai/v1/billing/teams/${XAI_TEAM_ID}/postpaid/spending-limits" \
  -H "Authorization: Bearer ${XAI_MANAGEMENT_KEY}"
  1. Read the spendingLimits object. Documented fields include softSl and effectiveSl (soft spending limit), plus hard-limit fields such as hardSlOverride, hardSlAuto, and effectiveHardSl, each carrying a val string in USD cents. Overrides may be absent, so treat missing hard-override objects as optional per the reference. Compare effectiveSl to the preview totals from Preview a postpaid invoice via the xAI Management API when you need to know how close the current cycle sits to the soft cap.

  2. Raise or lower the soft limit only through Set postpaid spending limits via the xAI Management API with desiredSoftSpendingLimit.val in USD cents. Console Billing → API Credits remains the staff path for the same invoiced billing limit story described in Manage Billing. Setting the soft limit to 0 keeps the team on prepaid-only behavior once credits are gone.

Keep every call on https://management-api.x.ai. An inference API key against https://api.x.ai will not answer billing routes.

Use limits before you spend

Run this GET in the same checklist that reads prepaid balance and the postpaid invoice preview so finance sees soft cap, hard effective limit, remaining prepaid, and draft postpaid amount together. After a set call, re-GET to confirm effectiveSl matches the value you posted. Pair with Top up prepaid credits via the xAI Management API when the soft limit is already binding and prepaid top-up is the faster unblock.

Pitfalls

Reading val as dollars instead of USD cents misstates the cap by two orders of magnitude. Treating a missing hardSlOverride as a zero hard limit when hardSlAuto or effectiveHardSl still carries a value understates the real ceiling. Expecting GET to change limits without the POST set route leaves the soft cap untouched. Mixing consumer Grok subscription billing with these team Management limits confuses which product will reject traffic.