Authentication
How to issue API Keys, authenticate REST API requests, and follow security best practices.
The Onttle REST API uses Bearer Token authentication. You must include the API Key issued from your Project in the Authorization header of every request.
What is an API Key?
An API Key is the credential that allows an external application to access data in a specific Project.
- Project scope: An API Key belongs to a specific Project and can only access that Project's data.
- Key type: A publishable key (
pk-proj_…) is read-only; a secret key (sk-proj_…) can also write. - Allowed hosts: Optionally restrict requests to specific domains or IP addresses (CIDR ranges included).
Issuing an API Key
- Open the Project in the dashboard where you want to issue a key.
- Click API Keys in the left menu.
- Click New API Key.
- Enter a name (e.g.,
production-read). - Select the key type.
- Publishable (
pk-proj_…): Allows GET requests only. Safe for browsers and public websites, ideally together with allowed hosts. - Secret (
sk-proj_…): Also allows POST, PUT, and DELETE requests, file uploads, chat and embeddings. Server-side only.
- Publishable (
- Optionally enter allowed hosts, one per line: domains (
https://example.com,*.example.com) or IPs (203.0.113.10,203.0.113.0/24). A request is accepted when any entry matches. Use an IP for calls made from a server. - Choose an expiry: never, in 30 / 90 / 180 days or 1 year, or an exact date.
- Click Create.
[IMAGE AREA] API Key creation screen (name, permission, allowed hosts input UI)
The full API Key value is only shown once immediately after creation. Copy it before closing the window: Onttle stores only a hash of the key, so it cannot be displayed again. The list shows the key's prefix and last 4 characters (sk-proj_abcd…wxyz). The key type cannot be changed later; issue a new key instead.
Using the Authorization Header
Include the following header in every API request.
Authorization: Bearer {API_KEY}
curl Example
curl https://api.onttle.com/v1/{projectId}/tables/posts \
-H "Authorization: Bearer $ONTTLE_API_KEY"
TypeScript Example
const res = await fetch(
`https://api.onttle.com/v1/${projectId}/tables/posts`,
{
headers: {
Authorization: `Bearer ${process.env.ONTTLE_API_KEY}`,
'Content-Type': 'application/json',
},
},
)
The X-Onttle-Key Header
The API Key can also be sent in the X-Onttle-Key header instead of Authorization.
curl https://api.onttle.com/v1/{projectId}/tables/posts \
-H "X-Onttle-Key: $ONTTLE_API_KEY"
The member feature needs this header, because Authorization then carries the access token of the signed-in member.
curl https://api.onttle.com/v1/{projectId}/me \
-H "X-Onttle-Key: $ONTTLE_PUBLISHABLE_KEY" \
-H "Authorization: Bearer $MEMBER_ACCESS_TOKEN"
| Header | Value | Used for |
|---|---|---|
X-Onttle-Key |
API Key | Project authentication (every endpoint) |
Authorization |
Bearer {API Key} |
Project authentication (original form, still supported) |
Authorization |
Bearer {accessToken} |
The signed-in member (together with X-Onttle-Key) |
Managing Keys with Environment Variables
Never hard-code API Keys in source code. Manage them as environment variables.
# .env.local (Next.js)
ONTTLE_API_KEY=your_api_key_here
ONTTLE_PROJECT_ID=your_project_id
Server-side environment variables are not included in the client bundle. If you need to call the API from the browser, route requests through a server-side handler.
Publishable vs. Secret Keys
| Operation | Publishable (pk-proj_…) |
Secret (sk-proj_…) |
|---|---|---|
| GET requests | Yes | Yes |
| POST / PUT / DELETE | No | Yes |
| File uploads, chat messages, embeddings search | No | Yes |
Member API (/auth/*, /me): POST / PATCH / PUT / DELETE |
Yes | Yes |
| Content create / update / delete allowed by a Table's permission rule | Yes (whether a member token is needed depends on the rule) | Yes |
| File uploads by members the file upload permission allows | Yes (member token required) | Yes |
For public-facing websites that only display content, use a publishable Key. Secret Keys should only be used in server environments.
A publishable Key may write in three cases only: the member API (sign-up, login …), content writes that a Table's permission rule allows, and file uploads by members that the file upload permission allows. The defaults are all "Secret key only", so a Project whose settings were never changed still cannot be written with a publishable Key.
Security Best Practices
Never do the following
- Hard-code an API Key in source code
- Commit an API Key to Git
- Include a secret Key (
sk-proj_…) in browser client code - Log API Keys in response logs
Recommended practices
- Manage Keys as environment variables and add
.env.localto.gitignore - Issue separate API Keys per service (separate production and development)
- Perform write operations only from server-side API Routes
- If exposure is suspected, immediately delete the Key and issue a new one
Expiry and Unused-Key Warnings
Expiry
You can set an expiry when creating or editing a key. After it passes, every request made with the key is rejected with 401 apiKeyExpired; the key stays in the list marked Expired so the cause is visible. To keep using it, edit the key to extend the expiry or issue a new key. An expiry is recommended for keys handed to outside collaborators or used in short campaigns.
Warnings
The API Keys list and Workspace → Security → API key status flag the following keys.
| Status | Condition |
|---|---|
| Expired | The expiry has passed |
| Expires in N days | Expires within 7 days |
| Unused for N days | Enabled but not used for 90+ days (never-used keys count from creation) |
An unused key is still a liability if it leaks, so delete or disable keys you no longer need.
Rotating and Deleting Keys
Disabling
To temporarily block a Key, disable it from the API Keys list. Requests using a disabled Key will be rejected.
Deleting
Deleting a Key immediately rejects all requests using it. Deleted Keys cannot be recovered.
Authentication Error Handling
| Error | Cause |
|---|---|
401 unauthorized |
Missing API Key header, incorrect Key value, deleted or disabled Key, a Key of another Project, or a request from a domain / IP outside the Key's allowed hosts |
401 apiKeyExpired |
The Key's expiry has passed (extend it or issue a new Key) |
403 forbidden |
Insufficient Key permissions (attempting write with a publishable Key) |
403 apiNotEnabled |
The endpoint is turned off in the Project's API endpoints screen |
403 ipNotAllowed |
The request is rejected by the IP allow / block lists in the Workspace security settings |
Next Steps
- Error Codes — Understand the cause and resolution for each error status code.
- Members API — Sign-up and login for your end users, and how member tokens are used.
- REST API Usage — See complete request examples including the authentication header.