LeveredDocs
API Reference

Optimizations

Endpoints for creating, managing, and serving optimizations.

All endpoints are under /api/v2/optimizations. Unless noted otherwise, requests require an Authorization: Bearer <token> header.

List optimizations

GET /api/v2/optimizations

Auth: Required

Query parameters:

ParameterTypeDefaultDescription
limitinteger10Maximum number of results (1-100)
order_bystringupdated_atSort field: updated_at or created_at
include_archivedbooleanfalseInclude archived optimizations

Response:

{
  "optimizations": [
    {
      "id": "699ede80-c94b-4f98-9c79-dd3e07748703",
      "name": "Landing Page Hero",
      "status": "live",
      "model_status": "trained",
      "model_id": "4754cae0-9a5d-4691-91af-6d15ccc1f82e",
      "created_at": "2026-01-15T10:30:00Z",
      "updated_at": "2026-03-28T14:22:00Z",
      "summary": {
        "variants_count": 6,
        "users": 1310
      },
      "summary_pending": false
    }
  ],
  "meta": {
    "request_id": "req_abc123",
    "organization_id": "org_xyz"
  }
}

Each row also carries the optimization's settings (such as description, control_type and holdout_percentage). Lifts are measured against what control_type names: the baseline variant (variant), the current version (external) or an even split of traffic (none). In summary, variants_count is the number of variants in the design and users counts all users served so far. The summary object is null when no users have been served yet or the counts cannot be loaded. If summary_pending is true, the summary could not be loaded in time. Fetch it with GET /api/v2/optimizations/:id/summary.

The optimization's model figures (lift, confidence, probability of best, factor effects, importance) are not in any optimization response: query them from the posterior.

Get optimization

GET /api/v2/optimizations/:id

Auth: Required

Path parameters:

ParameterTypeDescription
idstring (UUID)Optimization ID

Response: Returns optimization (its settings, including status, reward_metric_id, assignment_metric_id, holdout_percentage and control_type; see List optimizations), model_config (the full design, including level ids and any factor and level labels and descriptions), draft_readiness (for drafts, otherwise null) and shipped_policy (null unless shipped).

Create optimization

POST /api/v2/optimizations

Auth: Required

Request body:

{
  "name": "Landing Page Hero",
  "training_data_config": {
    "reward": {
      "name": "signup",
      "type": "bool"
    },
    "design_factors": [
      {
        "name": "headline",
        "dtype": "str",
        "levels": ["Ship faster", "Save time", "Build better"]
      },
      {
        "name": "cta_text",
        "dtype": "str",
        "levels": ["Start free", "Try it now"]
      }
    ],
    "context_factors": [
      {
        "name": "device",
        "dtype": "str",
        "levels": ["mobile", "desktop"]
      }
    ],
    "attribution": {
      "type": "last_touch",
      "conversion_window_hours": 24
    }
  },
  "reward_metric_id": "metric-uuid",
  "holdout_percentage": 10
}
FieldTypeRequiredDescription
namestringYesHuman-readable name
descriptionstringNoOptional description (max 1000 characters)
training_data_config.rewardobjectNoReward definition with name and type (bool or numeric). Defaults to {"name": "reward", "type": "bool"}
training_data_config.design_factorsarrayYesThe design factors of the optimization. Each has name, dtype (str or bool) and levels, and optionally label (max 120 characters), description and hypothesis (max 1000 each). A level is a value or an object {"value", "label", "description"}. Labels and descriptions are for display only and do not change what is served
training_data_config.context_factorsarrayNoContextual variables for personalization. Same shape as design factors
training_data_config.attributionobjectNoAttribution model. type is last_touch, conversion_window_hours sets the lookback (default: 24)
reward_metric_idstring (UUID)YesLink a reward metric at creation time
assignment_source_idstring (UUID)NoLink an assignment source. If omitted, Levered creates one that points to an exposures table in your warehouse
holdout_percentageintegerNoPercentage of traffic to hold out for control (0-50, default: 10)
control_typestringNoWhat holdout users see. With variant (default), one of the variants is the baseline and Levered serves it to the holdout. With external, the holdout keeps a version that is not one of the variants. external requires holdout_percentage above 0, and holdout users train the model as that current version, never as a variant. With none, all variants are new. none requires holdout_percentage 0. Guardrails need holdout_percentage above 0 with any control type. See Holdout
baseline_variantobjectWith control_type variantThe baseline: today's experience, as a map of factor name to level value, one entry for each design factor. Required with control_type variant (the default); not allowed with external or none
guardrailsarrayNoGuardrail definitions to attach at creation time (max 10)
reward_conversion_windowobjectNoConversion window for the reward metric: {"value": 7, "unit": "days"} (hours or days), or null for no window. Default: 24 hours
excluded_combinationsarrayNoUp to 50 maps of factor name to level value that are never served. Partial maps exclude every variant that matches them

The design may have at most 100 variants (406 otherwise). Creating an optimization with the same design factor names as an existing draft, live, paused or shipped optimization returns 409.

Response:

{
  "id": "699ede80-c94b-4f98-9c79-dd3e07748703",
  "model_id": "4754cae0-9a5d-4691-91af-6d15ccc1f82e",
  "meta": {
    "request_id": "req_abc123",
    "organization_id": "org_xyz"
  }
}

Update optimization

PATCH /api/v2/optimizations/:id

Auth: Required

Request body:

{
  "status": "completed"
}

To rename an optimization or change its description, use Rename optimization. PATCH /api/v2/optimizations/:id rejects name and description.

training_data_config in PATCH accepts only design_factors, and only while the optimization is a draft. A training_data_config with any other key, or without design_factors, returns 400. The new design is validated like a design at creation. Replacing the design resets the model and restarts the variant numbering. excluded_combinations can only be sent together with design_factors. A replacement design drops the earlier exclusions, so send the exclusions again with the new design. While the model is training, a design replacement is rejected.

Allowed status transitions:

FromTo
draftlive
livepaused, shipped, completed, archived
pausedlive, shipped, completed, archived
shippedlive, completed
completedarchived

Going from draft to live requires at least one call to /serve for the optimization. A dry_run call counts.

baseline_variant can be changed with PATCH only while the optimization is a draft. control_type can also be changed with PATCH. Setting or removing external is allowed only while the optimization is a draft. Switching to none requires holdout_percentage 0. A PATCH that switches to none or sets holdout_percentage to 0 removes the guardrails, because guardrails compare against the holdout. A variant optimization always names its baseline: send baseline_variant when switching to control_type variant, and with a replacement design that no longer contains the current baseline. It can't be cleared while the control type is variant. The holdout percentage of an optimization with control type external can only be changed while the optimization is a draft.

Setting status to shipped requires a trained model. It freezes the leading variant for each context into a policy, which GET /optimizations/:id returns as shipped_policy. holdout_percentage cannot be changed while an optimization is shipped.

Rename optimization

PATCH /api/v2/optimizations/:id/metadata

Auth: Required

Changes the name, the description, or both. Works at any status.

FieldTypeRequiredDescription
namestringNoNew name, 1-255 characters
descriptionstring or nullNoNew description, max 1000 characters. null clears it

Response: { "id", "name", "description", "meta" }.

Label factors and levels

PATCH /api/v2/optimizations/:id/factors/:factor_name/metadata
PATCH /api/v2/optimizations/:id/factors/:factor_name/levels/:level_id/metadata

Auth: Required

Sets the display label (max 120 characters) and description (max 1000) of a design factor or level, and the hypothesis (max 1000) of a factor. Works at any status and does not change what is served. Send null or "" to clear a field. An empty body returns 400.

Delete (archive) optimization

DELETE /api/v2/optimizations/:id

Auth: Required

Archives the optimization (also allowed for drafts). Data is retained but the optimization is hidden from default list views. Returns 400 if it is shipped (stop it first) or already archived.

Response:

{
  "id": "699ede80-c94b-4f98-9c79-dd3e07748703",
  "status": "archived",
  "meta": {
    "request_id": "req_abc123",
    "organization_id": "org_xyz"
  }
}

With ?hard=true, a draft or an optimization that never received a /serve call is deleted permanently (mode: "hard"). An archived optimization with traffic is removed from all lists (mode: "soft"). For other optimizations with traffic, the request returns 400. Archive them first.

Response with ?hard=true:

{
  "id": "699ede80-c94b-4f98-9c79-dd3e07748703",
  "deleted": true,
  "mode": "hard",
  "meta": {
    "request_id": "req_abc123",
    "organization_id": "org_xyz"
  }
}

Upload variant screenshot

POST /api/v2/optimizations/:id/variants/by-number/:n/screenshot

Auth: Required

Uploads a single PNG that shows variant :n rendered in your app, as a multipart request. The file is validated by its magic bytes (PNG only). The size limit is 10 MB. Re-uploading overwrites the previous screenshot. Variant numbers are assigned when results are first fetched. If the variant number is unknown, fetch GET /api/v2/optimizations/:id/results/state once and retry.

levered optimizations screenshot normally calls this endpoint. The command captures and uploads all variants in one step.

Request: multipart/form-data with a single file field.

Response:

{
  "ok": true,
  "variant_number": 3,
  "meta": {
    "request_id": "req_abc123",
    "organization_id": "org_xyz"
  }
}

Get variant screenshot

GET /api/v2/optimizations/:id/variants/by-number/:n/screenshot

Auth: Required

Returns the stored PNG (Content-Type: image/png), or 404 if no screenshot has been uploaded for that variant. Screenshots are private to the owning organization and are only served through this endpoint. The variants in GET /api/v2/optimizations/:id/results/state carry a screenshot_uploaded_at timestamp (null when absent) so clients can tell which variants have a preview.

Serve variant

POST /api/v2/optimizations/:id/serve

Auth: Not required (public endpoint). Rate limited to 500 requests/min per IP.

Returns one variant selected for the user by the optimization policy.

Request body:

{
  "anonymous_id": "user-abc",
  "context": {
    "device": "mobile"
  }
}
FieldTypeRequiredDescription
anonymous_idstringYesStable user identifier. The exposure is joined with rewards in your warehouse on this id
contextobjectNoContext factor values for personalization
dry_runbooleanNoPreview mode. Levered makes the same decision, records nothing and does not pin the user to the variant. Default: false

Returns 400 unless the optimization is live or shipped. With dry_run, draft and paused are allowed too.

Each successful request returns one selection in the variants array. Omit the legacy n_variants field. An explicit 1 is also accepted. Counts greater than 1 are rejected with HTTP 400.

Response:

{
  "variants": [
    {
      "props": { "headline": "Ship faster", "cta_text": "Start free" },
      "expected_reward": 0.31
    }
  ],
  "optimization_id": "699ede80-c94b-4f98-9c79-dd3e07748703",
  "is_holdout": false,
  "trained": true,
  "meta": {
    "request_id": "req_abc123",
    "organization_id": "org_xyz"
  }
}
FieldTypeDescription
variantsarrayOne selected variant with its design factor values and expected reward
optimization_idstringThe optimization that served this variant
optimization_namestringName of the optimization
shippedbooleanPresent and true when the optimization is shipped. Each user then gets the leading variant for their context
is_holdoutbooleantrue if the user is in the holdout. With control_type variant, the variant is the baseline. With external, the variant has no factor values and the app shows its current version
trainedbooleantrue if the model has been trained, false for an untrained policy