# Authentication & API keys

> How to authenticate Wayline API requests with live and test keys, where to send the key, and how key environments, scopes and expiry work.

Source: https://www.wayline.cloud/docs/concepts/authentication

Every request to the Wayline API is authenticated with an **API key** that belongs to your organization.

## Sending the key

Send the key as a Bearer token (preferred):

```bash
curl "https://api.wayline.cloud/v1/distance?origin={{ORIGIN}}&destination={{DESTINATION}}" \
  -H "Authorization: Bearer $WAYLINE_API_KEY"
```

Also accepted, in this order of preference:

| Method | Example | When to use |
|---|---|---|
| `Authorization: Bearer <key>` | `Authorization: Bearer wl_live_…` | Always, if you can. |
| `X-API-Key` header | `X-API-Key: wl_live_…` | Clients that reserve `Authorization`. |
| `key` query parameter | `?key=wl_live_…` | Only for the Google-compatible endpoint, for drop-in compatibility. Query strings can end up in logs; prefer headers. |

## Live and test keys

| | Test keys (`wl_test_…`) | Live keys (`wl_live_…`) |
|---|---|---|
| Billing | Never billed | Billed per unit after free units |
| Limits | Daily cap and low rate limit | Your plan's rate limit |
| Use for | Development, CI, demos | Production |

Both key types return real results from the same routing engine.

## Key lifecycle

- **Shown once.** We store only an HMAC-SHA256 hash of each key. If you lose a key, create a new one.
- **Restrictions.** Limit a key to allowed origins (browser use), IP ranges (server use) and endpoint scopes.
- **Expiry.** Keys can have an optional expiry date; expired keys return `KEY_EXPIRED`.
- **Revocation.** Revoked keys stop working within seconds.

## Rotating a key

1. Create a new key with the same restrictions.
2. Deploy it to your secrets store.
3. Watch the old key's usage drop to zero in the dashboard.
4. Revoke the old key.

Related: [Key security](/docs/concepts/key-security) · [Errors](/docs/errors#invalid-api-key)
