Metrics
Endpoints for defining reward metrics, assignment sources, and previewing metric data.
A metric is a SQL query that Levered runs against your warehouse. A reward metric returns the events that count as a reward. An assignment source returns the exposure rows. All metric endpoints are under /api/v2/warehouse and require an Authorization: Bearer <token> header.
Create metric
POST /api/v2/warehouse/metricsAuth: Required
Creates a reward metric backed by a SQL query against your warehouse. If the organization already has a metric with the same name, the request replaces its SQL and column mapping.
Request body:
{
"name": "Signup Conversion",
"sql": "SELECT user_id AS anonymous_id, converted_at AS timestamp FROM conversions",
"column_mapping": {
"anonymous_id": "anonymous_id",
"timestamp": "timestamp",
"reward_type": "bool"
}
}| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Human-readable metric name |
sql | string | Yes | SQL query that produces the metric data. Must return at least the columns specified in column_mapping. |
column_mapping | object | Yes | Maps query output columns to Levered's expected fields |
column_mapping.anonymous_id | string | Yes | Column containing the user identifier |
column_mapping.timestamp | string | Yes | Column containing the event timestamp |
column_mapping.reward_type | string | No | Type of reward: bool (binary conversion) or numeric (continuous value) |
column_mapping.value | string | No | Column with the numeric reward value. Without it, each returned row counts as a reward of 1 |
Response (201):
{
"id": "metric-uuid",
"name": "Signup Conversion",
"sql": "SELECT user_id AS anonymous_id, converted_at AS timestamp FROM conversions",
"column_mapping": {
"anonymous_id": "anonymous_id",
"timestamp": "timestamp",
"reward_type": "bool"
},
"created_at": "2026-03-28T14:00:00Z",
"updated_at": null,
"meta": {
"request_id": "req_abc123",
"organization_id": "org_xyz"
}
}List metrics
GET /api/v2/warehouse/metricsAuth: Required
Returns all reward metrics in the organization. Assignment sources are not in the list.
Response:
{
"metrics": [
{
"id": "metric-uuid",
"name": "Signup Conversion",
"sql": "SELECT user_id AS anonymous_id, converted_at AS timestamp FROM conversions",
"column_mapping": {
"anonymous_id": "anonymous_id",
"timestamp": "timestamp",
"reward_type": "bool"
},
"created_at": "2026-03-28T14:00:00Z",
"updated_at": null
}
],
"meta": {
"request_id": "req_abc123",
"organization_id": "org_xyz"
}
}Get metric
GET /api/v2/warehouse/metrics/:idAuth: Required
Path parameters:
| Parameter | Type | Description |
|---|---|---|
id | string (UUID) | Metric ID |
Response: Returns the full metric object including sql and column_mapping.
Preview metric
POST /api/v2/warehouse/metrics/:id/previewAuth: Required
Executes the metric's SQL query and returns a sample of the results. Use it to check that the query returns the expected data before linking the metric to an optimization.
Path parameters:
| Parameter | Type | Description |
|---|---|---|
id | string (UUID) | Metric ID |
Query parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
limit | integer | 10 | Number of rows to return (1-1000) |
Response:
{
"rows": [
{ "anonymous_id": "user-abc", "timestamp": "2026-03-28T14:00:00Z" },
{ "anonymous_id": "user-def", "timestamp": "2026-03-28T14:05:00Z" }
],
"meta": {
"request_id": "req_abc123",
"organization_id": "org_xyz"
}
}Update metric
PUT /api/v2/warehouse/metrics/:idAuth: Required
Replaces a metric's name, SQL and column mapping. Takes the same body as Create metric. The new SQL is checked against your warehouse in the same way before it is saved. Works for reward metrics and for an optimization's exposure source, for example to filter test users out of both.
Response: the updated metric, as in Create metric.
Delete metric
DELETE /api/v2/warehouse/metrics/:idAuth: Required
Deletes a metric. If the metric is referenced by guardrails, the request fails with 409 Conflict.
Path parameters:
| Parameter | Type | Description |
|---|---|---|
id | string (UUID) | Metric ID |
Response: 204 No Content
Assignment source
Assignment sources define where Levered reads exposure (variant assignment) data from your warehouse. Each optimization is linked to one through assignment_source_id at creation. If assignment_source_id is omitted, Levered creates one for the optimization.
Create assignment source
Creates a new assignment source, or replaces the one with the same name.
POST /api/v2/warehouse/assignment-sourceAuth: Required
Request body:
{
"name": "Exposure Events",
"sql": "SELECT anonymous_id, timestamp, headline, cta_text FROM exposures",
"column_mapping": {
"anonymous_id": "anonymous_id",
"timestamp": "timestamp"
}
}| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Human-readable name |
sql | string | Yes | SQL query that returns exposure rows. Must include the design factor columns. |
column_mapping.anonymous_id | string | Yes | Column containing the user identifier |
column_mapping.timestamp | string | Yes | Column containing the event timestamp |
column_mapping.variant | string | No | Column containing a JSON-serialized variant object (e.g., {"headline": "A", "cta": "B"}) |
column_mapping.context | string | No | Column containing JSON context attributes |
column_mapping.factors | object | No | Maps design factor names to warehouse column names (e.g., {"headline": "headline_col"}) |
Response (201):
{
"id": "source-uuid",
"name": "Exposure Events",
"sql": "SELECT anonymous_id, timestamp, headline, cta_text FROM exposures",
"column_mapping": {
"anonymous_id": "anonymous_id",
"timestamp": "timestamp"
},
"created_at": "2026-03-28T14:00:00Z",
"updated_at": null,
"meta": {
"request_id": "req_abc123",
"organization_id": "org_xyz"
}
}Get assignment source
GET /api/v2/warehouse/assignment-sourceAuth: Required
Returns an assignment source configuration. If the organization has several, it returns one of them.
Preview assignment source
POST /api/v2/warehouse/assignment-source/previewAuth: Required
Executes the assignment source SQL and returns a sample of rows.
Response:
{
"rows": [
{ "anonymous_id": "user-abc", "timestamp": "2026-03-28T14:00:00Z", "headline": "Ship faster", "cta_text": "Start free" },
{ "anonymous_id": "user-def", "timestamp": "2026-03-28T14:01:00Z", "headline": "Build better", "cta_text": "Try it now" }
],
"meta": {
"request_id": "req_abc123",
"organization_id": "org_xyz"
}
}