Billing

Manage team balance, credit top-ups, saved payment methods, and billing settings.

All endpoints require authentication. Use API key scopes billing:read (view balance and settings) and billing:write (checkout, charges, and settings updates).

Subscription — plan signup and Stripe subscription management


Money units

ContextUnitExample
GET /billing, GET /billing/balanceMicrocents (1 USD = 100,000,000)250000000 = $2.50
POST /billing/checkout, POST /billing/charge body amountCents (1 USD = 100)500 = $5.00 minimum top-up

Get billing account

GET /billing

Returns the team's billing account with cached balance.

Response

FieldTypeDescription
balanceint64Current balance in microcents
currencystringCurrency code (for example usd)
statusstringAccount status

Example:

bash
1curl https://api.inference.sh/billing \2  -H "Authorization: Bearer inf_your_key" \3  -H "X-API-Version: 2"

Get balance

GET /billing/balance

Recalculates balance from grants and usage, then returns the current value. Use this after checkout when status is processing, or when you need an authoritative balance.

Response

json
1{2  "balance": 2500000003}

balance is in microcents.


Service fee

GET /billing/service-fee

Returns the active service-fee configuration used for top-ups (default 5% + $0.30). Call before checkout or a saved-card charge to show users the full total including fee and tax.


Add credits

Two paths depending on whether a card is already on file.

MethodEndpointWhen to use
Stripe CheckoutPOST /billing/checkoutNo saved card, user picks a payment method, or delayed methods (ACH, SEPA)
Saved cardPOST /billing/chargeGET /billing/settings reports has_payment_method: true

Both paths apply the same service fee and tax rules, then credit balance on success.

Stripe Checkout

POST /billing/checkout — requires billing:write.

Body:

FieldTypeRequiredDescription
amountint64YesCredit to add, in cents (minimum 500 = $5)
success_urlstringYesRedirect URL after payment
cancel_urlstringYesRedirect URL if the user cancels

ResponsePaymentRecordDTO with status: "pending" and session_url for redirect. Line items include credit_amount, service_fee, and tax fields filled when checkout completes.

Complete checkout:

POST /billing/checkout/success — body: { "session_id": "<stripe_checkout_session_id>" }.

statusMeaning
completeBalance credited now; grant included
processingDelayed payment; balance credited when Stripe confirms (poll GET /billing/balance)

Credits apply exactly once — the success URL and Stripe webhooks share the same completion path.

Example:

bash
1curl -X POST https://api.inference.sh/billing/checkout \2  -H "Authorization: Bearer inf_your_key" \3  -H "Content-Type: application/json" \4  -H "X-API-Version: 2" \5  -d '{6    "amount": 2000,7    "success_url": "https://app.inference.sh/settings/billing?success=1",8    "cancel_url": "https://app.inference.sh/settings/billing"9  }'

Saved card charge

POST /billing/charge — requires billing:write.

Body:

FieldTypeRequiredDescription
amountint64YesCredit to add, in cents (minimum 500)

Success response:

json
1{2  "status": "complete",3  "grant": { }4}

Balance is credited immediately.

Errors (400, code charge_failed):

MessageCause
no saved payment methodUse checkout or save a card first
minimum top-up amount is $5amount < 500
payment failed: ...Stripe declined the charge

Redeem voucher code

Redeem a promotional or gift code to add credits to the current team. In the web app, open Settings → Billing and use the Redeem code section (monospace input, case-normalized as you type).

POST /billing/vouchers/redeem — requires billing:write.

Body:

FieldTypeRequiredDescription
codestringYesVoucher code (whitespace trimmed; matching is case-insensitive)

ResponseCreditGrantDTO for the credited amount. amount and remaining are in microcents. Grant type is typically voucher; notes includes the code string.

Example:

bash
1curl -X POST https://api.inference.sh/billing/vouchers/redeem \2  -H "Authorization: Bearer inf_your_key" \3  -H "Content-Type: application/json" \4  -H "X-API-Version: 2" \5  -d '{"code": "PROMO-ABCD-EFGH"}'

After a successful redemption, poll GET /billing/balance or call GET /credit-grants/active (requires billing:read) to confirm the updated balance and grant expiry.

Rate limits

LimitWindow
10 attempts per user1 minute
30 attempts per IP1 minute

When exceeded, the API returns 429 with code rate_limited and message Too many redemption attempts. Please try again later.

Errors

Failed redemptions return 400 with code redeem_failed and one of these messages:

MessageCause
invalid codeCode not found
this code is no longer activeCode revoked or already used (single-use codes)
this voucher is no longer activeVoucher paused, expired, or exhausted
this code is not yet validBefore the voucher valid_from time
this code has expiredAfter the voucher valid_until time
this voucher has reached its maximum number of redemptionsCampaign cap reached
this code has reached its maximum number of usesPer-code use limit reached
you have already redeemed this voucherPer-user limit reached
your team has already redeemed this voucherPer-team limit reached
this code is assigned to a different accountCode is email-restricted
this voucher is only available for new usersTeam has a prior top-up grant
failed to credit accountRedemption recorded but grant creation failed (retry may be idempotent)

Voucher administration (creating campaigns, generating codes, pausing vouchers) is internal and not exposed on the public REST API.


Billing settings

GET /billing/settings — requires billing:read.

Returns auto-recharge, alerts, invoice fields, and saved-card metadata.

FieldDescription
has_payment_methodWhether instant top-up (POST /billing/charge) is available
payment_method_labelDisplay label (for example Visa •••• 4242)
auto_recharge_enabledAuto top-up when balance drops below threshold
spending_limitTeam spending cap (microcents)
low_balance_thresholdAlert threshold (microcents)

POST /billing/settings — requires billing:write. Send only fields to update (BillingSettingsUpdateRequest).


Saved payment methods

EndpointMethodScopePurpose
/billing/payment-method/setupPOSTbilling:writeStripe Checkout to save a card
/billing/payment-method/successPOSTbilling:writeComplete setup (session_id in body)
/billing/payment-methodDELETEbilling:writeRemove saved card

Setup body: { "success_url": "...", "cancel_url": "..." }. Success body: { "session_id": "..." } — returns last4 and brand.

Users can also save a card during a balance checkout when Stripe shows “Save my info for future purchases.”


Payment history

GET /billing/payments — requires billing:read.

Lists payment records for the team (checkout sessions, charges, and status).


Insufficient balance

When a run would exceed available balance, the API may return 402 Payment Required with a message pointing to billing settings. This is separate from plan limit errors (limit_exceeded, feature_not_available) enforced by entitlements.

The belt and infsh CLIs surface billing URLs in error text for 402 responses.


we use cookies

we use cookies to ensure you get the best experience on our website. for more information on how we use cookies, please see our cookie policy.

by clicking "accept", you agree to our use of cookies.
learn more.