---
title: Get credit balance
---

[Skip to content](#_top)

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

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

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

Copy Markdown

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

---

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

# Get credit balance

ai\_gateway.billing.credit\_balance(BillingCreditBalanceParams\*\*kwargs) -> [BillingCreditBalanceResponse](<https://developers.cloudflare.com/api/python/resources/ai_gateway#(resource)%20ai_gateway.billing%20%3E%20(model)%20billing_credit_balance_response%20%3E%20(schema)>)

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

account\_id: str

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

##### ReturnsExpand Collapse

<details>

<summary>

class BillingCreditBalanceResponse: …

</summary>

balance: float

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

has\_default\_payment\_method: bool

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

<details>

<summary>

payment\_method: Optional\[PaymentMethod]

</summary>

brand: Optional\[str]

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

last4: Optional\[str]

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20billing_credit_balance_response%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)%20billing_credit_balance_response%20%3E%20(schema)%20%3E%20(property)%20payment_method">Link to this property</a>

<details>

<summary>

topup\_config: TopupConfig

</summary>

amount: Optional\[float]

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

threshold: Optional\[float]

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

disabled\_reason: Optional\[str]

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

error: Optional\[str]

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

last\_failed\_at: Optional\[float]

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20billing_credit_balance_response%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)%20billing_credit_balance_response%20%3E%20(schema)%20%3E%20(property)%20topup_config">Link to this property</a>

first\_topup\_success: Optional\[bool]

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20billing_credit_balance_response%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)%20billing_credit_balance_response%20%3E%20(schema)>)

### Get credit balance

Python

HTTPTypeScriptPythonGoTerraform

```
import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),  # This is the default and can be omitted
)
response = client.ai_gateway.billing.credit_balance(
    account_id="account_id",
)
print(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
  }
}
```