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

# Authentication

> API keys per stage and the Authorization header.

Authenticate every request except `GET /v1/health` with your API key as a bearer token:

```sh theme={null}
curl -s "https://api.cufea.com/v1/tenant" -H "Authorization: Bearer $CUFEA_KEY"
```

```json theme={null}
{"tenant_id":"4b976379-cf1e-4679-a56a-c5be3d4436f1","stage":"sandbox","dian_environment":"test"}
```

`GET /v1/tenant` answers for any valid key and tells you its tenant and stage.

## One key per stage

| Prefix | Stage | Issued |
| - | - | - |
| `cufea_sandbox_` | Cufea's simulated DIAN | To every tenant, from sign-up |
| `cufea_test_` | DIAN test (habilitación) | By the tenant owner on the console's **Keys** page, or by a [partner](https://docs.cufea.com/en/partners.md) |
| `cufea_prod_` | DIAN production | Only after the tenant is [promoted](https://docs.cufea.com/en/production.md); the first one is the operator's |
| `cufea_partner_` | Partner routes under `/v1/partner` only | By the operator, to [partners](https://docs.cufea.com/en/partners.md) |

* A key creates, sends, reads and lists documents of its own stage only; documents of another
  stage answer as if they did not exist. A test key never reads production documents.
* Keys issued earlier with the `cfa_test_` prefix keep working as test keys.
* A partner key creates no documents and reads no configuration or secrets: it works only
  under `/v1/partner`.

## Managing keys

Issue and revoke keys on the console's **Keys** page, or over the API with
`GET`/`POST /v1/tenant/api-keys` and `DELETE /v1/tenant/api-keys/{key_id}`. Over the API a key
issues keys of its own stage only (`403 stage_not_allowed` for another one). **A key is shown
once**, when it is issued: only a hash is kept, so store it right away. A request cannot revoke the key it is
authenticated with (`409 cannot_revoke_current_key`).

There is no password confirmation over the API: a test key can configure the tenant's
certificate and promote it to production, so keep it like a password. Every configuration
write made with a key is recorded in the tenant's audit log with the key's id as the actor,
never a secret value.

## Missing or wrong key

A missing or wrong key answers `401` and uses no [rate limit](https://docs.cufea.com/en/rate-limits.md) quota:

```json theme={null}
{"type":"urn:cufea:problem:unauthorized","title":"Unauthorized","status":401,
 "code":"unauthorized","detail":"Missing or invalid API key.",
 "request_id":"3668a7374b1e4314b2f932a5620da1f1"}
```


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