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
has_default_payment_method: bool
payment_method: Optional[PaymentMethod]
brand: Optional[str]
last4: Optional[str]
topup_config: TopupConfig
amount: Optional[float]
disabled_reason: Optional[str]
error: Optional[str]
last_failed_at: Optional[float]
threshold: Optional[float]
first_topup_success: Optional[bool]
class BillingUsageHistoryResponse:
history: List[History]
id: str
aggregated_value: float
end_time: float
start_time: float
class BillingInvoiceHistoryResponse:
invoices: List[Invoice]
amount_due: float
amount_paid: float
amount_remaining: float
currency: str
id: Optional[str]
attempt_count: Optional[float]
attempted: Optional[bool]
auto_advance: Optional[bool]
created: Optional[float]
created_by: Optional[str]
description: Optional[str]
invoice_origin: Optional[str]
invoice_pdf: Optional[str]
status: Optional[str]
class BillingInvoicePreviewResponse:
id: str
amount_due: float
amount_paid: float
amount_remaining: float
currency: str
invoice_lines: List[InvoiceLine]
amount: float
currency: str
description: Optional[str]
period: InvoiceLinePeriod
end: float
start: float
pricing: InvoiceLinePricing
unit_amount_decimal: Optional[str]
quantity: float
pretax_credit_amounts: Optional[List[InvoiceLinePretaxCreditAmount]]
amount: float
type: str
credit_balance_transaction: Optional[str]
discount: Optional[str]
period_end: float
period_start: float
status: Literal["draft", "open", "paid", 2 more]
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
ModelsExpand Collapse
class TopupCreateResponse:
client_secret: Optional[str]

Stripe PaymentIntent client secret.

onboarding: bool

Whether the user was already onboarded.

payment_intent_id: str

Stripe invoice ID.

brand: Optional[str]

Card brand (visa, mastercard, etc.).

last4: Optional[str]

Last 4 digits of card.

class TopupStatusResponse:
payment_intent_id: str
status: Literal["completed", "pending"]
One of the following:
"completed"
"pending"

BillingTopupConfig

Get auto top-up configuration
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]
disabled_reason: Optional[str]
error: Optional[str]
last_failed_at: Optional[float]
threshold: Optional[float]
class ConfigCreateResponse:
amount: float
threshold: float

BillingSpending Limit

Get spending limit
ai_gateway.billing.spending_limit.get(SpendingLimitGetParams**kwargs) -> SpendingLimitGetResponse
GET/accounts/{account_id}/ai-gateway/billing/spending-limit
Set spending limit
ai_gateway.billing.spending_limit.create(SpendingLimitCreateParams**kwargs) -> object
POST/accounts/{account_id}/ai-gateway/billing/spending-limit
Delete spending limit
ai_gateway.billing.spending_limit.delete(SpendingLimitDeleteParams**kwargs) -> object
DELETE/accounts/{account_id}/ai-gateway/billing/spending-limit
ModelsExpand Collapse
class SpendingLimitGetResponse:
config: Config
amount: Optional[float]
duration: Optional[str]
strategy: Optional[str]
enabled: bool