Payment Methods
On this page
Manage your payment methods
The Management API lets you view registered cards and set the default payment method for automatic charges. Managing this is essential to avoid service interruptions caused by failed payments.
View payment methods
Managing cards via the API has one practical goal, but it’s critical: detect a card about to expire before a charge fails. A failed invoice isn’t just an isolated financial incident—it leads to service suspension, essentially a production outage originating in accounting.
curl "https://management-api.x.ai/v1/billing/teams/$TEAM_ID/payment-method" \
-H "Authorization: Bearer $MANAGEMENT_API_KEY"
The response contains information for each card: type (Visa, Mastercard, etc.), the last 4 digits, the expiration date, and the status (active, default).
Set the default payment method
To change the card used for automatic charges:
curl -X POST "https://management-api.x.ai/v1/billing/teams/$TEAM_ID/payment-method/default" \
-H "Authorization: Bearer $MANAGEMENT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"paymentMethodId": "pm_abc123"
}'
The paymentMethodId is the identifier returned by the view endpoint. The change takes effect for upcoming charges—not those already in progress. If an invoice status changes to FAILED, switching the default card doesn’t automatically retry it: fix the payment method, then check the status of the affected invoice.
Accepted cards
xAI accepts a wide range of payment cards for the API:
- Visa
- Mastercard
- American Express (AMEX)
- Discover
- JCB
- UnionPay
Important restriction: Indian cards
Payment cards issued in India are not accepted for using the xAI API. This restriction applies only to the API—payments for the consumer Grok service (via grok.com or mobile apps) are not affected by this limitation.
If you are based in India and want to use the API, you must use a card issued in another country or explore other payment options.
Payment management best practices
Keep a backup card
Register at least two payment methods, preferably on two different accounts. The scenario this covers is common and costly: the company card gets replaced, no one thinks to include the API in the list of subscriptions to update, and the service stops three weeks later. A failed payment (FAILED status) can lead to temporary suspension of your API keys.
Monitor expirations
Regularly check the expiration dates of your registered cards. Update cards before they expire to avoid any interruption.
Payment alerts
Combine invoice viewing (GET /invoices) with an alert script:
import requests
MANAGEMENT_API = "https://management-api.x.ai"
MGMT_KEY = "xai-mgmt-..."
TEAM_ID = "team-..."
response = requests.get(
f"{MANAGEMENT_API}/v1/billing/teams/{TEAM_ID}/invoices?billingCycle.year=2026&billingCycle.month=4",
headers={"Authorization": f"Bearer {MGMT_KEY}"}
)
invoices = response.json()
for invoice in invoices.get("invoices", []):
if invoice.get("status") == "FAILED":
print(f"ALERT: invoice {invoice['id']} failed!")
# Send a notification (email, Slack, etc.)
Integrate into your infrastructure
Automated verification
Integrate periodic payment status verification into your monitoring:
# Monthly verification script
#!/bin/bash
RESPONSE=$(curl -s "https://management-api.x.ai/v1/billing/teams/$TEAM_ID/payment-method" \
-H "Authorization: Bearer $MANAGEMENT_API_KEY")
# Check if a default card is active
echo "$RESPONSE" | python3 -c "
import sys, json
data = json.load(sys.stdin)
methods = data.get('paymentMethods', [])
if not methods:
print('ALERT: no payment method registered')
sys.exit(1)
default = [m for m in methods if m.get('isDefault')]
if not default:
print('ALERT: no default payment method')
sys.exit(1)
print('OK: default payment method active')
"
Key takeaways
GET /v1/billing/teams/{teamId}/payment-methodlists registered cardsPOST /v1/billing/teams/{teamId}/payment-method/defaultsets the default card- Visa, Mastercard, AMEX, Discover, JCB, and UnionPay cards are accepted
- Indian cards are not accepted for the API (but work for grok.com)
- Always keep at least two cards registered to avoid interruptions
- Monitor FAILED statuses in your invoices to detect payment issues