# Feature flags

Create, target, roll out and schedule feature flags, then evaluate them for a user with the project API key or locally with a personal API key.

Feature flags let your tests check what each user sees before and after you change a rollout. The example sets the key, project and project API key of the default scenario, creates a flag for everyone and evaluates it for one user:

```bash
KEY=phx_rysticexamplepersonalkey000000000000000
TOKEN=phc_93a00453928e7bff26aac13f55056c3e3f5fdd7c2eb
FLAGS="$RYSTIC_URL/api/projects/3104/feature_flags"
curl -s -X POST "$FLAGS/" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"key":"new-checkout","filters":{"groups":[{"properties":[],"rollout_percentage":100}]}}' | jq -c '{id, key, active, version}'
# -> {"id":1,"key":"new-checkout","active":true,"version":1}
curl -s -X POST "$RYSTIC_URL/flags/?v=2" -H 'Content-Type: application/json' -d '{"token":"'"$TOKEN"'","distinct_id":"user_1"}' | jq -c '.flags["new-checkout"] | {enabled, variant, reason: .reason.code}'
# -> {"enabled":true,"variant":null,"reason":"condition_match"}
```

Flags are managed with a personal API key and evaluated with the project API key, as [Auth](https://www.rystic.ai/docs/simulators/posthog.md#auth) describes. The default scenario starts with no flags, so the first flag you create gets `id` 1.

## Target users by a person property

To show a flag only to some users, add a condition on a person property and send that property with the evaluation. A user whose `plan` is `pro` matches, and any other user gets `no_condition_match`:

```bash
curl -s -X POST "$FLAGS/" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"key":"pro-only","filters":{"groups":[{"properties":[{"key":"plan","value":["pro"],"operator":"exact","type":"person"}],"rollout_percentage":100}]}}' | jq -c '{id, key}'
# -> {"id":2,"key":"pro-only"}
curl -s -X POST "$RYSTIC_URL/flags/?v=2" -d '{"token":"'"$TOKEN"'","distinct_id":"user_9","person_properties":{"plan":"pro"}}' | jq -c '.flags["pro-only"] | {enabled, reason: .reason.code}'
# -> {"enabled":true,"reason":"condition_match"}
curl -s -X POST "$RYSTIC_URL/flags/?v=2" -d '{"token":"'"$TOKEN"'","distinct_id":"user_9","person_properties":{"plan":"free"}}' | jq -c '.flags["pro-only"] | {enabled, reason: .reason.code}'
# -> {"enabled":false,"reason":"no_condition_match"}
```

To evaluate only some flags, list their keys in `flag_keys_to_evaluate`:

```bash
curl -s -X POST "$RYSTIC_URL/flags/?v=2" -d '{"token":"'"$TOKEN"'","distinct_id":"user_9","flag_keys_to_evaluate":["pro-only"]}' | jq -c '.flags | keys'
# -> ["pro-only"]
```

## Roll a flag out to a percentage

Lower a condition's `rollout_percentage` to release a flag to part of your users. Each update raises the flag's `version`. At 30 percent, four of twenty sample users get the flag, and a user outside the rollout gets `out_of_rollout_bound`:

```bash
curl -s -X PATCH "$FLAGS/1/" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"filters":{"groups":[{"properties":[],"rollout_percentage":30}]}}' | jq -c '{version, rollout: .filters.groups[0].rollout_percentage}'
# -> {"version":2,"rollout":30}
for u in $(seq 20); do curl -s -X POST "$RYSTIC_URL/flags/?v=2" -d '{"token":"'"$TOKEN"'","distinct_id":"user_'"$u"'"}' | jq -r --arg u "$u" 'select(.flags["new-checkout"].enabled) | $u'; done | paste -sd ' ' -
# -> 2 3 4 12
curl -s -X POST "$RYSTIC_URL/flags/?v=2" -d '{"token":"'"$TOKEN"'","distinct_id":"user_1"}' | jq -c '.flags["new-checkout"] | {enabled, reason: .reason.code}'
# -> {"enabled":false,"reason":"out_of_rollout_bound"}
```

The same `distinct_id` gets the same result on every call, so a test can pick a user known to be inside or outside the rollout.

## Test each variant of a multivariate flag

A multivariate flag splits users between variants, and a variant can return a payload. Of ten sample users, four get `control` and six get `test`, which includes its JSON payload in `metadata.payload`:

```bash
curl -s -X POST "$FLAGS/" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"key":"checkout-copy","filters":{"groups":[{"properties":[],"rollout_percentage":100}],"multivariate":{"variants":[{"key":"control","rollout_percentage":50},{"key":"test","rollout_percentage":50}]},"payloads":{"test":"{\"color\":\"green\"}"}}}' | jq -c '{id, key}'
# -> {"id":3,"key":"checkout-copy"}
for u in $(seq 10); do curl -s -X POST "$RYSTIC_URL/flags/?v=2" -d '{"token":"'"$TOKEN"'","distinct_id":"user_'"$u"'"}' | jq -r '.flags["checkout-copy"].variant'; done | sort | uniq -c | awk '{print $2, $1}'
# -> control 4
# -> test 6
curl -s -X POST "$RYSTIC_URL/flags/?v=2" -d '{"token":"'"$TOKEN"'","distinct_id":"user_2"}' | jq -c '.flags["checkout-copy"] | {variant, payload: .metadata.payload}'
# -> {"variant":"test","payload":"{\"color\":\"green\"}"}
```

## Turn a flag off or archive it

Set `active` to `false` to switch a flag off for everyone. Evaluation then returns `disabled` as the reason. Archiving a flag also switches it off and moves it out of the default list into `?archived=true`:

```bash
curl -s -X PATCH "$FLAGS/1/" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"active":false}' | jq -c '{active, version}'
# -> {"active":false,"version":3}
curl -s -X POST "$RYSTIC_URL/flags/?v=2" -d '{"token":"'"$TOKEN"'","distinct_id":"user_2"}' | jq -c '.flags["new-checkout"] | {enabled, reason: .reason.code}'
# -> {"enabled":false,"reason":"disabled"}
curl -s -X POST "$FLAGS/2/archive/" -H "Authorization: Bearer $KEY" | jq -c '{archived, active, status}'
# -> {"archived":true,"active":false,"status":"ARCHIVED"}
curl -s "$FLAGS/" -H "Authorization: Bearer $KEY" | jq -c '[.results[].key]'
# -> ["new-checkout","checkout-copy"]
curl -s "$FLAGS/?archived=true" -H "Authorization: Bearer $KEY" | jq -c '[.results[].key]'
# -> ["pro-only"]
```

## Evaluate flags locally

A server library that evaluates flags in its own process downloads the definitions from `GET /flags/definitions`. Send the project API key as `token` and the personal API key as the bearer token. Without the bearer token, the request returns 401:

```bash
curl -s "$RYSTIC_URL/flags/definitions?token=$TOKEN" -H "Authorization: Bearer $KEY" | jq -c '[.flags[] | {key, active}]'
# -> [{"key":"new-checkout","active":false},{"key":"pro-only","active":false},{"key":"checkout-copy","active":true}]
curl -s "$RYSTIC_URL/flags/definitions?token=$TOKEN" -w '\n%{http_code}\n' | jq -r '.code? // .'
# -> not_authenticated
# -> 401
```

Local evaluation has its own request limit, shared by the whole project. [Rate limits](https://www.rystic.ai/docs/simulators/posthog/features/rate-limits.md) shows how to turn it on and what a refused request returns.

## Schedule a flag change

Load the `posthog_flag_experiment` scenario to start from a project with four flags and two scheduled changes. Its project is 3103, with its own project API key. One seeded change switched on `express-pay-beta` and has `executed_at` set. The other, which switches off `onboarding-checklist`, has not run:

```bash
curl -s -X POST "$RYSTIC_URL/_rystic/scenario" -o /dev/null -w '%{http_code}\n' -d '{"name":"posthog_flag_experiment"}'
# -> 204
PROJECT="$RYSTIC_URL/api/projects/3103"
curl -s "$PROJECT/scheduled_changes/" -H "Authorization: Bearer $KEY" | jq -c '.results[] | {id, record_id, payload, executed_at}'
# -> {"id":5401,"record_id":"5104","payload":{"operation":"update_status","value":true},"executed_at":"2026-02-27T08:00:00.000000Z"}
# -> {"id":5402,"record_id":"5103","payload":{"operation":"update_status","value":false},"executed_at":null}
```

To schedule a change, name the flag's id in `record_id` with `model_name` set to `FeatureFlag`. Read the changes for one flag with `?record_id=`:

```bash
curl -s -X POST "$PROJECT/scheduled_changes/" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"record_id":"5102","model_name":"FeatureFlag","payload":{"operation":"update_status","value":false},"scheduled_at":"2026-03-02T09:00:00Z"}' | jq -c '{id, record_id, scheduled_at, executed_at}'
# -> {"id":5403,"record_id":"5102","scheduled_at":"2026-03-02T09:00:00Z","executed_at":null}
curl -s "$PROJECT/scheduled_changes/?record_id=5102" -H "Authorization: Bearer $KEY" | jq -c '[.results[].id]'
# -> [5403]
```

The flag's activity log names a change that ran on a schedule in `detail.trigger`:

```bash
curl -s "$PROJECT/feature_flags/5104/activity/" -H "Authorization: Bearer $KEY" | jq -c '.results[] | {activity, trigger: .detail.trigger.job_type}'
# -> {"activity":"updated","trigger":"scheduled_change"}
```

## Link a flag to an early access feature

An early access feature lets users opt in to a feature behind a flag. Created with a `name` and no flag, it creates a flag whose key comes from the name. To reuse a flag, send its id as `feature_flag_id`. A multivariate flag is refused:

```bash
curl -s -X POST "$PROJECT/early_access_feature/" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"name":"Gift cards","stage":"concept"}' | jq -c '{name, stage, flag: .feature_flag.key, rollout: .feature_flag.filters.groups[0].rollout_percentage}'
# -> {"name":"Gift cards","stage":"concept","flag":"gift-cards","rollout":0}
curl -s -X POST "$PROJECT/early_access_feature/" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"name":"Redesign preview","stage":"beta","feature_flag_id":5101}' -w '\n%{http_code}\n' | jq -r '.detail? // .'
# -> Multivariate feature flags are not supported here.
# -> 400
```

## Reference

Each scenario's project has its own project API key:

| Scenario | Project id | Project API key |
|---|---|---|
| `posthog_first_event` | 3104 | `phc_93a00453928e7bff26aac13f55056c3e3f5fdd7c2eb` |
| `posthog_flag_experiment` | 3103 | `phc_45f8a0bcb7d18d1ec767bab3d1dd386fb5c692b93c1` |

The flags `posthog_flag_experiment` seeds, all active and at 100 percent rollout:

| Id | Key | Kind |
|---|---|---|
| 5101 | `checkout-redesign` | multivariate, `control` and `test` at 50 percent each |
| 5102 | `pricing-page-copy` | multivariate, `control` and `test` at 50 percent each |
| 5103 | `onboarding-checklist` | multivariate, `control` and `test` at 50 percent each |
| 5104 | `express-pay-beta` | boolean, linked to the early access feature `Express pay` |

Deleting a flag, duplicate keys and the change feed have their own entries in [Limitations](https://www.rystic.ai/docs/simulators/posthog.md#limitations).

---

Source: https://www.rystic.ai/docs/simulators/posthog/features/feature-flags · Markdown: https://www.rystic.ai/docs/simulators/posthog/features/feature-flags.md
