# Authenticate your requests

> Every request carries a sending key as `Authorization: Bearer <key>`. Create one in Baker under **Settings → API Keys**, choosing **Sending events only**: it can post events for that one company and do nothing else. The key decides the company, so the body never names one. Keep it on your server and rotate it by creating a new one before revoking the old.

Source: https://withbaker.com/docs/authentication · Updated 2026-11-23

## API keys

A sending key belongs to one company in Baker and can do one thing: post events for it. It cannot publish pages, change ads, spend money or read anything back. That makes it safe to keep in another system's environment file, such as your CRM's middleware or your store's backend.

Anyone in the company who can edit in Baker can create one: open **Settings → API Keys**, add a label, choose **Sending events only** and press **Create**.

| Field | | What it takes |
| --- | --- | --- |
| `Authorization` | required | Bearer \<your sending key> |
| `Content-Type` | required | application/json |
| `X-Baker-Mode` | optional | live (the default) or test.<br>A test send is authenticated and validated identically and stores nothing. An unrecognised value is refused rather than assumed. |

## One key, one company

The key is the only thing that says which company an event belongs to. The body has no company field, and one is refused, so a key cannot write into another company's reports by mistake. An agency sending for several clients creates one key in each client's company and keeps them apart.

## Keep it on your server

Read the key from an environment variable (the samples use `BAKER_EVENTS_KEY`) and never ship it in a browser, a mobile app or a repository. For events that happen in the browser, use Baker's pixel and `window.baker.track(name)` instead: it needs no key.

> **Tip:** Rotate a key without losing an event: create the new one, deploy it, then press **Revoke** on the old one under **Settings → API Keys**. Both work in between.

## The public test key

`bk_test_public` is published so anybody, and any coding agent, can call the real API before having a key. A request with it is parsed and judged by exactly the rules your company's requests are, and answered in the same shape with `"mode": "test"`. It belongs to no company, so nothing is stored, nothing shows in Baker, and asking it to go live is refused with a `403`. It has its own rate limit and never spends yours.

```bash
export BAKER_EVENTS_KEY=bk_test_public
```

## Test mode

Send `X-Baker-Mode: test` while you build. The request is authenticated, parsed, validated and answered exactly as a live one, and nothing is stored: no report moves. There is no separate test key or test endpoint, so going live is removing one header. Any value other than `live` or `test` is refused with a `400`, so a typo can never send a rehearsal into your real numbers. The answer always says which mode it used.

## Source addresses, for tools that cannot set a header

Some tools can call a webhook URL and set nothing else. For those, Baker gives a source address, `https://api.withbaker.com/v1/sources/<token>`, where the address itself is the credential. Get it in Baker under **Measure → Sources → API**, with **Get the address**.

It takes the same body and gives the same answers as `/v1/events`, with no `Authorization` header. A wrong or removed address answers `404 not_found`. Treat the address like a password.

## Authentication errors: 401 and 403

| Status | Code | Means |
| --- | --- | --- |
| `401` | `invalid_api_key` | The key is missing, mistyped or revoked. Check the Authorization header and the key in Baker. |
| `403` | `forbidden` | The key is valid but may not send events, the company's Baker account is closed, or the public test key was asked to go live. Use a key created as Sending events only. The public test key only rehearses. |
| `404` | `not_found` | Nothing is listening at this source address: it is wrong, or the source was removed. Copy the address again from Baker. |

```json
{
  "ok": false,
  "error": {
    "code": "invalid_api_key",
    "message": "Missing or invalid Authorization header"
  }
}
```

## Need help?

Write to support@withbaker.com: a person answers within 24 hours. The OpenAPI description is at https://withbaker.com/docs/openapi.json.
