Evaluate flags over HTTP

The flags decide route POST /v1/flags on the capture host, plus flag kinds, condition filters, rollout and sticky behaviour.

Embed
Preview of the card
<a href="https://lucidace.com/help/flags-decide"><img src="https://lucidace.com/help/_api/public/orgs/af34862a-c837-4478-8335-0505efe40459/spaces/2f4b888b-c4e6-488b-81bd-6e838fb12d2e/pages/e1850ce0-54db-4dbf-935d-caa79ae64138/social-card.svg?v=3e7ae33eec8b" alt="Evaluate flags over HTTP" width="600" height="315"></a>

You do not need an SDK to read flags. The capture host (the apiHost your SDK uses) answers POST /v1/flags with the value of every flag for one user. The same route is in GET /v1/openapi.json under the capture tag. It is on the capture host, not the app host.

Request

curl -X POST "https://<your capture host>/v1/flags" -H "Content-Type: application/json" -d '{
  "api_key": "lc_pk_...",
  "distinct_id": "user_123",
  "person_properties": {"plan": "pro"},
  "flag_keys": ["new-checkout"]
}'

Field

Required

Meaning

api_key

yes (or Authorization: Bearer <key>)

public or secret project key

distinct_id

yes, unless bucketing_key

who to evaluate for

bucketing_key

no

hash unit used instead of distinct_id

person_properties

no

properties for person filters

groups / group_properties

no

group keys by type, and their properties, for group filters

flag_keys

no

only evaluate these flags; omitted means all

Response

{"flags": {"new-checkout": {"enabled": true, "value": true, "reason": "condition_match", "condition_index": 0}}, "request_id": "..."}

If you sent flag_keys, any key this project does not have is listed in "unknown_flags":["..."], so a typo does not look like a flag that is off. The field is left out when there are none.

If your SDK ignores that field, the keys still show up: Data > Project health lists the 100 most recently requested unknown keys with the last time each was seen (read it with GET /v1/projects/{pid}/pipeline-health/unknown-flags, which returns {"data":[{"key","first_seen_at","last_seen_at"}]}). Keys longer than 200 characters are not recorded, and an unknown key is recorded within about 30 seconds of the request.

Per flag: enabled, value (true/false, or the variant key), variant and payload when there is one, reason and condition_index (the condition that decided it, -1 when none did).

reason

Meaning

condition_match

a condition's filters and rollout matched

no_condition_match

no condition matched; value is off

sticky_bucket

a stored assignment decided (see below)

out_of_rollout

early_exit: filters matched but the unit is outside the rollout

inactive, kill_switch

the flag is disabled

prerequisite_failed, prerequisite_missing, prerequisite_cycle

a prerequisite flag decided it

requires_server

needs a secret-key / server evaluation

no_bucketing_key

no distinct_id / unit to hash

holdout, namespace_excluded, app_context_excluded

held out, outside the layer, or not served to this app context

preview, user_preview

a QA preview override

If the plan quota is exhausted the response is 200 with "quota_limited": true and no flags; keep your cached values.

Record exposure

POST /v1/flags only decides; it records nothing. An experiment's results count a person from their first exposure event, so an HTTP caller must send one. The SDKs do this for you (expose() in sdks/node/src/flags.ts): once per user, flag and value they send two events with the same properties.

Event

Properties

$feature_flag_called

$feature_flag (the flag key), $feature_flag_response (the value or variant key you served), locally_evaluated (false for a value from this route), optional $feature_flag_request_id (the request_id of the decide response)

$exposure

the same properties

Experiment results read event IN ('$exposure', '$feature_flag_called') where $feature_flag equals the experiment's flag key, and take the variant from $feature_flag_response, so $exposure alone is enough for experiments. $feature_flag_called is what the flag usage and stale-flag views count, so send it too when you want those. Send the variant key as a string: an empty variant is ignored. An experiment can also name a custom exposure event instead.

Send them with the capture route when you act on the value, with the same distinct_id you decided for:

curl -X POST "https://<your capture host>/v1/batch" -H "Content-Type: application/json" -d '{
  "api_key": "lc_pk_...",
  "batch": [
    {"event": "$feature_flag_called", "distinct_id": "user_123",
     "properties": {"$feature_flag": "new-checkout", "$feature_flag_response": "test",
                    "locally_evaluated": false, "$feature_flag_request_id": "<request_id from the decide response>"}},
    {"event": "$exposure", "distinct_id": "user_123",
     "properties": {"$feature_flag": "new-checkout", "$feature_flag_response": "test",
                    "locally_evaluated": false, "$feature_flag_request_id": "<request_id from the decide response>"}}
  ]
}'

Give each event a uuid if you retry, so a duplicate is dropped. Do not send an exposure when your own fallback was served because the call failed: that is not an exposure (the SDKs skip it too).

One call instead. Add "record_exposure": true (default false) to the /v1/flags body and Lucida records both $feature_flag_called and $exposure for each flag it returns that decided (a flag that needs the server, or has no bucketing key, is skipped), so no second request is needed. It works on /v1/flags only, not /decide or /v1/flags/batch.

Dedupe window. Each event gets a deterministic id derived from the project, distinct_id, flag, value and the UTC day. Calling again for the same user, flag and value on the same UTC day (a retry, a page reload) adds no extra row once the warehouse merges duplicates (usually within minutes; reads with FINAL are exact at once). The exact key is the UUIDv5 of project|distinct_id|flag|value|UTC day (YYYY-MM-DD)|event name, one per event of the pair. A new value (the user moved from control to test) or a new UTC day records a new exposure.

Why per day. The key bounds the exposure log to one row per user, flag and value per day, so a busy page or a retry loop does not write one row per call, while a returning user and a changed variant still show up on the day they happen. It does not change experiment results: analysis attributes each person (unit) to the variant of their first exposure (argMin by timestamp, over rows collapsed with FINAL) and counts them once, so the later daily rows only feed the "switched variants" check. "send_exposure": true is the older switch: same pair, but a random id on every call, so it is not deduped.

Errors

Errors are RFC 9457 application/problem+json with type https://lucidace.com/help/problems#<class>.

Status

Meaning

Retry?

400

malformed body, or no distinct_id / bucketing_key

fix it first

401

missing or unknown key

no

403

the request origin is on the project's flag blocklist

no

429

rate limit; see Retry-After

yes, with backoff

503

flag definitions unavailable

yes

Defining flags

Flags are created with POST /v1/projects/{project_id}/flags.

kind

Notes

boolean

the default; no variants

multivariate

needs two or more variants, whose rollout_pct sum to 100

remote_config

serves a JSON payload (can be encrypted)

migration

variants for staged migrations

ai_config

variants carrying model configuration

Only multivariate, migration and ai_config take variants; anything else is 400.

A flag has ordered filters.conditions[]. A condition matches when all its filters[] pass and the unit falls inside its rollout_pct (0-100). The first matching condition decides. A filter is {type, key, op, value}:

type

Reads key from

person

person_properties

group

group properties (also needs group_type)

cohort

cohort membership

device, geo

device / geo properties

app_version

the SDK's app version

flag

another flag's value (prerequisite)

context

a multi-kind context (also needs context_kind: user, device or org)

event

an event count in the session or page (scope)

op

eq, neq, in, not_in

equality and set membership

contains, ncontains, icontains, not_icontains, starts_with, not_starts_with, ends_with, not_ends_with, regex, nregex

strings

gt, gte, lt, lte, between, not_between

numbers

is_set, is_not_set

presence

is_date_before, is_date_after

dates

semver_eq, semver_neq, semver_gt, semver_gte, semver_lt, semver_lte, semver_tilde, semver_caret, semver_wildcard

versions

array_contains_any, array_contains_all, array_contains_none

list properties

ip_in_cidr, ip_not_in_cidr

request IP

Change a flag's first-condition rollout with PATCH /v1/projects/{project_id}/flags/{id}/rollout {"rollout_pct": 100} (the old name rollout_percentage is still accepted).

Rollout and sticky behaviour

Each unit hashes to a fixed point in 0-100 using the flag key, its salt and the unit id. It is inside the rollout when that point is below rollout_pct. The hash does not depend on the percentage, so raising a rollout only adds users; it never removes anyone who was already in, and lowering it only removes the ones with the highest points.

  • stickiness (top level) chooses the unit that is hashed: distinct_id (default), person_id, device_id, group:<type> or context:<user|device|org>.

  • filters.sticky: true additionally stores the assignment so it survives allocation changes. Only "on" results are stored: the true of a boolean flag, or the variant a user was served. A user who was outside the rollout is not pinned and is hashed again next time, so raising the rollout can turn them on. A pinned user keeps their value (reason sticky_bucket) even if the rollout is later lowered or the variant weights change. The first stored assignment wins.

Updated