Skip to content
Start here

Billing

Get credit balance
ai_gateway.billing.credit_balance(BillingCreditBalanceParams**kwargs) -> BillingCreditBalanceResponse
GET/accounts/{account_id}/ai-gateway/billing/credit-balance
Get usage history
ai_gateway.billing.usage_history(BillingUsageHistoryParams**kwargs) -> BillingUsageHistoryResponse
GET/accounts/{account_id}/ai-gateway/billing/usage-history
Get invoice history
ai_gateway.billing.invoice_history(BillingInvoiceHistoryParams**kwargs) -> BillingInvoiceHistoryResponse
GET/accounts/{account_id}/ai-gateway/billing/invoice-history
Get invoice preview
ai_gateway.billing.invoice_preview(BillingInvoicePreviewParams**kwargs) -> BillingInvoicePreviewResponse
GET/accounts/{account_id}/ai-gateway/billing/invoice-preview
ModelsExpand Collapse
class BillingCreditBalanceResponse: …
balance: float

Credit balance in US cents. Can be fractional, because usage is deducted in fractions of a cent, and is negative when usage overdraws it.

has_default_payment_method: bool

Whether AI Gateway billing has a default payment method for the account.

payment_method: Optional[PaymentMethod]

The default payment method’s card. Null when there is no default, it isn’t a card, or it couldn’t be read.

brand: Optional[str]

Card brand, such as visa.

last4: Optional[str]

Last 4 digits of the card.

topup_config: TopupConfig

Auto top-up configuration, as GET /topup/config returns it.

amount: Optional[float]

Amount in cents that each auto top-up adds. 0 when auto top-up is off.

threshold: Optional[float]

Balance threshold in cents that triggers an auto top-up. 0 when auto top-up is off.

disabled_reason: Optional[str]

Why auto top-up was stopped. Present only once it stopped.

error: Optional[str]

Message from the failure that stopped auto top-up. Present only once it stopped.

last_failed_at: Optional[float]

When auto top-up was stopped, as a Unix timestamp in milliseconds. Present only once it stopped.

first_topup_success: Optional[bool]

Whether the account completed its first top-up. Auto top-up can be set up only after it.

class BillingUsageHistoryResponse: …
history: List[History]

Usage cost per window of value_grouping_window.

id: str

Usage summary identifier.

aggregated_value: float

AI Gateway usage cost in the window, in US dollars.

end_time: float

End of the window (exclusive), as a Unix timestamp in seconds.

start_time: float

Start of the window, as a Unix timestamp in seconds.

class BillingInvoiceHistoryResponse: …
invoices: List[Invoice]

Top-up invoices matching type, up to 100.

amount_due: float

Amount due, in US cents.

amount_paid: float

Amount paid, in US cents.

amount_remaining: float

Amount still owed, in US cents.

currency: str

Lowercase ISO 4217 currency code.

id: Optional[str]

Invoice number, as printed on the invoice, rather than an identifier. Null until the invoice is finalized.

attempt_count: Optional[float]

Number of payment attempts.

attempted: Optional[bool]

Whether payment was attempted.

auto_advance: Optional[bool]

Whether the invoice is finalized and collected without an explicit action. False for top-up invoices, which are charged when the top-up is made.

created: Optional[float]

When the invoice was created, as a Unix timestamp in seconds.

created_by: Optional[str]

What created the invoice. Always AI_GATEWAY.

description: Optional[str]

Invoice description.

invoice_origin: Optional[str]

How the top-up was made: auto or manual.

invoice_pdf: Optional[str]

URL of the invoice PDF. Null until the invoice is finalized.

status: Optional[str]

Invoice status: draft, open, paid, uncollectible, or void.

class BillingInvoicePreviewResponse: …
id: str

Invoice number, as printed on the invoice, rather than an identifier. Empty until the invoice is finalized.

amount_due: float

Amount due, in US cents.

amount_paid: float

Amount paid, in US cents.

amount_remaining: float

Amount still owed, in US cents.

currency: str

Lowercase ISO 4217 currency code.

invoice_lines: List[InvoiceLine]

Invoice line items.

amount: float

Line item amount, in US cents.

currency: str

Lowercase ISO 4217 currency code.

description: Optional[str]

Line item description.

period: InvoiceLinePeriod

Period the line item covers.

end: float

End of the period, as a Unix timestamp in seconds.

start: float

Start of the period, as a Unix timestamp in seconds.

pricing: InvoiceLinePricing

Line item pricing.

unit_amount_decimal: Optional[str]

Unit price in US cents, as a decimal string.

quantity: float

Quantity billed.

pretax_credit_amounts: Optional[List[InvoiceLinePretaxCreditAmount]]

Credits applied to the line item before tax.

amount: float

Credit applied, in US cents.

type: str

Credit type: credit_balance_transaction or discount.

credit_balance_transaction: Optional[str]

Credit balance transaction identifier, when type is credit_balance_transaction.

discount: Optional[str]

Discount identifier, when type is discount.

period_end: float

End of the billing period, as a Unix timestamp in seconds.

period_start: float

Start of the billing period, as a Unix timestamp in seconds.

status: Literal["draft", "open", "paid", 2 more]

Invoice status.

One of the following:
"draft"
"open"
"paid"
"uncollectible"
"void"

BillingTopup

Create a top-up
ai_gateway.billing.topup.create(TopupCreateParams**kwargs) -> TopupCreateResponse
POST/accounts/{account_id}/ai-gateway/billing/topup
Check top-up status
ai_gateway.billing.topup.status(TopupStatusParams**kwargs) -> TopupStatusResponse
POST/accounts/{account_id}/ai-gateway/billing/topup/status
Check top-up eligibility (deprecated)
Deprecated
ai_gateway.billing.topup.eligibility(TopupEligibilityParams**kwargs) -> TopupEligibilityResponse
POST/accounts/{account_id}/ai-gateway/billing/topup/eligibility
Get top-up eligibility
ai_gateway.billing.topup.get_eligibility(TopupGetEligibilityParams**kwargs) -> TopupGetEligibilityResponse
GET/accounts/{account_id}/ai-gateway/billing/topup/eligibility
Get account top-up limits (deprecated)
Deprecated
ai_gateway.billing.topup.limits(TopupLimitsParams**kwargs) -> TopupLimitsResponse
GET/accounts/{account_id}/ai-gateway/billing/topup/limits
ModelsExpand Collapse
class TopupCreateResponse: …
client_secret: Optional[str]

Client secret used to complete payment authentication.

onboarding: bool

Whether the user was already onboarded.

payment_intent_id: str

Top-up payment identifier.

brand: Optional[str]

Card brand (visa, mastercard, etc.).

last4: Optional[str]

Last 4 digits of card.

class TopupStatusResponse: …
payment_intent_id: str

Top-up identifier from the request.

status: Literal["completed", "pending"]

completed once the top-up payment is processed and its credits are added to the balance, pending until then.

One of the following:
"completed"
"pending"
class TopupEligibilityResponse: …
account_payment_method_state: Literal["NONE", "UNSUPPORTED_ONLY", "SUPPORTED_PRESENT", "UNKNOWN"]

Account-level payment-method state derived from the provided list.

One of the following:
"NONE"
"UNSUPPORTED_ONLY"
"SUPPORTED_PRESENT"
"UNKNOWN"
aig_customer_state: Literal["RESOLVED", "RESOLUTION_FAILED"]

AI Gateway billing profile resolution outcome.

One of the following:
"RESOLVED"
"RESOLUTION_FAILED"
aig_default_payment_method_state: Literal["PRESENT", "MISSING"]

Whether AI Gateway billing has a default payment method.

One of the following:
"PRESENT"
"MISSING"
display_payment_method: Optional[DisplayPaymentMethod]

Card to reference in the UI, e.g. “use card ending 1234”.

last4: str

Last 4 digits of the card.

brand: Optional[str]

Card brand, when known.

eligible: bool

True only when reason === ELIGIBLE.

reason: Literal["ELIGIBLE", "NO_ACCOUNT_PAYMENT_METHOD", "UNSUPPORTED_ACCOUNT_PAYMENT_METHOD", 6 more]

Canonical eligibility outcome for display and support triage.

One of the following:
"ELIGIBLE"
"NO_ACCOUNT_PAYMENT_METHOD"
"UNSUPPORTED_ACCOUNT_PAYMENT_METHOD"
"ACCOUNT_PAYMENT_METHOD_NOT_DEFAULT"
"ACCOUNT_PAYMENT_METHOD_NOT_LINKED_TO_AIG"
"CONTRACT_BILLING_NOT_SELF_SERVE"
"AIG_CUSTOMER_RESOLUTION_FAILED"
"PENDING_3DS_AUTHENTICATION"
"PAYMENT_AUTHENTICATION_FAILED"
One of the following:
recoverable: bool

Whether the customer can resolve this themselves (vs contact support).

class TopupGetEligibilityResponse: …
auto_topup: AutoTopup

Auto top-up state.

can_configure: bool

Whether auto top-up can be set up or changed now.

config: Optional[AutoTopupConfig]

Configured threshold and amount. Null unless state is active or needs_confirmation.

amount_cents: int

Amount in cents that each auto top-up adds.

threshold_cents: int

Balance threshold in cents that triggers an auto top-up.

limits: AutoTopupLimits

Allowed auto top-up values.

amount_max_cents: int

Maximum auto top-up amount in cents.

amount_min_cents: int

Minimum auto top-up amount in cents.

threshold_min_cents: int

Minimum threshold in cents.

payment_method_id: Optional[str]

Payment method auto top-up charges or, once stopped, the one it stopped on. Null when there is none to name.

state: Literal["first_topup_required", "not_configured", "active", 2 more]

first_topup_required: auto top-up can be set up after the first manual top-up. not_configured: auto top-up is off. active: auto top-up is on. needs_confirmation: auto top-up is on, but its card has to be confirmed or replaced. stopped: auto top-up was turned off; stopped_reason says why, when known.

One of the following:
"first_topup_required"
"not_configured"
"active"
"needs_confirmation"
"stopped"
stopped_reason: Optional[Literal["payment_method_removed", "payment_method_changed", "expired_card", 4 more]]

Why auto top-up stopped. Present only when state is stopped and the reason is known.

One of the following:
"payment_method_removed"
"payment_method_changed"
"expired_card"
"payment_method_not_supported"
"prepaid_card_not_supported"
"payment_declined"
"amount_out_of_range"
contract_version: Literal[2]

Response contract version. Always 2.

evaluated_at: datetime

When eligibility was evaluated, as an ISO 8601 timestamp.

formatdate-time
manual_topup: ManualTopup

Manual top-up availability.

available: bool

Whether a manual top-up can be made now. True only when status is ready.

default_payment_method_id: Optional[str]

Payment method to preselect: the default when it can pay, otherwise the first that can. Null when none can.

limits: ManualTopupLimits

Allowed manual top-up amounts.

currency: Literal["USD"]

Currency of the amounts. Always USD.

max_cents: int

Maximum top-up amount in cents.

min_cents: int

Minimum top-up amount in cents.

payment_methods: List[PaymentMethod]

The account’s payment methods, and whether each can pay for a top-up.

id: str

Payment method identifier.

is_default: bool

Whether this is the account’s default payment method.

type: Literal["card", "apple_pay", "google_pay", 3 more]

Payment method type. A card saved in a wallet has the wallet type and its card details. link is a card saved with Link, which has card details, or a Link payment that no card funds, which has none.

One of the following:
"card"
"apple_pay"
"google_pay"
"link"
"paypal"
"other"
usable: bool

Whether this payment method can pay for a top-up.

brand: Optional[str]

Card brand. Present for cards, including cards saved in a wallet.

exp_month: Optional[int]

Expiration month, 1 to 12. Present for cards, including cards saved in a wallet.

exp_year: Optional[int]

Four-digit expiration year. Present for cards, including cards saved in a wallet.

last4: Optional[str]

Last 4 digits. Present for cards, including cards saved in a wallet.

unusable_reason: Optional[Literal["payment_method_not_supported", "expired_card", "prepaid_card_not_supported", "card_not_3ds_capable"]]

Why this payment method can’t pay for a top-up. Present only when usable is false.

One of the following:
"payment_method_not_supported"
"expired_card"
"prepaid_card_not_supported"
"card_not_3ds_capable"
reason: Literal["NONE", "CONTRACT_BILLING", "ACCOUNT_RESTRICTED", 3 more]

What prevents a manual top-up, or NONE. CONTRACT_BILLING: the account is billed by contract. ACCOUNT_RESTRICTED: the account is restricted. ELIGIBILITY_UNAVAILABLE: eligibility could not be determined. NO_ELIGIBLE_PAYMENT_METHOD: no payment method can pay for a top-up. DAILY_LIMIT_REACHED: the account reached its daily top-up limit.

One of the following:
"NONE"
"CONTRACT_BILLING"
"ACCOUNT_RESTRICTED"
"ELIGIBILITY_UNAVAILABLE"
"NO_ELIGIBLE_PAYMENT_METHOD"
"DAILY_LIMIT_REACHED"
status: Literal["ready", "blocked", "unavailable"]

ready when a manual top-up is available, blocked when reason prevents one, or unavailable when eligibility could not be determined and the request can be retried.

One of the following:
"ready"
"blocked"
"unavailable"
class TopupLimitsResponse: …
currency: str

ISO 4217 currency code.

max_cents: int

Maximum allowed top-up amount in cents.

min_cents: int

Minimum allowed top-up amount in cents.

BillingTopupConfig

Get auto top-up configuration (deprecated)
Deprecated
ai_gateway.billing.topup.config.get(ConfigGetParams**kwargs) -> ConfigGetResponse
GET/accounts/{account_id}/ai-gateway/billing/topup/config
Set auto top-up configuration
ai_gateway.billing.topup.config.create(ConfigCreateParams**kwargs) -> ConfigCreateResponse
POST/accounts/{account_id}/ai-gateway/billing/topup/config
Delete auto top-up configuration
ai_gateway.billing.topup.config.delete(ConfigDeleteParams**kwargs) -> object
DELETE/accounts/{account_id}/ai-gateway/billing/topup/config
ModelsExpand Collapse
class ConfigGetResponse: …
amount: Optional[float]

Amount in cents that each auto top-up adds. 0 when auto top-up is off.

threshold: Optional[float]

Balance threshold in cents that triggers an auto top-up. 0 when auto top-up is off.

disabled_reason: Optional[str]

Why auto top-up was stopped. Present only once it stopped.

error: Optional[str]

Message from the failure that stopped auto top-up. Present only once it stopped.

last_failed_at: Optional[float]

When auto top-up was stopped, as a Unix timestamp in milliseconds. Present only once it stopped.

One of the following:
class UnionMember0: …
amount: float

Auto top-up amount in cents from the request.

threshold: float

Balance threshold in cents from the request.

class UnionMember1: …
amount: float

Auto top-up amount in cents from the request.

status: Literal["configured"]

Auto top-up is saved.

threshold: float

Balance threshold in cents from the request.

class UnionMember2: …
amount: float

Auto top-up amount in cents from the request.

client_secret: str

Client secret used to complete card authentication.

setup_intent_id: str

Card setup identifier to send back as setup_intent_id once authenticated.

status: Literal["requires_action"]

The card must be authenticated with client_secret before auto top-up is saved. Then send the request again with setup_intent_id.

threshold: float

Balance threshold in cents from the request.

BillingSpending Limit

Get spending limit (deprecated)
Deprecated
ai_gateway.billing.spending_limit.get(SpendingLimitGetParams**kwargs) -> SpendingLimitGetResponse
GET/accounts/{account_id}/ai-gateway/billing/spending-limit
Set spending limit (deprecated)
Deprecated
ai_gateway.billing.spending_limit.create(SpendingLimitCreateParams**kwargs) -> object
POST/accounts/{account_id}/ai-gateway/billing/spending-limit
Delete spending limit (deprecated)
Deprecated
ai_gateway.billing.spending_limit.delete(SpendingLimitDeleteParams**kwargs) -> object
DELETE/accounts/{account_id}/ai-gateway/billing/spending-limit
ModelsExpand Collapse
class SpendingLimitGetResponse: …
config: Config

Spending limit configuration.

amount: Optional[float]

Spending limit amount in cents.

duration: Optional[str]

Window the limit applies to: daily, weekly, or monthly.

strategy: Optional[str]

Window type: fixed or sliding.

enabled: bool

Whether a spending limit is enforced for the account.