Skip to main content
Use the user billing endpoints to read your team’s credit balance and buy top-ups with a saved payment method. Both endpoints require authentication with your API key. Invalid keys return 402.

Check credit balance

GET /user/credits/info returns the authenticated team’s credit balance, a per-lot breakdown, active subscription details, and whether usage is allowed. Use this endpoint to power billing widgets, usage dashboards, or pre-flight checks before running large jobs. For API details see Get credit info.

Response

Each lot in breakdown has a purchase_kind of Subscription, Top-up, Manual, Setup, or Pending.

Purchase a top-up

POST /user/purchase-topup charges a saved card on Stripe and buys credits in one step. There is no Checkout redirect or embedded payment UI. Pass the credit amount in the request body:
Supported values: 10,000, 20,000, 80,000, and 100,000. For API details see Purchase top-up.

Requirements

  • The team must have a Stripe customer with at least one saved card.
  • Only one purchase attempt is allowed every 60 seconds per team. If you hit the cooldown, the response is 429 with a Retry-After header.

Responses

200 — payment succeeded:
202 — payment is still processing. Credits are added once Stripe confirms the payment:
Credits are issued by the Stripe webhook after payment confirmation, not directly from the HTTP response. Treat 200 as payment success; poll GET /user/credits/info if you need to confirm the updated balance.

Common errors

Automatic refills

To keep your balance from running out, check it on a schedule and buy a top-up when it drops below a threshold. This uses the two endpoints above and works anywhere you can run a script: a cron job, a CI step, a serverless function, or an AI agent before a large job.
  1. Call GET /user/credits/info and read credits.
  2. If credits is below your threshold, call POST /user/purchase-topup with one of the supported amounts.
  3. On 200 or 202, stop. Credits arrive once Stripe confirms the payment, so don’t buy again on the next check until the balance has updated.
To run the check every hour with cron:
Pick a threshold that covers your usage between checks. If you run the check hourly and use about 1,000 credits an hour, a threshold of 2,000 leaves a buffer while a top-up is processing.
Each run can charge your saved card. Run only one refill job per team, and handle 429 (purchase_topup_cooldown) and 503 (payment_status_unknown) by waiting for the next scheduled check instead of retrying right away. A 402 (payment_failed) means your card was declined; update it in the dashboard before the next run.