# Billing ## Get credit balance `client.aiGateway.billing.creditBalance(BillingCreditBalanceParamsparams, RequestOptionsoptions?): BillingCreditBalanceResponse` **get** `/accounts/{account_id}/ai-gateway/billing/credit-balance` Retrieve the current credit balance, payment method info, and top-up configuration. ### Parameters - `params: BillingCreditBalanceParams` - `account_id: string` Cloudflare account ID. ### Returns - `BillingCreditBalanceResponse` - `balance: number` - `has_default_payment_method: boolean` - `payment_method: PaymentMethod | null` - `brand?: string` - `last4?: string` - `topup_config: TopupConfig` - `amount: number | null` - `disabledReason: string | null` - `error: string | null` - `lastFailedAt: number | null` - `threshold: number | null` - `first_topup_success?: boolean` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.aiGateway.billing.creditBalance({ account_id: 'account_id' }); console.log(response.balance); ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "result": { "balance": 0, "has_default_payment_method": true, "payment_method": { "brand": "brand", "last4": "last4" }, "topup_config": { "amount": 0, "disabledReason": "disabledReason", "error": "error", "lastFailedAt": 0, "threshold": 0 }, "first_topup_success": true }, "success": true, "result_info": { "has_more": true, "page": 0, "per_page": 0, "total_count": 0 } } ``` ## Get usage history `client.aiGateway.billing.usageHistory(BillingUsageHistoryParamsparams, RequestOptionsoptions?): BillingUsageHistoryResponse` **get** `/accounts/{account_id}/ai-gateway/billing/usage-history` Retrieve aggregated usage meter event summaries for the given time range. ### Parameters - `params: BillingUsageHistoryParams` - `account_id: string` Path param: Cloudflare account ID. - `value_grouping_window: "day" | "hour"` Query param: Grouping window for usage data. - `"day"` - `"hour"` - `end_time?: number | null` Query param: End time as Unix timestamp in milliseconds. - `start_time?: number | null` Query param: Start time as Unix timestamp in milliseconds. ### Returns - `BillingUsageHistoryResponse` - `history: Array` - `id: string` - `aggregated_value: number` - `end_time: number` - `start_time: number` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.aiGateway.billing.usageHistory({ account_id: 'account_id', value_grouping_window: 'day', }); console.log(response.history); ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "result": { "history": [ { "id": "id", "aggregated_value": 0, "end_time": 0, "start_time": 0 } ] }, "success": true, "result_info": { "has_more": true, "page": 0, "per_page": 0, "total_count": 0 } } ``` ## Get invoice history `client.aiGateway.billing.invoiceHistory(BillingInvoiceHistoryParamsparams, RequestOptionsoptions?): BillingInvoiceHistoryResponse` **get** `/accounts/{account_id}/ai-gateway/billing/invoice-history` Retrieve a list of past invoices with pagination, optionally filtered by type. ### Parameters - `params: BillingInvoiceHistoryParams` - `account_id: string` Path param: Cloudflare account ID. - `type?: "auto" | "all" | "manual"` Query param: Filter invoice type: auto, manual, or all. - `"auto"` - `"all"` - `"manual"` ### Returns - `BillingInvoiceHistoryResponse` - `invoices: Array` - `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: boolean` - `page: number` - `per_page: number` - `total_count: number` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.aiGateway.billing.invoiceHistory({ account_id: 'account_id' }); console.log(response.invoices); ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "result": { "invoices": [ { "amount_due": 0, "amount_paid": 0, "amount_remaining": 0, "currency": "currency", "id": "id", "attempt_count": 0, "attempted": true, "auto_advance": true, "created": 0, "created_by": "created_by", "description": "description", "invoice_origin": "invoice_origin", "invoice_pdf": "invoice_pdf", "status": "status" } ], "pagination": { "has_more": true, "page": 0, "per_page": 0, "total_count": 0 } }, "success": true, "result_info": { "has_more": true, "page": 0, "per_page": 0, "total_count": 0 } } ``` ## Get invoice preview `client.aiGateway.billing.invoicePreview(BillingInvoicePreviewParamsparams, RequestOptionsoptions?): BillingInvoicePreviewResponse` **get** `/accounts/{account_id}/ai-gateway/billing/invoice-preview` Retrieve a preview of the upcoming invoice including line items and tax. ### Parameters - `params: BillingInvoicePreviewParams` - `account_id: string` Cloudflare account ID. ### Returns - `BillingInvoicePreviewResponse` - `id: string` - `amount_due: number` - `amount_paid: number` - `amount_remaining: number` - `currency: string` - `invoice_lines: Array` - `amount: number` - `currency: string` - `description: string | null` - `period: Period` - `end: number` - `start: number` - `pricing: Pricing` - `unit_amount_decimal: string | null` - `quantity: number` - `pretax_credit_amounts?: Array` - `amount: number` - `type: string` - `credit_balance_transaction?: string | null` - `discount?: string | null` - `period_end: number` - `period_start: number` - `status: "draft" | "open" | "paid" | 2 more` - `"draft"` - `"open"` - `"paid"` - `"uncollectible"` - `"void"` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.aiGateway.billing.invoicePreview({ account_id: 'account_id' }); console.log(response.id); ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "result": { "id": "id", "amount_due": 0, "amount_paid": 0, "amount_remaining": 0, "currency": "currency", "invoice_lines": [ { "amount": 0, "currency": "currency", "description": "description", "period": { "end": 0, "start": 0 }, "pricing": { "unit_amount_decimal": "unit_amount_decimal" }, "quantity": 0, "pretax_credit_amounts": [ { "amount": 0, "type": "type", "credit_balance_transaction": "credit_balance_transaction", "discount": "discount" } ] } ], "period_end": 0, "period_start": 0, "status": "draft" }, "success": true, "result_info": { "has_more": true, "page": 0, "per_page": 0, "total_count": 0 } } ``` ## Domain Types ### Billing Credit Balance Response - `BillingCreditBalanceResponse` - `balance: number` - `has_default_payment_method: boolean` - `payment_method: PaymentMethod | null` - `brand?: string` - `last4?: string` - `topup_config: TopupConfig` - `amount: number | null` - `disabledReason: string | null` - `error: string | null` - `lastFailedAt: number | null` - `threshold: number | null` - `first_topup_success?: boolean` ### Billing Usage History Response - `BillingUsageHistoryResponse` - `history: Array` - `id: string` - `aggregated_value: number` - `end_time: number` - `start_time: number` ### Billing Invoice History Response - `BillingInvoiceHistoryResponse` - `invoices: Array` - `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: boolean` - `page: number` - `per_page: number` - `total_count: number` ### Billing Invoice Preview Response - `BillingInvoicePreviewResponse` - `id: string` - `amount_due: number` - `amount_paid: number` - `amount_remaining: number` - `currency: string` - `invoice_lines: Array` - `amount: number` - `currency: string` - `description: string | null` - `period: Period` - `end: number` - `start: number` - `pricing: Pricing` - `unit_amount_decimal: string | null` - `quantity: number` - `pretax_credit_amounts?: Array` - `amount: number` - `type: string` - `credit_balance_transaction?: string | null` - `discount?: string | null` - `period_end: number` - `period_start: number` - `status: "draft" | "open" | "paid" | 2 more` - `"draft"` - `"open"` - `"paid"` - `"uncollectible"` - `"void"` # Topup ## Create a top-up `client.aiGateway.billing.topup.create(TopupCreateParamsparams, RequestOptionsoptions?): TopupCreateResponse` **post** `/accounts/{account_id}/ai-gateway/billing/topup` Create a credit top-up via Stripe PaymentIntent for the given account. ### Parameters - `params: TopupCreateParams` - `account_id: string` Path param: Cloudflare account ID. - `amount: number` Body param: Top-up amount in cents (min 1000). ### Returns - `TopupCreateResponse` - `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. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const topup = await client.aiGateway.billing.topup.create({ account_id: 'account_id', amount: 5000, }); console.log(topup.payment_intent_id); ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "result": { "client_secret": "client_secret", "onboarding": true, "payment_intent_id": "payment_intent_id", "brand": "brand", "last4": "last4" }, "success": true, "result_info": { "has_more": true, "page": 0, "per_page": 0, "total_count": 0 } } ``` ## Check top-up status `client.aiGateway.billing.topup.status(TopupStatusParamsparams, RequestOptionsoptions?): TopupStatusResponse` **post** `/accounts/{account_id}/ai-gateway/billing/topup/status` Get the payment processing status of a top-up by its invoice ID. ### Parameters - `params: TopupStatusParams` - `account_id: string` Path param: Cloudflare account ID. - `payment_intent_id: string` Body param: Stripe invoice ID to check status for. ### Returns - `TopupStatusResponse` - `payment_intent_id: string` - `status: "completed" | "pending"` - `"completed"` - `"pending"` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.aiGateway.billing.topup.status({ account_id: 'account_id', payment_intent_id: 'in_1abc', }); console.log(response.payment_intent_id); ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "result": { "payment_intent_id": "payment_intent_id", "status": "completed" }, "success": true, "result_info": { "has_more": true, "page": 0, "per_page": 0, "total_count": 0 } } ``` ## Domain Types ### Topup Create Response - `TopupCreateResponse` - `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. ### Topup Status Response - `TopupStatusResponse` - `payment_intent_id: string` - `status: "completed" | "pending"` - `"completed"` - `"pending"` # Config ## Get auto top-up configuration `client.aiGateway.billing.topup.config.get(ConfigGetParamsparams, RequestOptionsoptions?): ConfigGetResponse` **get** `/accounts/{account_id}/ai-gateway/billing/topup/config` Retrieve the current auto top-up threshold, amount, and any error state. ### Parameters - `params: ConfigGetParams` - `account_id: string` Cloudflare account ID. ### Returns - `ConfigGetResponse` - `amount: number | null` - `disabledReason: string | null` - `error: string | null` - `lastFailedAt: number | null` - `threshold: number | null` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const config = await client.aiGateway.billing.topup.config.get({ account_id: 'account_id' }); console.log(config.amount); ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "result": { "amount": 0, "disabledReason": "disabledReason", "error": "error", "lastFailedAt": 0, "threshold": 0 }, "success": true, "result_info": { "has_more": true, "page": 0, "per_page": 0, "total_count": 0 } } ``` ## Set auto top-up configuration `client.aiGateway.billing.topup.config.create(ConfigCreateParamsparams, RequestOptionsoptions?): ConfigCreateResponse` **post** `/accounts/{account_id}/ai-gateway/billing/topup/config` Configure auto top-up with a balance threshold and top-up amount. ### Parameters - `params: ConfigCreateParams` - `account_id: string` Path param: Cloudflare account ID. - `amount: number` Body param: Auto top-up amount in cents (min 1000). - `threshold: number` Body param: Balance threshold in cents that triggers auto top-up (min 500). ### Returns - `ConfigCreateResponse` - `amount: number` - `threshold: number` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const config = await client.aiGateway.billing.topup.config.create({ account_id: 'account_id', amount: 5000, threshold: 500, }); console.log(config.amount); ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "result": { "amount": 0, "threshold": 0 }, "success": true, "result_info": { "has_more": true, "page": 0, "per_page": 0, "total_count": 0 } } ``` ## Delete auto top-up configuration `client.aiGateway.billing.topup.config.delete(ConfigDeleteParamsparams, RequestOptionsoptions?): ConfigDeleteResponse` **delete** `/accounts/{account_id}/ai-gateway/billing/topup/config` Remove the auto top-up configuration for the account. ### Parameters - `params: ConfigDeleteParams` - `account_id: string` Cloudflare account ID. ### Returns - `ConfigDeleteResponse = unknown` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const config = await client.aiGateway.billing.topup.config.delete({ account_id: 'account_id' }); console.log(config); ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "result": {}, "success": true, "result_info": { "has_more": true, "page": 0, "per_page": 0, "total_count": 0 } } ``` ## Domain Types ### Config Get Response - `ConfigGetResponse` - `amount: number | null` - `disabledReason: string | null` - `error: string | null` - `lastFailedAt: number | null` - `threshold: number | null` ### Config Create Response - `ConfigCreateResponse` - `amount: number` - `threshold: number` ### Config Delete Response - `ConfigDeleteResponse = unknown` # Spending Limit ## Get spending limit `client.aiGateway.billing.spendingLimit.get(SpendingLimitGetParamsparams, RequestOptionsoptions?): SpendingLimitGetResponse` **get** `/accounts/{account_id}/ai-gateway/billing/spending-limit` Retrieve the current spending limit configuration for the account. ### Parameters - `params: SpendingLimitGetParams` - `account_id: string` Cloudflare account ID. ### Returns - `SpendingLimitGetResponse` - `config: Config` - `amount: number | null` - `duration: string | null` - `strategy: string | null` - `enabled: boolean` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const spendingLimit = await client.aiGateway.billing.spendingLimit.get({ account_id: 'account_id', }); console.log(spendingLimit.config); ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "result": { "config": { "amount": 0, "duration": "duration", "strategy": "strategy" }, "enabled": true }, "success": true, "result_info": { "has_more": true, "page": 0, "per_page": 0, "total_count": 0 } } ``` ## Set spending limit `client.aiGateway.billing.spendingLimit.create(SpendingLimitCreateParamsparams, RequestOptionsoptions?): SpendingLimitCreateResponse` **post** `/accounts/{account_id}/ai-gateway/billing/spending-limit` Configure a spending limit with amount, strategy, and duration. ### Parameters - `params: SpendingLimitCreateParams` - `account_id: string` Path param: Cloudflare account ID. - `amount: number` Body param: Spending limit amount in cents (min 100). - `duration: "daily" | "weekly" | "monthly"` Body param: Spending limit duration. - `"daily"` - `"weekly"` - `"monthly"` - `strategy: "fixed" | "sliding"` Body param: Spending limit strategy. - `"fixed"` - `"sliding"` ### Returns - `SpendingLimitCreateResponse = unknown` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const spendingLimit = await client.aiGateway.billing.spendingLimit.create({ account_id: 'account_id', amount: 10000, duration: 'monthly', strategy: 'fixed', }); console.log(spendingLimit); ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "result": {}, "success": true, "result_info": { "has_more": true, "page": 0, "per_page": 0, "total_count": 0 } } ``` ## Delete spending limit `client.aiGateway.billing.spendingLimit.delete(SpendingLimitDeleteParamsparams, RequestOptionsoptions?): SpendingLimitDeleteResponse` **delete** `/accounts/{account_id}/ai-gateway/billing/spending-limit` Remove the spending limit for the account. ### Parameters - `params: SpendingLimitDeleteParams` - `account_id: string` Cloudflare account ID. ### Returns - `SpendingLimitDeleteResponse = unknown` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const spendingLimit = await client.aiGateway.billing.spendingLimit.delete({ account_id: 'account_id', }); console.log(spendingLimit); ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "result": {}, "success": true, "result_info": { "has_more": true, "page": 0, "per_page": 0, "total_count": 0 } } ``` ## Domain Types ### Spending Limit Get Response - `SpendingLimitGetResponse` - `config: Config` - `amount: number | null` - `duration: string | null` - `strategy: string | null` - `enabled: boolean` ### Spending Limit Create Response - `SpendingLimitCreateResponse = unknown` ### Spending Limit Delete Response - `SpendingLimitDeleteResponse = unknown`