Skip to content

Evaluation

The evaluation endpoints are the core of FlagBridge. They determine whether a flag is enabled for a given user context.

POST /v1/evaluate

Evaluate a single flag.

Auth: Live key, Test key, or Admin key

POST /v1/evaluate
Authorization: Bearer fb_live_YOUR_KEY
Content-Type: application/json

Request body

json
{
  "flagKey": "new-checkout-flow",
  "context": {
    "userId": "user-123",
    "email": "user@example.com",
    "country": "BR",
    "plan": "pro"
  }
}
FieldTypeRequiredDescription
flagKeystringYesThe flag's unique key
contextobjectNoEvaluation context attributes
context.userIdstringNoUnique user identifier (used for percentage rollouts)

Response

json
{
  "flagKey": "new-checkout-flow",
  "enabled": true,
  "variant": null,
  "reason": "TARGETING_RULE_MATCH",
  "ruleId": "rule_abc123",
  "evaluatedAt": "2026-03-31T20:00:00.000Z"
}
FieldTypeDescription
flagKeystringThe evaluated flag key
enabledbooleanWhether the flag is enabled
variantstring | nullVariant value (for multi-variant flags)
reasonstringEvaluation reason (see below)
ruleIdstring | nullID of the matching rule, if any
evaluatedAtstringISO 8601 timestamp

Evaluation reasons

ReasonDescription
FLAG_DISABLEDFlag is globally disabled for this environment
FLAG_ENABLEDFlag is globally enabled (no targeting rules)
TARGETING_RULE_MATCHA targeting rule matched
PERCENTAGE_ROLLOUTIncluded in percentage rollout
PERCENTAGE_ROLLOUT_EXCLUDEDExcluded from percentage rollout
TEST_OVERRIDEOverridden by a test session
FLAG_NOT_FOUNDFlag does not exist (returns enabled: false)

Examples

bash
curl -X POST https://api.flagbridge.io/v1/evaluate \
  -H "Authorization: Bearer fb_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "flagKey": "new-checkout-flow",
    "context": {
      "userId": "user-123",
      "plan": "pro"
    }
  }'
typescript
const result = await client.evaluate('new-checkout-flow', {
  userId: 'user-123',
  plan: 'pro',
});

POST /v1/evaluate/batch

Evaluate multiple flags in a single request. More efficient than multiple individual requests.

Auth: Live key, Test key, or Admin key

POST /v1/evaluate/batch
Authorization: Bearer fb_live_YOUR_KEY
Content-Type: application/json

Request body

json
{
  "flags": ["new-checkout-flow", "dark-mode", "sidebar-v2"],
  "context": {
    "userId": "user-123",
    "plan": "pro"
  }
}
FieldTypeRequiredDescription
flagsstring[]YesArray of flag keys to evaluate (max 50)
contextobjectNoEvaluation context (applied to all flags)

Response

json
{
  "results": {
    "new-checkout-flow": {
      "flagKey": "new-checkout-flow",
      "enabled": true,
      "variant": null,
      "reason": "TARGETING_RULE_MATCH"
    },
    "dark-mode": {
      "flagKey": "dark-mode",
      "enabled": false,
      "variant": null,
      "reason": "FLAG_DISABLED"
    },
    "sidebar-v2": {
      "flagKey": "sidebar-v2",
      "enabled": true,
      "variant": "compact",
      "reason": "PERCENTAGE_ROLLOUT"
    }
  },
  "evaluatedAt": "2026-03-31T20:00:00.000Z"
}

Examples

bash
curl -X POST https://api.flagbridge.io/v1/evaluate/batch \
  -H "Authorization: Bearer fb_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "flags": ["new-checkout-flow", "dark-mode"],
    "context": { "userId": "user-123" }
  }'
typescript
const results = await client.evaluateBatch(
  ['new-checkout-flow', 'dark-mode'],
  { userId: 'user-123' }
);

results['new-checkout-flow'].enabled; // true
results['dark-mode'].enabled;         // false

INFO

Batch evaluation uses a single network round-trip. Prefer it over multiple evaluate calls when you need several flags at once — especially in server-rendered pages.

Test session header

When running E2E tests, pass the session token as a header to apply test overrides:

bash
curl -X POST https://api.flagbridge.io/v1/evaluate \
  -H "Authorization: Bearer fb_test_YOUR_KEY" \
  -H "X-FlagBridge-Session: sess_abc123" \
  -H "Content-Type: application/json" \
  -d '{"flagKey": "new-checkout-flow", "context": {"userId": "user-123"}}'

See the Testing API for how to create sessions and set overrides.