> The index of all pages is at https://docs.afffast.com/llms.txt.

# Log drains to Axiom

Send the logs of your workspace to an Axiom dataset with a log drain.

The type `axiom` sends the records of a [log drain](https://docs.afffast.com/docs/log-drains.md) to an Axiom dataset. You need an API key with the scope `log_drains:write`. A log drain is a feature of the Business plan.

## Prepare Axiom

1. Make a dataset in Axiom.
2. Make an **API token** with the ingest permission for the dataset. A personal access token does not work.
3. Find the region of your organization: `us-east-1` or `eu-central-1`.

## Make the log drain

```bash
curl https://api.afffast.com/v1/log_drains \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "type": "axiom",
    "label": "Axiom",
    "config": { "dataset": "afffast-logs", "region": "us-east-1" },
    "credentials": { "api_token": "xaat-..." },
    "sources": ["api_request", "delivery", "sync_run"]
  }'
```

- `dataset` is the name of the dataset. It must exist. Use letters, digits and the characters `_ . -`.
- `region` is `us-east-1` or `eu-central-1`.
- `api_token` is write-only. The API never returns it.

`POST /v1/log_drains/{id}/test` sends one sample record (`"test": true`).

## What Axiom gets

Each record is one event. It has the field `_time` (the time of the record) and all fields of the record: `id`, `object`, `source`, `level`, `timestamp`, `workspace`, `livemode`, `test` and `data`. The API sends NDJSON that it compresses with gzip. One request has 1000 records or 3 MiB at most. This is below the limit of Axiom (4 MiB for one request).

Use `id` to remove duplicates. Delivery is at least once.

## Errors

| Answer of Axiom            | What the API does                                                                             |
| -------------------------- | --------------------------------------------------------------------------------------------- |
| 2xx                        | The batch is done.                                                                            |
| 429                        | The API waits and tries again.                                                                |
| 401, 403                   | The API stops the log drain (`failing`). The token is wrong or has no ingest permission.      |
| 404                        | The API stops the log drain (`failing`). The dataset does not exist, or the region is wrong.  |
| 2xx with `failed` above 0  | The API skips the events that Axiom did not ingest, and goes on. It does not send them again. |
| 400                        | The API stops the log drain (`failing`).                                                      |
| 413                        | The API sends the batch in smaller parts.                                                     |
| 408, 5xx, other, no answer | The API tries again with a growing wait.                                                      |

See [Log drains](https://docs.afffast.com/docs/log-drains.md) for the retry wait and the resume of a log drain that failed.
