Skip to content

Evaluate Endpoint

Evaluates a single flag for the provided user context and returns the resolved variation.

POST /evaluate
{
"flagKey": "dark-mode",
"context": {
"userId": "user-123",
"attributes": {
"plan": "pro",
"country": "US"
}
}
}
FieldTypeRequiredDescription
flagKeystringYesThe flag to evaluate
contextobjectYesUser context for targeting
context.userIdstringNoUnique user identifier (used for percentage rollouts)
context.attributesobjectNoCustom attributes for targeting rules
{
"key": "dark-mode",
"variation": "on",
"value": true,
"reason": "fallthrough"
}
FieldTypeDescription
keystringThe flag key that was evaluated
variationstringKey of the variation that was served
valueanyThe resolved value (type depends on the flag’s type)
reasonstringWhy this variation was selected (see below)
prerequisiteKeystringPresent only when reason is prerequisite-failed: the key of the parent flag that gated this flag off

The reason is returned verbatim from the evaluator and is lower-case:

ReasonDescription
rule-match:<ruleId>A targeting rule matched the context. The matched rule’s ID is appended to the reason.
fallthroughFlag is on but no rules matched; the fallthrough variation was served.
flag-disabledFlag is off; the off variation was served.
prerequisite-failedA prerequisite flag did not serve its required variation; the off variation was served. prerequisiteKey names the parent flag. See Prerequisite Flags.

A flag key that does not exist returns 404 Not Found rather than a reason value.

  • 401 Unauthorized — Invalid or missing SDK key.
  • 404 Not Found — The flag key does not exist in this environment.

When you call this endpoint, the server runs the following logic:

  1. Flag disabled — If enabled is false, return the offVariation (reason flag-disabled).
  2. Prerequisites — Evaluate each prerequisite’s parent flag against the same context. If any parent does not serve its required variation, return the offVariation (reason prerequisite-failed, with prerequisiteKey set to the first failing parent).
  3. Rules — Evaluate each rule in priority order. If a rule’s conditions match the context, serve according to the rule’s serve config (reason rule-match:<ruleId>).
  4. Fallthrough — If no rules match, serve according to the fallthrough config (reason fallthrough).

For Rollout serve configs, the user is bucketed into a variation based on a hash of the bucketBy attribute (defaulting to userId) and the configured salt.