API Overview
The AnswerLayer API provides programmatic access to a semantic layer and natural language query engine. It sits between your application and your data warehouse — you define the semantic model (entities, relationships, measures, metrics), then submit natural language questions via the API. AnswerLayer generates SQL, executes it against your warehouse, and returns structured results over a streaming connection.
To install the CLI or run AnswerLayer locally from its public container image, start with CLI and local setup.
Base URL
Set ANSWERLAYER_BASE_URL to the root URL of your AnswerLayer install. For example:
export ANSWERLAYER_BASE_URL=https://answerlayer.your-company.com
API endpoints are served beneath $ANSWERLAYER_BASE_URL/api/v1. The CLI-managed local runtime saves its selected local URL automatically.
How it works
1. Connect a data warehouse
Register a database connection by providing credentials for your warehouse. Supported adapters: PostgreSQL, BigQuery, Snowflake, MySQL, SQL Server, ClickHouse, Athena, and DuckDB. You can also upload CSV files directly.
AnswerLayer connects to your database at query time — it does not copy or cache your data. Credentials are encrypted at rest with AES-256.
2. Build a semantic layer
The semantic layer is a structured description of your data model that sits between the natural language input and SQL generation. It consists of:
- Entities — tables or views mapped to business objects (e.g.,
orders,customers) - Relationships — foreign key joins between entities
- Dimensions — columns used for grouping and filtering (e.g.,
region,product_category) - Measures — numeric columns to aggregate (e.g.,
SUM(order_total)) - Metrics — derived KPIs defined as expressions over measures (e.g.,
revenue_per_customer) - Filters — reusable WHERE clause predicates (e.g.,
active_customers,last_90_days)
You can generate the semantic layer automatically from your schema using the /semantic/*/generate/stream endpoints, or define components manually via the CRUD API.
3. Query via inquiry sessions
Create an inquiry session scoped to a connection, then submit natural language questions as turns. The agent:
- Reads the semantic layer to understand your data model
- Generates SQL using the entity relationships, dimensions, and measures
- Executes the query against your warehouse
- Returns structured results (columns + rows) over a streaming SSE connection
Sessions are stateful — follow-up questions have access to the full conversation history, so the agent can reference prior results without re-explanation.
4. Embed in your product
Authenticate from your backend with a scoped API key. You can pass a stable, opaque customer-organization identifier in X-Subject-Org-ID and an individual identifier in X-Subject-User-ID. On connections using legacy subject filtering, the subject organization also supplies the tenant value used by that filter. These headers are trusted metadata and do not grant access by themselves.
Request format
All requests use JSON. Include Content-Type: application/json for request bodies.
# Create a session
curl -X POST "$ANSWERLAYER_BASE_URL/api/v1/inquiry/sessions" \
-H "X-API-Key: $ANSWERLAYER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"connection_id": "your-connection-uuid"}'
# Ask a question (streaming)
curl -N -X POST "$ANSWERLAYER_BASE_URL/api/v1/inquiry/sessions/{session_id}" \
-H "X-API-Key: $ANSWERLAYER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"user_input": "What'\''s the month-over-month change in average order value for our top 5 regions?"}'
Response format
Responses are JSON. Streaming endpoints use Server-Sent Events (SSE).
Errors
Standard HTTP status codes with a JSON body:
| Status | Meaning |
|---|---|
| 400 | Bad request — invalid parameters |
| 401 | Unauthorized — missing or invalid API key |
| 403 | Forbidden — valid key but missing required scope |
| 404 | Not found |
| 422 | Unprocessable — request understood but can’t be fulfilled |
| 500 | Server error |
{
"detail": "Missing required scope: inquiry:execute"
}