# Billing ## Get credit balance `client.AIGateway.Billing.CreditBalance(ctx, query) (*BillingCreditBalanceResponse, error)` **get** `/accounts/{account_id}/ai-gateway/billing/credit-balance` Retrieve the current credit balance, payment method info, and top-up configuration. ### Parameters - `query BillingCreditBalanceParams` - `AccountID param.Field[string]` Cloudflare account ID. ### Returns - `type BillingCreditBalanceResponse struct{…}` - `Balance float64` - `HasDefaultPaymentMethod bool` - `PaymentMethod BillingCreditBalanceResponsePaymentMethod` - `Brand string` - `Last4 string` - `TopupConfig BillingCreditBalanceResponseTopupConfig` - `Amount float64` - `DisabledReason string` - `Error string` - `LastFailedAt float64` - `Threshold float64` - `FirstTopupSuccess bool` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai_gateway" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.AIGateway.Billing.CreditBalance(context.TODO(), ai_gateway.BillingCreditBalanceParams{ AccountID: cloudflare.F("account_id"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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(ctx, params) (*BillingUsageHistoryResponse, error)` **get** `/accounts/{account_id}/ai-gateway/billing/usage-history` Retrieve aggregated usage meter event summaries for the given time range. ### Parameters - `params BillingUsageHistoryParams` - `AccountID param.Field[string]` Path param: Cloudflare account ID. - `ValueGroupingWindow param.Field[BillingUsageHistoryParamsValueGroupingWindow]` Query param: Grouping window for usage data. - `const BillingUsageHistoryParamsValueGroupingWindowDay BillingUsageHistoryParamsValueGroupingWindow = "day"` - `const BillingUsageHistoryParamsValueGroupingWindowHour BillingUsageHistoryParamsValueGroupingWindow = "hour"` - `EndTime param.Field[float64]` Query param: End time as Unix timestamp in milliseconds. - `StartTime param.Field[float64]` Query param: Start time as Unix timestamp in milliseconds. ### Returns - `type BillingUsageHistoryResponse struct{…}` - `History []BillingUsageHistoryResponseHistory` - `ID string` - `AggregatedValue float64` - `EndTime float64` - `StartTime float64` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai_gateway" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.AIGateway.Billing.UsageHistory(context.TODO(), ai_gateway.BillingUsageHistoryParams{ AccountID: cloudflare.F("account_id"), ValueGroupingWindow: cloudflare.F(ai_gateway.BillingUsageHistoryParamsValueGroupingWindowDay), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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(ctx, params) (*BillingInvoiceHistoryResponse, error)` **get** `/accounts/{account_id}/ai-gateway/billing/invoice-history` Retrieve a list of past invoices with pagination, optionally filtered by type. ### Parameters - `params BillingInvoiceHistoryParams` - `AccountID param.Field[string]` Path param: Cloudflare account ID. - `Type param.Field[BillingInvoiceHistoryParamsType]` Query param: Filter invoice type: auto, manual, or all. - `const BillingInvoiceHistoryParamsTypeAuto BillingInvoiceHistoryParamsType = "auto"` - `const BillingInvoiceHistoryParamsTypeAll BillingInvoiceHistoryParamsType = "all"` - `const BillingInvoiceHistoryParamsTypeManual BillingInvoiceHistoryParamsType = "manual"` ### Returns - `type BillingInvoiceHistoryResponse struct{…}` - `Invoices []BillingInvoiceHistoryResponseInvoice` - `AmountDue float64` - `AmountPaid float64` - `AmountRemaining float64` - `Currency string` - `ID string` - `AttemptCount float64` - `Attempted bool` - `AutoAdvance bool` - `Created float64` - `CreatedBy string` - `Description string` - `InvoiceOrigin string` - `InvoicePDF string` - `Status string` - `Pagination BillingInvoiceHistoryResponsePagination` - `HasMore bool` - `Page float64` - `PerPage float64` - `TotalCount float64` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai_gateway" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.AIGateway.Billing.InvoiceHistory(context.TODO(), ai_gateway.BillingInvoiceHistoryParams{ AccountID: cloudflare.F("account_id"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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(ctx, query) (*BillingInvoicePreviewResponse, error)` **get** `/accounts/{account_id}/ai-gateway/billing/invoice-preview` Retrieve a preview of the upcoming invoice including line items and tax. ### Parameters - `query BillingInvoicePreviewParams` - `AccountID param.Field[string]` Cloudflare account ID. ### Returns - `type BillingInvoicePreviewResponse struct{…}` - `ID string` - `AmountDue float64` - `AmountPaid float64` - `AmountRemaining float64` - `Currency string` - `InvoiceLines []BillingInvoicePreviewResponseInvoiceLine` - `Amount float64` - `Currency string` - `Description string` - `Period BillingInvoicePreviewResponseInvoiceLinesPeriod` - `End float64` - `Start float64` - `Pricing BillingInvoicePreviewResponseInvoiceLinesPricing` - `UnitAmountDecimal string` - `Quantity float64` - `PretaxCreditAmounts []BillingInvoicePreviewResponseInvoiceLinesPretaxCreditAmount` - `Amount float64` - `Type string` - `CreditBalanceTransaction string` - `Discount string` - `PeriodEnd float64` - `PeriodStart float64` - `Status BillingInvoicePreviewResponseStatus` - `const BillingInvoicePreviewResponseStatusDraft BillingInvoicePreviewResponseStatus = "draft"` - `const BillingInvoicePreviewResponseStatusOpen BillingInvoicePreviewResponseStatus = "open"` - `const BillingInvoicePreviewResponseStatusPaid BillingInvoicePreviewResponseStatus = "paid"` - `const BillingInvoicePreviewResponseStatusUncollectible BillingInvoicePreviewResponseStatus = "uncollectible"` - `const BillingInvoicePreviewResponseStatusVoid BillingInvoicePreviewResponseStatus = "void"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai_gateway" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.AIGateway.Billing.InvoicePreview(context.TODO(), ai_gateway.BillingInvoicePreviewParams{ AccountID: cloudflare.F("account_id"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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 } } ``` # Topup ## Create a top-up `client.AIGateway.Billing.Topup.New(ctx, params) (*BillingTopupNewResponse, error)` **post** `/accounts/{account_id}/ai-gateway/billing/topup` Create a credit top-up via Stripe PaymentIntent for the given account. ### Parameters - `params BillingTopupNewParams` - `AccountID param.Field[string]` Path param: Cloudflare account ID. - `Amount param.Field[int64]` Body param: Top-up amount in cents (min 1000). ### Returns - `type BillingTopupNewResponse struct{…}` - `ClientSecret string` Stripe PaymentIntent client secret. - `Onboarding bool` Whether the user was already onboarded. - `PaymentIntentID string` Stripe invoice ID. - `Brand string` Card brand (visa, mastercard, etc.). - `Last4 string` Last 4 digits of card. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai_gateway" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) topup, err := client.AIGateway.Billing.Topup.New(context.TODO(), ai_gateway.BillingTopupNewParams{ AccountID: cloudflare.F("account_id"), Amount: cloudflare.F(int64(5000)), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", topup.PaymentIntentID) } ``` #### 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(ctx, params) (*BillingTopupStatusResponse, error)` **post** `/accounts/{account_id}/ai-gateway/billing/topup/status` Get the payment processing status of a top-up by its invoice ID. ### Parameters - `params BillingTopupStatusParams` - `AccountID param.Field[string]` Path param: Cloudflare account ID. - `PaymentIntentID param.Field[string]` Body param: Stripe invoice ID to check status for. ### Returns - `type BillingTopupStatusResponse struct{…}` - `PaymentIntentID string` - `Status BillingTopupStatusResponseStatus` - `const BillingTopupStatusResponseStatusCompleted BillingTopupStatusResponseStatus = "completed"` - `const BillingTopupStatusResponseStatusPending BillingTopupStatusResponseStatus = "pending"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai_gateway" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.AIGateway.Billing.Topup.Status(context.TODO(), ai_gateway.BillingTopupStatusParams{ AccountID: cloudflare.F("account_id"), PaymentIntentID: cloudflare.F("in_1abc"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", response.PaymentIntentID) } ``` #### 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 } } ``` # Config ## Get auto top-up configuration `client.AIGateway.Billing.Topup.Config.Get(ctx, query) (*BillingTopupConfigGetResponse, error)` **get** `/accounts/{account_id}/ai-gateway/billing/topup/config` Retrieve the current auto top-up threshold, amount, and any error state. ### Parameters - `query BillingTopupConfigGetParams` - `AccountID param.Field[string]` Cloudflare account ID. ### Returns - `type BillingTopupConfigGetResponse struct{…}` - `Amount float64` - `DisabledReason string` - `Error string` - `LastFailedAt float64` - `Threshold float64` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai_gateway" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) config, err := client.AIGateway.Billing.Topup.Config.Get(context.TODO(), ai_gateway.BillingTopupConfigGetParams{ AccountID: cloudflare.F("account_id"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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.New(ctx, params) (*BillingTopupConfigNewResponse, error)` **post** `/accounts/{account_id}/ai-gateway/billing/topup/config` Configure auto top-up with a balance threshold and top-up amount. ### Parameters - `params BillingTopupConfigNewParams` - `AccountID param.Field[string]` Path param: Cloudflare account ID. - `Amount param.Field[int64]` Body param: Auto top-up amount in cents (min 1000). - `Threshold param.Field[int64]` Body param: Balance threshold in cents that triggers auto top-up (min 500). ### Returns - `type BillingTopupConfigNewResponse struct{…}` - `Amount float64` - `Threshold float64` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai_gateway" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) config, err := client.AIGateway.Billing.Topup.Config.New(context.TODO(), ai_gateway.BillingTopupConfigNewParams{ AccountID: cloudflare.F("account_id"), Amount: cloudflare.F(int64(5000)), Threshold: cloudflare.F(int64(500)), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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(ctx, body) (*BillingTopupConfigDeleteResponse, error)` **delete** `/accounts/{account_id}/ai-gateway/billing/topup/config` Remove the auto top-up configuration for the account. ### Parameters - `body BillingTopupConfigDeleteParams` - `AccountID param.Field[string]` Cloudflare account ID. ### Returns - `type BillingTopupConfigDeleteResponse interface{…}` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai_gateway" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) config, err := client.AIGateway.Billing.Topup.Config.Delete(context.TODO(), ai_gateway.BillingTopupConfigDeleteParams{ AccountID: cloudflare.F("account_id"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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 } } ``` # Spending Limit ## Get spending limit `client.AIGateway.Billing.SpendingLimit.Get(ctx, query) (*BillingSpendingLimitGetResponse, error)` **get** `/accounts/{account_id}/ai-gateway/billing/spending-limit` Retrieve the current spending limit configuration for the account. ### Parameters - `query BillingSpendingLimitGetParams` - `AccountID param.Field[string]` Cloudflare account ID. ### Returns - `type BillingSpendingLimitGetResponse struct{…}` - `Config BillingSpendingLimitGetResponseConfig` - `Amount float64` - `Duration string` - `Strategy string` - `Enabled bool` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai_gateway" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) spendingLimit, err := client.AIGateway.Billing.SpendingLimit.Get(context.TODO(), ai_gateway.BillingSpendingLimitGetParams{ AccountID: cloudflare.F("account_id"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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.New(ctx, params) (*BillingSpendingLimitNewResponse, error)` **post** `/accounts/{account_id}/ai-gateway/billing/spending-limit` Configure a spending limit with amount, strategy, and duration. ### Parameters - `params BillingSpendingLimitNewParams` - `AccountID param.Field[string]` Path param: Cloudflare account ID. - `Amount param.Field[int64]` Body param: Spending limit amount in cents (min 100). - `Duration param.Field[BillingSpendingLimitNewParamsDuration]` Body param: Spending limit duration. - `const BillingSpendingLimitNewParamsDurationDaily BillingSpendingLimitNewParamsDuration = "daily"` - `const BillingSpendingLimitNewParamsDurationWeekly BillingSpendingLimitNewParamsDuration = "weekly"` - `const BillingSpendingLimitNewParamsDurationMonthly BillingSpendingLimitNewParamsDuration = "monthly"` - `Strategy param.Field[BillingSpendingLimitNewParamsStrategy]` Body param: Spending limit strategy. - `const BillingSpendingLimitNewParamsStrategyFixed BillingSpendingLimitNewParamsStrategy = "fixed"` - `const BillingSpendingLimitNewParamsStrategySliding BillingSpendingLimitNewParamsStrategy = "sliding"` ### Returns - `type BillingSpendingLimitNewResponse interface{…}` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai_gateway" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) spendingLimit, err := client.AIGateway.Billing.SpendingLimit.New(context.TODO(), ai_gateway.BillingSpendingLimitNewParams{ AccountID: cloudflare.F("account_id"), Amount: cloudflare.F(int64(10000)), Duration: cloudflare.F(ai_gateway.BillingSpendingLimitNewParamsDurationMonthly), Strategy: cloudflare.F(ai_gateway.BillingSpendingLimitNewParamsStrategyFixed), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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(ctx, body) (*BillingSpendingLimitDeleteResponse, error)` **delete** `/accounts/{account_id}/ai-gateway/billing/spending-limit` Remove the spending limit for the account. ### Parameters - `body BillingSpendingLimitDeleteParams` - `AccountID param.Field[string]` Cloudflare account ID. ### Returns - `type BillingSpendingLimitDeleteResponse interface{…}` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai_gateway" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) spendingLimit, err := client.AIGateway.Billing.SpendingLimit.Delete(context.TODO(), ai_gateway.BillingSpendingLimitDeleteParams{ AccountID: cloudflare.F("account_id"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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 } } ```