Authentication
The AnswerLayer API uses API key authentication. Keep API keys on your backend and never expose them in browser or mobile client code.
Creating an API key
API keys are created in the AnswerLayer dashboard under Settings > API Keys. Each key belongs to an organization and can be scoped to specific permissions.
When you create a key, the full key is shown once. Store it securely — it cannot be retrieved later.
Using the key
Include the key in every request:
curl "$ANSWERLAYER_BASE_URL/api/v1/connections/" \
-H "X-API-Key: $ANSWERLAYER_API_KEY"
Scopes
Each API key has a set of scopes that control what it can do. Requests to scoped endpoints without the required scope return 403 Forbidden.
| Scope | Grants access to |
|---|---|
inquiry:execute | Create inquiry sessions and submit questions |
inquiry:read | List inquiry sessions and turns |
inquiry_policy:read | List, inspect, and resolve response policies |
inquiry_policy:write | Preview, create, revise, activate, archive, and assign response policies |
semantic:read | List and view semantic layer components |
semantic:write | Create, update, and delete semantic layer components |
semantic:generate | Trigger AI generation of semantic layer components |
query:execute | Execute, validate, and export raw SQL via the query endpoints |
Wildcard scopes
Use resource:* to grant all actions for a resource:
inquiry:*grantsinquiry:readandinquiry:executeinquiry_policy:*grantsinquiry_policy:readandinquiry_policy:writesemantic:*grantssemantic:read,semantic:write, andsemantic:generate
Connection scoping
Optionally, a key can be restricted to a single database connection. When set, the key can only access data through that connection. This is useful for database-level tenant isolation.
Set the connection when creating the key in the dashboard.
Attributing requests to your end-users
When your backend calls AnswerLayer on behalf of an end-user, it can pass opaque identifiers with the request:
| Header | Purpose | Example |
|---|---|---|
X-Subject-Org-ID | Identifies which of your customers/tenants is making the request | acme-widgets |
X-Subject-User-ID | Identifies the individual end-user within that organization | user-42 |
curl -N -X POST "$ANSWERLAYER_BASE_URL/api/v1/inquiry/sessions/{session_id}" \
-H "X-API-Key: $ANSWERLAYER_API_KEY" \
-H "X-Subject-Org-ID: acme-widgets" \
-H "X-Subject-User-ID: user-42" \
-H "Content-Type: application/json" \
-d '{"user_input": "What was our revenue last quarter?"}'
These headers are trusted metadata, not a separate authentication method. AnswerLayer accepts the values because the request came from your authenticated backend. Do not send email addresses, names, or other personal information when a stable internal ID will do.
X-Subject-Org-ID identifies your customer organization; it is not your AnswerLayer organization ID. X-Subject-User-ID identifies the individual within that customer organization and supports end-user attribution in audit and usage data. On connections using the legacy subject-filter configuration, the subject organization can also supply the tenant value for a warehouse row filter. The headers do not grant API scopes or connection access by themselves; the API key and the connection’s server-side configuration remain authoritative.
Use immutable database primary keys or identity-provider subjects for both values. Never use an email address, display name, organization name, username, or session token, and never reassign an identifier.
If subject filtering or embedded inquiry access is enabled for a connection, send the same subject values consistently on every operation for that session. Missing or different subject values do not inherit access to the original session. Subject headers are suitable only for server-to-server integrations where your backend authenticates the user before making the AnswerLayer request.
Errors
| Status | Meaning |
|---|---|
| 401 | Missing or invalid X-API-Key |
| 403 | Authenticated but missing the required scope |
| 422 | Request shape is invalid |