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

# Authentication

> API keys, live and test modes, budgets and rotation.

Send an API key with every request, as a bearer token:

```bash theme={null}
curl https://api.apiforgeo.com/v1/balance \
  -H "Authorization: Bearer afg_live_..."
```

A request without a valid key gets `401` with the code `unauthenticated`.

Create and manage keys in the [dashboard](https://app.apiforgeo.com), under **API keys**. A key belongs to an organization. Every task it creates is charged to that organization's balance.

> [!WARNING]
>
> The dashboard shows a key once, when you create it. Keep it on your server. Never put it in a browser or a mobile app.

## Live and test keys

| | Live key | Test key |
| - | - | - |
| Prefix | `afg_live_` | `afg_test_` |
| Runs on | The real models | A sandbox |
| Cost | \$0.013 a task | Free |
| Result | The model's real answer | A sample in the live shape |
| `mode` on the task | `live` | `test` |

Build and test your integration with a test key. Then change the key. The code stays the same: a test result has the same shape as a live one.

In the sandbox, the prompt controls the outcome:

* `[fail]` in the prompt: the task fails.
* `[slow]` in the prompt: the task takes about 2 minutes.
* Any other prompt: the task completes in about 15 seconds.

## Budgets

A key can have a total budget, a monthly budget, or both. A task that would go over the budget is refused with `403` and the code `key_budget_exceeded`:

```json theme={null}
{
  "error": {
    "code": "key_budget_exceeded",
    "message": "This API key has a monthly budget of $10.00 and has spent $10.00 this month. Raise the budget or use another key.",
    "details": { "budget": "monthly", "budgetMicros": 10000000, "spentMicros": 10000000 },
    "requestId": "req_0193f2a7b8c77d1e9f3a4b5c6d7e8f90"
  }
}
```

Give each app or environment its own key with a budget. A bug in one then cannot spend the whole balance.

## Rotation

Rotate a key in the dashboard to get a new secret. The old secret keeps working for 24 hours, so you can deploy the new one without downtime. After 24 hours, the old secret gets `401`.

Revoke a key to stop it at once.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.