> Index: https://quebragalho.dev/en/docs/llms.txt

# Account API

Balance, API key details and usage with the same key you use for inference. It is what a CLI uses to show how much balance is left and how much has been spent.

## Balance, key and usage with the same key

The key that runs inference also reads the account data.

**cURL**

```bash
# available balance: topped-up + bonus
curl https://api.quebragalho.dev/v1/balance \
  -H "Authorization: Bearer $QUEBRAGALHO_API_KEY"

# this key: plan and models
curl https://api.quebragalho.dev/v1/key \
  -H "Authorization: Bearer $QUEBRAGALHO_API_KEY"

# usage of this key
curl -G https://api.quebragalho.dev/v1/usage \
  -d scope=key \
  -H "Authorization: Bearer $QUEBRAGALHO_API_KEY"
```

- `GET /v1/balance`: Balance available right now, split into topped-up balance (`default`) and bonus.
- `GET /v1/key`: Key name, plan and enabled models. It does not include the person's email or name.
- `GET /v1/usage`: Requests and input, output and cache tokens per period, in windows of up to 31 days. `scope=key` shows only this key; the default is the whole account.

> Up to 60 reads per minute per key. Above that, the response is 429 with `Retry-After`.

## Sign in without copying the key

CLIs and integrations can sign in without you copying and pasting a key. The terminal shows a code, you approve it at `/connect/cli` and the program gets its own API key. It shows up under API keys with the "via CLI" badge, and you can revoke it there at any time.

**Device flow**

```http
# 1 · the terminal asks for a code
POST https://app.quebragalho.dev/api/cli/v1/auth/device/code
# 2 · and polls until you approve
POST https://app.quebragalho.dev/api/cli/v1/auth/device/token
```

QGCLI uses this flow: `qg login --device`. You approve it at [app.quebragalho.dev/connect/cli](https://app.quebragalho.dev/connect/cli).

Read it in the browser: https://quebragalho.dev/en/docs/api/conta
