Management API

Billing Management


Get billing information

/v1/billing/teams/{team_id}/billing-info

Get billing information of the team with given team ID.

Path parameters

team_id

string

required

Team ID of the team.

Response Body

billingInfo

object

Billing info.


Set billing information

/v1/billing/teams/{team_id}/billing-info

Set billing information of a team.

Path parameters

team_id

string

required

Team ID of the team.

Request Body


List Invoices

/v1/billing/teams/{team_id}/invoices

List invoices that belong to a team.

Path parameters

team_id

string

required

Team ID of the team.

Query parameters

billingCycle.year

integer

billingCycle.month

integer

since.year

integer

since.month

integer

invoiceIds.invoiceIds

array

Response Body

invoices

array

Invoices.


List payment methods

/v1/billing/teams/{team_id}/payment-method

List payment methods of a team. You can add or delete the payment methods on https://console.x.ai.

Path parameters

team_id

string

required

Team ID of the team.

Response Body

paymentMethods

array

Payment methods on file.

pendingPaymentMethod

object

Represents an incomplete attempt to add a payment method. Might resolve into a payment method.


Set default payment method

/v1/billing/teams/{team_id}/payment-method/default

Set default payment method to an existing payment method on file.

Path parameters

team_id

string

required

Team ID of the team.

Request Body


Preview postpaid invoice of the month

/v1/billing/teams/{team_id}/postpaid/invoice/preview

Preview the amount to pay for postpaid usage in the current billing period.

Path parameters

team_id

string

required

Team ID of the team.

Response Body

coreInvoice

object

The invoice object.

effectiveSpendingLimit

string

The effective current spending limit in USD cents.

defaultCredits

string

The current default credits in USD cents.

billingCycle

object


Get monthly postpaid spending limits

/v1/billing/teams/{team_id}/postpaid/spending-limits

Get the postpaid monthly spending limits. The API will stop functioning once the team has consumed all of the prepaid credits, and the postpaid usage amount has reached the user-set soft spending limit.

Path parameters

team_id

string

required

Team ID of the team.

Response Body

spendingLimits

object

Postpaid monthly spending limit.
Override might not exist, hence optional (actually, this comes from either default hard_spending_limit override or monthly hard_spending_limit override).


Set monthly postpaid spending limits

/v1/billing/teams/{team_id}/postpaid/spending-limits

Set the postpaid monthly spending limit of a team. This can be used to restrict the maximum amount of postpaid API usage. Note this will not limit the amount of prepaid credit usage, and prepaid credits will always be consumed before accruing postpaid usage. To use only prepaid credits, you can set this limit to 0.

Path parameters

team_id

string

required

Team ID.

Request Body

Response Body

thisBpSoftSpendingLimit

object

Representation of USD Cents.


List prepaid credit balance and balance changes

/v1/billing/teams/{team_id}/prepaid/balance

List the prepaid credit balance and balance changes of a team.

Path parameters

team_id

string

required

The team ID of the team.

Response Body

changes

array

The changes of the prepaid credit balance.

total

object

Representation of USD Cents.


Top up prepaid credit

/v1/billing/teams/{team_id}/prepaid/top-up

Top up prepaid credit using the default payment method.

Path parameters

team_id

string

required

Team ID of the team to top up for.

Request Body

Response Body

change

object

Change item on the prepaid credit balance.


Daily token usage

POST /v1/billing/teams/{team_id}/usage returns your team's usage as time series, bucketed by time and optionally grouped by fields such as token type and model. It reads the same data as Usage Explorer. Authenticate with a management key.

Choose what to measure with values[].name. Each value supports only AGGREGATION_SUM.

ValueMeasures
usdCost in USD
unitsTokens for token unit types; other units, such as images or audio seconds, for the rest
itemsBilling items; one request produces an item for each priced dimension
transactionsRequests

You can group and filter by unit_type, description, api_key_id, product, request_ip, user_id, and unit_price. unit_type is the token type, such as Prompt text tokens, Cached prompt text tokens, Completion text tokens, or Reasoning text tokens. Prompt text tokens counts only uncached input; cached input is reported as Cached prompt text tokens. description is the product name followed by the billed resource, usually the model.

The following request returns daily token counts for each token type and model:

Bash

curl https://management-api.x.ai/v1/billing/teams/{team_id}/usage \
  -X POST \
  -H "Authorization: Bearer $XAI_MANAGEMENT_KEY" \
  -H "Content-Type: application/json" \
  -d '{
        "analyticsRequest": {
          "timeRange": {
            "startTime": "2026-10-26 00:00:00",
            "endTime": "2026-11-03 00:00:00",
            "timezone": "Etc/GMT"
          },
          "timeUnit": "TIME_UNIT_DAY",
          "values": [{ "name": "units", "aggregation": "AGGREGATION_SUM" }],
          "groupBy": ["unit_type", "description"],
          "filters": []
        }
      }'

The response has one entry in timeSeries for each combination of group values. Its group array lists those values in groupBy order, so here the token type comes first and the description second. dataPoints has one entry per day in the range, and values[0] holds that day's token count.

  • startTime and endTime use the format YYYY-MM-DD HH:MM:SS in the IANA time zone given by timezone, which also sets the day boundaries. endTime is exclusive.
  • Keep unit_type in groupBy when you measure units. Grouping by description alone adds every unit type for a model into one number.
  • If limitReached is true, the response hit its row limit and may be incomplete; shorten the time range or group by fewer fields.
  • An unknown value or field name returns HTTP 400.

Split long- vs short-context tokens

Long-context requests are billed at higher rates (see Pricing), but their tokens are reported under the same unit_type and description as other tokens. To separate them, add unit_price to groupBy in the request above so that each price gets its own time series:

JSON

"groupBy": ["unit_type", "description", "unit_price"]

unit_price is measured in 1e-10 USD per unit, so dividing it by 10,000 gives USD per million tokens; "25000" is $2.50 per million tokens. Match each series to the model's standard and long-context rates to tell them apart. A token type and model can have other series too, for example from US regional endpoint rates, custom pricing, or a price change during the time range. To return only some prices, filter on unit_price, e.g., "filters": ["unit_price:>12500"].


Get historical usage of the API

/v1/billing/teams/{team_id}/usage

To measure tokens instead of cost, use the value units. Daily token usage lists every accepted value and field.

Get historical usage of the API (spend, token and other unit counts) over a time period, bucketed by time and grouped by fields. For daily token counts, sum units per day grouped by unit_type.

Path parameters

team_id

string

required

The team whose billing records to analyze.

Request Body

Response Body

timeSeries

array

For each value of the group-by clause, we return one time series.

limitReached

boolean

If this is true, the maximum cardinality of the query has been reached and only a subset of results is returned.


Last updated: November 3, 2026