> ## Documentation Index
> Fetch the complete documentation index at: https://magica.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Get credit balance

> Return the authenticated user's current credit balance.

Returns the current credit balance for the authenticated user (or the user's active organization, if applicable).

<Tip>
  Pair this with [`POST
      /v1/workflows/estimate-credits`](/api-reference/workflows/estimate-credits) or
  [`POST /v1/nodes/estimate-credits`](/api-reference/nodes/estimate-credits) to
  confirm there's enough balance before kicking off an expensive run.
</Tip>

## Authorizations

<ParamField header="Authorization" type="string" required>
  Bearer API key. Format: `Bearer gx_your_api_key`.
</ParamField>

## Response

<ResponseField name="availableBalance" type="number">
  Raw credit balance in **microcredits**. Divide by 1,000,000 to convert to
  credits. Use `formatted` if you just need a display string.
</ResponseField>

<ResponseField name="formatted" type="string">
  Human-readable balance, denominated in millions (e.g. `"1.23M"`).
</ResponseField>

<ResponseField name="hasActiveSubscription" type="boolean">
  `true` when the user's (or org's) subscription is currently active.
</ResponseField>

<ResponseField name="isOrganization" type="boolean">
  `true` when the returned balance belongs to an organization the user is a
  member of, rather than the user's personal account.
</ResponseField>

## Request

<Tabs>
  <Tab title="cURL">
    ```bash theme={null}
    curl https://api.magica.com/api/v1/credits/balance \
      -H "Authorization: Bearer $MAGICA_API_KEY"
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    const res = await fetch("https://api.magica.com/api/v1/credits/balance", {
      headers: { Authorization: `Bearer ${process.env.MAGICA_API_KEY}` },
    });
    const { availableBalance, formatted, hasActiveSubscription } = await res.json();
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import os, requests

    res = requests.get(
        "https://api.magica.com/api/v1/credits/balance",
        headers={"Authorization": f"Bearer {os.environ['MAGICA_API_KEY']}"},
    )
    payload = res.json()
    print(payload["formatted"])  # e.g. "26.17M"
    ```
  </Tab>
</Tabs>

## Response example

```json theme={null}
{
  "availableBalance": 26170000,
  "formatted": "26.17M",
  "hasActiveSubscription": true,
  "isOrganization": false
}
```

## Errors

| Status | Reason                     |
| ------ | -------------------------- |
| `401`  | Missing or invalid API key |
| `500`  | Server error               |
