# API keys

Source: https://cubibase.com/docs/platform/api-keys

Also available: [Markdown version](https://cubibase.com/docs/platform/api-keys.md) · [llms.txt](https://cubibase.com/llms.txt) · [full site content](https://cubibase.com/llms-full.txt)

The publishable key identifies your project to the API. It is meant to live in your client — but it never authorizes rows by itself.

## Two kinds of key

| Key | Prefix | Where it lives | What it does |
| --- | --- | --- | --- |
| Publishable | `cb_pub_` | Your app (browser, mobile) | Identifies the project on every Data API and Auth call |
| Secret | `cb_sec_` | Server-side only (trusted servers, AI agents) | Authenticates Data API and RPC calls as the service actor; shown once, stored hashed |

> **important**: Never ship a secret key in a browser or mobile client. It acts with service-level access to every row a service policy grants. Keep it on your server or in an agent environment.

## Using the secret key (service actor)

A secret key authenticates REST and RPC calls without an end-user JWT. Send it as the `apikey` header or as `Authorization: Bearer`. The request runs with `cubibase.role = 'service'` and an empty `cubibase.user_id()`. Row-level security still applies — a table without a service policy returns no rows.

**Service request**

```http
GET https://example-project.api.cubibase.com/rest/v1/customers
apikey: cb_sec_…
```

Grant service access explicitly with a policy, for example `cubibase.current_role() = 'service'` for SELECT, or keep service access limited to SECURITY DEFINER functions. Every service write is recorded in the audit log.

## Using the publishable key

Send it in the `apikey` header on every request to the project host — Data API and Auth alike. The engine checks it against the project resolved from the host.

**Every request carries both headers**

```http
GET https://example-project.api.cubibase.com/rest/v1/customers
apikey: cb_pub_EXAMPLE_ONLY
Authorization: Bearer <USER_JWT>
```

| Situation | Response |
| --- | --- |
| No `apikey` header | `401 missing_api_key` |
| Key not valid for this project | `401 invalid_api_key` |
| Valid key, no bearer token and no secret key | `401 missing_end_user_token` |

## Keeping keys safe

- The publishable key is public by design, but treat it as a project credential: it names your project to the API.
- Row access comes from the end-user JWT and the table’s policies — not from the key.
- Manage keys from Console → project → API keys: create, revoke, and rotate.
- If a key leaks and you want it dead, revoke it; requests using it fail immediately.

## Additional resources

- [How CubiBase works](https://cubibase.com/docs/architecture) Where the key check sits in the request path.
- [Row-level security](https://cubibase.com/docs/database/row-level-security) What actually authorizes rows.
