---
title: Billing
---

[Skip to content](#%5Ftop) 

[API Reference](https://developers.cloudflare.com/api/typescript)

[AI Gateway](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway)

Copy Markdown

Open in **Claude**

Open in **ChatGPT**

Open in **Cursor**

---

**Copy Markdown**

**View as Markdown**

# Billing

##### [Get credit balance](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway/subresources/billing/methods/credit%5Fbalance)

client.aiGateway.billing.creditBalance(BillingCreditBalanceParams { account\_id } params, RequestOptionsoptions?): [BillingCreditBalanceResponse](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway#%28resource%29%20ai%5Fgateway.billing%20%3E%20%28model%29%20billing%5Fcredit%5Fbalance%5Fresponse%20%3E%20%28schema%29) { balance, has\_default\_payment\_method, payment\_method, 2 more } 

GET/accounts/{account\_id}/ai-gateway/billing/credit-balance

##### [Get usage history](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway/subresources/billing/methods/usage%5Fhistory)

client.aiGateway.billing.usageHistory(BillingUsageHistoryParams { account\_id, value\_grouping\_window, end\_time, start\_time } params, RequestOptionsoptions?): [BillingUsageHistoryResponse](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway#%28resource%29%20ai%5Fgateway.billing%20%3E%20%28model%29%20billing%5Fusage%5Fhistory%5Fresponse%20%3E%20%28schema%29) { history } 

GET/accounts/{account\_id}/ai-gateway/billing/usage-history

##### [Get invoice history](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway/subresources/billing/methods/invoice%5Fhistory)

client.aiGateway.billing.invoiceHistory(BillingInvoiceHistoryParams { account\_id, type } params, RequestOptionsoptions?): [BillingInvoiceHistoryResponse](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway#%28resource%29%20ai%5Fgateway.billing%20%3E%20%28model%29%20billing%5Finvoice%5Fhistory%5Fresponse%20%3E%20%28schema%29) { invoices, pagination } 

GET/accounts/{account\_id}/ai-gateway/billing/invoice-history

##### [Get invoice preview](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway/subresources/billing/methods/invoice%5Fpreview)

client.aiGateway.billing.invoicePreview(BillingInvoicePreviewParams { account\_id } params, RequestOptionsoptions?): [BillingInvoicePreviewResponse](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway#%28resource%29%20ai%5Fgateway.billing%20%3E%20%28model%29%20billing%5Finvoice%5Fpreview%5Fresponse%20%3E%20%28schema%29) { id, amount\_due, amount\_paid, 6 more } 

GET/accounts/{account\_id}/ai-gateway/billing/invoice-preview

##### ModelsExpand Collapse 

BillingCreditBalanceResponse { balance, has\_default\_payment\_method, payment\_method, 2 more } 

balance: number

has\_default\_payment\_method: boolean

payment\_method: PaymentMethod | null

brand?: string

last4?: string

topup\_config: TopupConfig { amount, threshold, disabledReason, 2 more } 

amount: number | null

threshold: number | null

disabledReason?: string | null

error?: string | null

lastFailedAt?: number | null

first\_topup\_success?: boolean

BillingUsageHistoryResponse { history } 

history: Array<History\>

id: string

aggregated\_value: number

end\_time: number

start\_time: number

BillingInvoiceHistoryResponse { invoices, pagination } 

invoices: Array<Invoice\>

amount\_due: number

amount\_paid: number

amount\_remaining: number

currency: string

id?: string | null

attempt\_count?: number

attempted?: boolean

auto\_advance?: boolean | null

created?: number

created\_by?: string

description?: string | null

invoice\_origin?: string

invoice\_pdf?: string | null

status?: string | null

pagination: Pagination { has\_more, page, per\_page, total\_count } 

has\_more: boolean

page: number

per\_page: number

total\_count: number

BillingInvoicePreviewResponse { id, amount\_due, amount\_paid, 6 more } 

id: string

amount\_due: number

amount\_paid: number

amount\_remaining: number

currency: string

invoice\_lines: Array<InvoiceLine\>

amount: number

currency: string

description: string | null

period: Period { end, start } 

end: number

start: number

pricing: Pricing { unit\_amount\_decimal } 

unit\_amount\_decimal: string | null

quantity: number

pretax\_credit\_amounts?: Array<PretaxCreditAmount\>

amount: number

type: string

credit\_balance\_transaction?: string | null

discount?: string | null

period\_end: number

period\_start: number

status: "draft" | "open" | "paid" | 2 more

One of the following:

"draft"

"open"

"paid"

"uncollectible"

"void"

#### BillingTopup

##### [Create a top-up](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway/subresources/billing/subresources/topup/methods/create)

client.aiGateway.billing.topup.create(TopupCreateParams { account\_id, amount } params, RequestOptionsoptions?): [TopupCreateResponse](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway#%28resource%29%20ai%5Fgateway.billing.topup%20%3E%20%28model%29%20topup%5Fcreate%5Fresponse%20%3E%20%28schema%29) { client\_secret, onboarding, payment\_intent\_id, 2 more } 

POST/accounts/{account\_id}/ai-gateway/billing/topup

##### [Check top-up status](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway/subresources/billing/subresources/topup/methods/status)

client.aiGateway.billing.topup.status(TopupStatusParams { account\_id, payment\_intent\_id } params, RequestOptionsoptions?): [TopupStatusResponse](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway#%28resource%29%20ai%5Fgateway.billing.topup%20%3E%20%28model%29%20topup%5Fstatus%5Fresponse%20%3E%20%28schema%29) { payment\_intent\_id, status } 

POST/accounts/{account\_id}/ai-gateway/billing/topup/status

##### ModelsExpand Collapse 

TopupCreateResponse { client\_secret, onboarding, payment\_intent\_id, 2 more } 

client\_secret: string | null

Stripe PaymentIntent client secret.

onboarding: boolean

Whether the user was already onboarded.

payment\_intent\_id: string

Stripe invoice ID.

brand?: string

Card brand (visa, mastercard, etc.).

last4?: string

Last 4 digits of card.

TopupStatusResponse { payment\_intent\_id, status } 

payment\_intent\_id: string

status: "completed" | "pending"

One of the following:

"completed"

"pending"

#### BillingTopupConfig

##### [Get auto top-up configuration](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway/subresources/billing/subresources/topup/subresources/config/methods/get)

client.aiGateway.billing.topup.config.get(ConfigGetParams { account\_id } params, RequestOptionsoptions?): [ConfigGetResponse](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway#%28resource%29%20ai%5Fgateway.billing.topup.config%20%3E%20%28model%29%20config%5Fget%5Fresponse%20%3E%20%28schema%29) { amount, threshold, disabledReason, 2 more } 

GET/accounts/{account\_id}/ai-gateway/billing/topup/config

##### [Set auto top-up configuration](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway/subresources/billing/subresources/topup/subresources/config/methods/create)

client.aiGateway.billing.topup.config.create(ConfigCreateParams { account\_id, amount, threshold } params, RequestOptionsoptions?): [ConfigCreateResponse](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway#%28resource%29%20ai%5Fgateway.billing.topup.config%20%3E%20%28model%29%20config%5Fcreate%5Fresponse%20%3E%20%28schema%29) { amount, threshold } 

POST/accounts/{account\_id}/ai-gateway/billing/topup/config

##### [Delete auto top-up configuration](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway/subresources/billing/subresources/topup/subresources/config/methods/delete)

client.aiGateway.billing.topup.config.delete(ConfigDeleteParams { account\_id } params, RequestOptionsoptions?): [ConfigDeleteResponse](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway#%28resource%29%20ai%5Fgateway.billing.topup.config%20%3E%20%28model%29%20config%5Fdelete%5Fresponse%20%3E%20%28schema%29)

DELETE/accounts/{account\_id}/ai-gateway/billing/topup/config

##### ModelsExpand Collapse 

ConfigGetResponse { amount, threshold, disabledReason, 2 more } 

amount: number | null

threshold: number | null

disabledReason?: string | null

error?: string | null

lastFailedAt?: number | null

ConfigCreateResponse { amount, threshold } 

amount: number

threshold: number

ConfigDeleteResponse \= unknown

#### BillingSpending Limit

##### [Get spending limit](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway/subresources/billing/subresources/spending%5Flimit/methods/get)

client.aiGateway.billing.spendingLimit.get(SpendingLimitGetParams { account\_id } params, RequestOptionsoptions?): [SpendingLimitGetResponse](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway#%28resource%29%20ai%5Fgateway.billing.spending%5Flimit%20%3E%20%28model%29%20spending%5Flimit%5Fget%5Fresponse%20%3E%20%28schema%29) { config, enabled } 

GET/accounts/{account\_id}/ai-gateway/billing/spending-limit

##### [Set spending limit (deprecated)](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway/subresources/billing/subresources/spending%5Flimit/methods/create)

Deprecated

client.aiGateway.billing.spendingLimit.create(SpendingLimitCreateParams { account\_id, amount, duration, strategy } params, RequestOptionsoptions?): [SpendingLimitCreateResponse](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway#%28resource%29%20ai%5Fgateway.billing.spending%5Flimit%20%3E%20%28model%29%20spending%5Flimit%5Fcreate%5Fresponse%20%3E%20%28schema%29)

POST/accounts/{account\_id}/ai-gateway/billing/spending-limit

##### [Delete spending limit](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway/subresources/billing/subresources/spending%5Flimit/methods/delete)

client.aiGateway.billing.spendingLimit.delete(SpendingLimitDeleteParams { account\_id } params, RequestOptionsoptions?): [SpendingLimitDeleteResponse](https://developers.cloudflare.com/api/typescript/resources/ai%5Fgateway#%28resource%29%20ai%5Fgateway.billing.spending%5Flimit%20%3E%20%28model%29%20spending%5Flimit%5Fdelete%5Fresponse%20%3E%20%28schema%29)

DELETE/accounts/{account\_id}/ai-gateway/billing/spending-limit

##### ModelsExpand Collapse 

SpendingLimitGetResponse { config, enabled } 

config: Config { amount, duration, strategy } 

amount: number | null

duration: string | null

strategy: string | null

enabled: boolean

SpendingLimitCreateResponse \= unknown

SpendingLimitDeleteResponse \= unknown