---
title: Get credit balance
---

[Skip to content](#_top)

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

[AI Gateway](https://developers.cloudflare.com/api/go/resources/ai_gateway)

[Billing](https://developers.cloudflare.com/api/go/resources/ai_gateway/subresources/billing)

Copy Markdown

Open in **Claude**Open in **ChatGPT**Open in **Cursor**

---

**Copy Markdown****View as Markdown**

# Get credit balance

client.AIGateway.Billing.CreditBalance(ctx, query) (\*[BillingCreditBalanceResponse](<https://developers.cloudflare.com/api/go/resources/ai_gateway#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingCreditBalanceResponse%20%3E%20(schema)>), error)

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

Retrieve the current credit balance, payment method info, and top-up configuration.

##### Security

<details>

<summary>API Token</summary>



The preferred authorization scheme for interacting with the Cloudflare API. <a href="https://developers.cloudflare.com/fundamentals/api/get-started/create-token/">Create a token</a>.

**Example:**<code>Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY</code>

</details>

<details>

<summary>API Email + API Key</summary>



The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

**Example:**<code>X-Auth-Email: user@example.com</code>

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

**Example:**<code>X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194</code>

</details>

##### Accepted Permissions (at least one required)

`AI Gateway Write``AI Gateway Read`

##### ParametersExpand Collapse

<details>

<summary>

query BillingCreditBalanceParams

</summary>

AccountID param.Field\[string]

Cloudflare account ID.

<a href="#(resource)%20ai_gateway.billing%20%3E%20(method)%20credit_balance%20%3E%20(params)%20default%20%3E%20(param)%20account_id">Link to this property</a>

</details>

[Link to this property](<#(resource)%20ai_gateway.billing%20%3E%20(method)%20credit_balance%20%3E%20(params)%20default>)

##### ReturnsExpand Collapse

<details>

<summary>

type BillingCreditBalanceResponse struct{…}

</summary>

Balance float64

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingCreditBalanceResponse%20%3E%20(schema)%20%3E%20(property)%20balance">Link to this property</a>

HasDefaultPaymentMethod bool

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingCreditBalanceResponse%20%3E%20(schema)%20%3E%20(property)%20has_default_payment_method">Link to this property</a>

<details>

<summary>

PaymentMethod BillingCreditBalanceResponsePaymentMethod

</summary>

Brand stringOptional

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingCreditBalanceResponse%20%3E%20(schema)%20%3E%20(property)%20payment_method%20%3E%20(property)%20brand">Link to this property</a>

Last4 stringOptional

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingCreditBalanceResponse%20%3E%20(schema)%20%3E%20(property)%20payment_method%20%3E%20(property)%20last4">Link to this property</a>

</details>

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingCreditBalanceResponse%20%3E%20(schema)%20%3E%20(property)%20payment_method">Link to this property</a>

<details>

<summary>

TopupConfig BillingCreditBalanceResponseTopupConfig

</summary>

Amount float64

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingCreditBalanceResponse%20%3E%20(schema)%20%3E%20(property)%20topup_config%20%3E%20(property)%20amount">Link to this property</a>

Threshold float64

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingCreditBalanceResponse%20%3E%20(schema)%20%3E%20(property)%20topup_config%20%3E%20(property)%20threshold">Link to this property</a>

DisabledReason stringOptional

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingCreditBalanceResponse%20%3E%20(schema)%20%3E%20(property)%20topup_config%20%3E%20(property)%20disabledReason">Link to this property</a>

Error stringOptional

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingCreditBalanceResponse%20%3E%20(schema)%20%3E%20(property)%20topup_config%20%3E%20(property)%20error">Link to this property</a>

LastFailedAt float64Optional

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingCreditBalanceResponse%20%3E%20(schema)%20%3E%20(property)%20topup_config%20%3E%20(property)%20lastFailedAt">Link to this property</a>

</details>

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingCreditBalanceResponse%20%3E%20(schema)%20%3E%20(property)%20topup_config">Link to this property</a>

FirstTopupSuccess boolOptional

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingCreditBalanceResponse%20%3E%20(schema)%20%3E%20(property)%20first_topup_success">Link to this property</a>

</details>

[Link to this property](<#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingCreditBalanceResponse%20%3E%20(schema)>)

### Get credit balance

Go

HTTPTypeScriptPythonGoTerraform

```
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)
}
```

200 example

```
{
  "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,
      "threshold": 0,
      "disabledReason": "disabledReason",
      "error": "error",
      "lastFailedAt": 0
    },
    "first_topup_success": true
  },
  "success": true,
  "result_info": {
    "has_more": true,
    "page": 0,
    "per_page": 0,
    "total_count": 0
  }
}
```

##### Returns Examples

200 example

```
{
  "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,
      "threshold": 0,
      "disabledReason": "disabledReason",
      "error": "error",
      "lastFailedAt": 0
    },
    "first_topup_success": true
  },
  "success": true,
  "result_info": {
    "has_more": true,
    "page": 0,
    "per_page": 0,
    "total_count": 0
  }
}
```