## Authentication

Every request carries the API key, `c_serv_…`, by any carrier below, and is checked for key, rate and credits before it is served. A missing or invalid key gets `401`, as does an [account API key](https://carbium.sh/docs/account-api-keys.md) (`c_acct_…`), which only manages the account.

| protocol | mechanism | carried in | example |
|---|---|---|---|
| **rpc** |  |  |  |
| RPC | api key header | request header | x-api-key: \<YOUR_KEY> |
| RPC | bearer token | authorization header | authorization: Bearer \<YOUR_KEY> |
| RPC | path segment | url path | /\<YOUR_KEY> |
| RPC | query param | url query | ?api-key=\<YOUR_KEY> |
| RPC | token header | request header | x-token: \<YOUR_KEY> |
| **websocket** |  |  |  |
| WS | api key header | handshake header | x-api-key: \<YOUR_KEY> |
| WS | query param | url query | ?api-key=\<YOUR_KEY> |
| WS | subprotocol | handshake header | Sec-WebSocket-Protocol: api-key.\<YOUR_KEY> |
| WS | path segment | url path | /\<YOUR_KEY> |
| **carbon stream** |  |  |  |
| Stream | token metadata | grpc metadata | x-token: \<YOUR_KEY> |
| Stream | authorization | grpc metadata | authorization: Bearer \<YOUR_KEY> |

> Treat the key like a password. Rotate it from [KEYS](https://carbium.sh/) if exposed; the old key stops working at once. Prefer a header: path and query forms leak into logs and referers.
