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.

ScopeGrants access to
inquiry:executeCreate inquiry sessions and submit questions
inquiry:readList inquiry sessions and turns
inquiry_policy:readList, inspect, and resolve response policies
inquiry_policy:writePreview, create, revise, activate, archive, and assign response policies
semantic:readList and view semantic layer components
semantic:writeCreate, update, and delete semantic layer components
semantic:generateTrigger AI generation of semantic layer components
query:executeExecute, validate, and export raw SQL via the query endpoints

Wildcard scopes

Use resource:* to grant all actions for a resource:

  • inquiry:* grants inquiry:read and inquiry:execute
  • inquiry_policy:* grants inquiry_policy:read and inquiry_policy:write
  • semantic:* grants semantic:read, semantic:write, and semantic: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:

HeaderPurposeExample
X-Subject-Org-IDIdentifies which of your customers/tenants is making the requestacme-widgets
X-Subject-User-IDIdentifies the individual end-user within that organizationuser-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

StatusMeaning
401Missing or invalid X-API-Key
403Authenticated but missing the required scope
422Request shape is invalid