API / list-payment-methods-via-management-api

API

List payment methods via the xAI Management API

List the payment methods on file for a team over HTTP when prepaid top-ups, failed charger attempts, or runbooks need to confirm which card or bank account will be charged before you spend. Official Billing Management documents GET /v1/billing/teams/{team_id}/payment-method on https://management-api.x.ai, authorized with a management key, and POST /v1/billing/teams/{team_id}/payment-method/default to select an existing method as default. Docs state you add or delete payment methods on console.x.ai; the Management routes cover list and default selection. 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 in the path, and at least one payment method already saved in Console when you expect a non-empty list. Response objects include paymentMethodId, billing address fields, redacted cardDetails (brand, exp month/year, last4), optional ACH or Link details, and paymentType. A pendingPaymentMethod object may appear for incomplete adds, including an ACH microdeposit verification URL when that flow is in progress. Neighboring spend jobs include Top up prepaid credits via the xAI Management API, Purchase prepaid credits on the xAI Console, and List invoices via the xAI Management API. More API jobs live on the API hub.

List methods and set the default

  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. List payment methods for the team:
curl "https://management-api.x.ai/v1/billing/teams/${XAI_TEAM_ID}/payment-method" \
  -H "Authorization: Bearer ${XAI_MANAGEMENT_KEY}"
  1. For each entry in paymentMethods, record paymentMethodId, paymentType, and the redacted card or bank fields you need for ops tickets. Never log full PAN data; the API only returns redacted card details handled by third-party processors. If pendingPaymentMethod is present, open achMicrodepositHostedVerificationUrl when ACH verification is still required.

  2. Set the default method when prepaid top-up or monthly invoiced charges should hit a different on-file method. Post the chosen id:

curl "https://management-api.x.ai/v1/billing/teams/${XAI_TEAM_ID}/payment-method/default" \
  -X POST \
  -H "Authorization: Bearer ${XAI_MANAGEMENT_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "paymentMethodId": "pm_xxxxxxxxxxxxxxxxxxxxxxxx"
  }'

A successful default change returns an empty JSON object per the docs example. Add a new card or bank only in Console under Billing → Billing details → Add Payment Information, matching Manage Billing. Console currently does not let you remove the last payment method on file.

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

Use methods before you charge

Run the list endpoint in the same runbook that calls prepaid top-up so you fail fast when no default method exists. After a FAILED charger attempt on an invoice, compare paymentMethodId on the attempt against the list and switch default only after finance approves the replacement card. Pair with Preview a postpaid invoice via the xAI Management API when you need the current cycle draft amounts before the charge lands.

Pitfalls

Treating redacted last4 fields as proof you hold the physical card still leaves you unable to complete Console add flows that need the real instrument. Calling default-set with a typo’d paymentMethodId leaves the previous default charging quietly. Expecting Management API to delete the sole remaining method conflicts with Console policy that blocks removing the last method. Mixing consumer payment screens on grok.com with these team Management methods confuses which product will be billed.