Feature Flags
Temps includes feature flags scoped to a project and overridable per environment. Changing a flag takes effect in seconds. Changing an environment variable needs a redeploy. That difference is the whole point.
Feature flags are Stable. Creating flags, per-environment values, the kill switch and reading flags with @temps-sdk/node-sdk work with the stable CLI and SDK. Targeting rules, rollouts and variants work in the console. Managing them from the CLI (flags rules, flags evaluate), and reading flags in the browser with useFlag, need the beta packages: @temps-sdk/cli@beta and @temps-sdk/react-analytics@beta or @temps-sdk/analytics-core@beta.
- Typed values: boolean, string, number and JSON.
- A default value per flag, overridable per environment.
- A one-action kill switch per environment.
- Targeting rules that serve a value by user attribute, country, browser and more.
- Percentage rollouts and multi-variant splits that stay the same for each user.
- Reads from your own origin in the browser, and OpenFeature (OFREP) for any language.
- Synchronous, in-memory reads in your server code, with no network call per check.
- A full audit trail of who changed what.
Flags and environment variables
Both are runtime configuration, and they are not interchangeable.
| Environment variable | Feature flag | |
|---|---|---|
| Time to take effect | A redeploy | Seconds |
| Good for | Secrets, connection strings, static config | Kill switches, gradual enablement, runtime tuning |
| Typed | No, always a string | Yes: bool, string, number, JSON |
| Per environment | Yes | Yes |
| Encrypted at rest | Yes, when marked secret | No |
Never put a secret in a feature flag. Flag values are not encrypted, and a flag can be marked visible to browsers. Use an environment variable marked secret instead.
Create a flag
In the dashboard, open your project, go to Feature Flags and choose New flag.
- Key: the identifier you use in code, for example
checkout.v2. Lowercase letters, digits, dot, underscore and hyphen. It can't be changed after you create it, because it appears verbatim in your source. - Type:
bool,string,numberorjson. It is fixed at creation, because changing it would invalidate every stored value. - Default value: served whenever nothing more specific applies, and whenever the flag is disabled.
- Expose to browsers: off by default. Leave it off unless a browser needs to read the flag.
Or from the CLI:
bunx @temps-sdk/cli flags create checkout.v2 \
--type bool \
--default false \
--description "New checkout flow"
Read flags in your app
Install the SDK and initialise it once at startup. TEMPS_API_URL and TEMPS_API_TOKEN are injected into every Temps deployment, so there is nothing to configure.
bun add @temps-sdk/node-sdk
import { flags } from '@temps-sdk/node-sdk'
// Fetches the flag set once, then refreshes in the background.
await flags.init()
app.get('/checkout', (req, res) => {
// Synchronous, in-memory, no network I/O.
const useV2 = flags.get('checkout.v2', { key: req.user.id }, false)
return useV2 ? renderCheckoutV2(res) : renderCheckout(res)
})
The third argument is a fallback. It is returned whenever the flag can't be resolved: an unknown key, a snapshot that hasn't loaded yet, or a stored value that doesn't match the flag's type. Always pass the value you want if Temps is unreachable.
flags.init() never throws. If the flag service is unreachable, every read returns your fallback, flags.ready stays false and flags.lastError explains why. A flag outage must not stop your app from booting. The refresh interval and other client options are in the Node SDK reference.
When a flag isn't doing what you expect, ask for the reason:
const { value, reason } = flags.getDetails('checkout.v2', {}, false)
reason.kind | Meaning |
|---|---|
RULE_MATCH | Targeting rule reason.index (counting from 0) matched |
PERCENTAGE_ROLLOUT | Rule reason.index matched and the user's bucket put them in its rollout or split |
ENVIRONMENT_VALUE | A value is set for this environment |
DEFAULT | Nothing is set here, so the flag default was served |
DISABLED | The kill switch is on, so the default was served |
FLAG_NOT_FOUND | No such flag, or it is archived, so your fallback was served |
ERROR | A stored value or rule couldn't be used, so the default was served |
The kill switch
Disabling a flag in an environment makes it serve its default value and ignore any value set there. It doesn't delete the value, and enabling it again restores exactly what was set before.
# Incident: turn it off now.
bunx @temps-sdk/cli flags disable checkout.v2 --environment production
# Later, restore the previous value.
bunx @temps-sdk/cli flags enable checkout.v2 --environment production
This is why the default value matters: it is what your users get during an incident. Set it to the safe, known-good behaviour.
Per-environment values
A flag is defined once for the project and overridden per environment, so preview and production can differ without touching your code.
bunx @temps-sdk/cli flags set checkout.v2 true --environment preview
bunx @temps-sdk/cli flags set checkout.v2 false --environment production
# Drop the override so this environment follows the flag default again.
bunx @temps-sdk/cli flags clear checkout.v2 --environment preview
Your app resolves a flag in this order:
- The flag is missing or archived: your fallback.
- The kill switch is on: the flag default.
- The first targeting rule that matches: what it serves.
- A value is set for this environment: that value.
- Otherwise: the flag default.
Targeting rules
A rule serves a different value to the users who match it. Rules are set per environment and checked from the top. The first one that matches decides. A user who matches no rule gets the environment value.
In the dashboard, open the flag and choose Add rules under an environment. Each rule has:
- Conditions, all of which must hold: an attribute, an operator and a value, for example
planis one ofpro, team. A rule with no conditions applies to everyone. - Rollout (optional): only this percentage of the matching users get the rule. The others fall through to the next rule.
- Serve: a value, a variant, or a split across variants.
| Operator | Matches when the attribute… |
|---|---|
eq, neq | equals or doesn't equal the value. 5 and "5" are equal; true and "true" are not |
in, not_in | is or isn't one of a list (at most 100 values) |
contains, not_contains | contains or doesn't contain a substring |
matches | matches a regular expression over the whole value |
gt, gte, lt, lte | compares as a number |
exists, not_exists | is set or isn't set |
An attribute the caller didn't send matches nothing except not_exists, so a rule never targets a user by accident because information was missing.
Your server passes attributes with each read:
const tier = flags.get(
'search.ranking',
{ key: user.id, attributes: { plan: user.plan, country: user.country } },
'classic'
)
A flag can have up to 50 rules per environment, 20 conditions per rule and 20 variants. From the beta CLI, rules are JSON, which makes them easy to review and copy between environments:
bunx @temps-sdk/cli@beta flags rules list checkout.v2 -e production --json > rules.json
bunx @temps-sdk/cli@beta flags rules set checkout.v2 @rules.json -e preview
bunx @temps-sdk/cli@beta flags evaluate checkout.v2 -e production --subject user_1001 --attr plan=pro
[
{
"description": "Internal users",
"conditions": [{ "attribute": "email", "operator": "matches", "value": ".*@example\\.com" }],
"serve": { "kind": "value", "value": true }
},
{
"description": "10% of pro accounts",
"conditions": [{ "attribute": "plan", "operator": "eq", "value": "pro" }],
"rollout_percentage": 10,
"serve": { "kind": "value", "value": true }
}
]
Saving rules replaces the whole list. The console and CLI send the revision they read, and Temps refuses the save with a 409 if someone else changed the rules in between, instead of silently overwriting their change. Use Test this flag in the flag's panel, or flags evaluate, to see what a given user would get, and why, before you ship a rule.
Percentage rollouts are sticky
A user's bucket is a hash of the flag key, the flag's salt and the subject key: the key you pass (usually a user id) or, in a browser, the Temps visitor cookie. The same user always lands on the same side, on every server and in every SDK. Raising a rollout from 10% to 20% keeps the first 10% in.
A partial rollout or split needs a subject. Without one the rule is skipped, so an anonymous request is never assigned at random.
Reshuffle (in the flag's panel, or flags reshuffle) draws new buckets for every rollout and split of the flag. Never reshuffle a flag that a running experiment depends on.
Variants
Variants are named values declared on the flag, for example control and test. A rule can serve one, or split matching users across several by weight:
{
"conditions": [],
"serve": {
"kind": "split",
"split": [
{ "variant": "control", "weight": 50 },
{ "variant": "test", "weight": 50 }
]
}
}
Weights are whole numbers that add up to 100. The served variant is reported with the value, so analytics and experiments can tell the arms apart. A variant can't be removed while a rule still serves it.
bunx @temps-sdk/cli@beta flags update checkout.v2 --variants '[{"key":"control","value":false},{"key":"test","value":true}]'
Read flags in the browser
A flag marked Expose to browsers can be read by your front end. Temps evaluates it on the server for the visitor making the request and sends only the result. The browser never sees rules, salts or server-only flags. This needs the beta React or core package.
import { TempsAnalyticsProvider, useFlag, useFlagVariant } from '@temps-sdk/react-analytics'
function Checkout() {
// `false` until flags arrive, then the served value.
const useV2 = useFlag('checkout.v2', false)
const arm = useFlagVariant('pricing.page') // 'control' | 'test' | null
return useV2 ? <CheckoutV2 /> : <CheckoutV1 />
}
Without React, analytics.flags.get('checkout.v2', false) from @temps-sdk/analytics-core does the same.
- Nothing is fetched until you read a flag, so pages that never use flags pay nothing.
- Requests go to
POST /api/_temps/flagson your own domain, the same path as Temps analytics, so there is no CORS and no key. - To target a signed-in user instead of the anonymous visitor, give the provider the user's key and attributes, or call
flags.reload({ key: user.id })after sign-in. When the user changes, values fetched for the previous one are dropped at once. - To avoid a flash of the wrong variant, render flags on the server and pass them to the provider as a bootstrap.
<TempsAnalyticsProvider flags={{ key: user.id, attributes: { plan: user.plan } }}>
{children}
</TempsAnalyticsProvider>
<TempsAnalyticsProvider flags={{ bootstrap: { 'checkout.v2': true } }}>
{children}
</TempsAnalyticsProvider>
Temps fills in some attributes from the request, so rules can use them without your app sending anything: environment, host, country (when GeoIP is configured), browser, os, device_type, visitor_id and session_id. Attributes your app sends override them.
The endpoint is limited to 30,000 requests a minute per site and 600 a minute per client address. Over the limit it answers 429, and the SDK keeps serving the last values it had.
Exposure events
For an experiment you need to know who actually saw each variant, not only who was assigned one. Set Record exposures on the flag to the share of visitors to record, or use bunx @temps-sdk/cli@beta flags update <key> --exposure-rate 10.
The first time a recorded visitor's page reads the flag, the browser sends one flag_exposure analytics event with flag_key, variant and reason. It shows up in your events and can be used in funnels like any other event. It is off by default and sampled per visitor, so a busy flag doesn't flood your analytics.
OpenFeature
Temps speaks the OpenFeature Remote Evaluation Protocol (OFREP), so any OpenFeature SDK with an OFREP provider (Go, Java, Python, .NET, JavaScript and more) can read Temps flags:
| Endpoint | Used by | Authentication |
|---|---|---|
/api/_temps/ofrep/v1/evaluate/flags[/{key}] on your site's domain | Browser and mobile SDKs | None. Same scope and limits as the browser endpoint, browser-visible flags only |
/api/ofrep/v1/evaluate/flags[/{key}] on the Temps API | Server SDKs | The deployment's TEMPS_API_TOKEN. Every flag of its environment |
The OpenFeature targetingKey is the subject key, and every other context field is an attribute.
Archive a flag
Every flag shows Last evaluated by an app in its panel. The SDK reports it when your code reads the flag, not when the console opens or a deploy fetches the flag set. Never means no running app has read this flag since the feature shipped, which is the signal that it is safe to archive.
Archiving stops a flag being served, and apps fall back to the default compiled into their own code. Check that fallback is what you want in production before you archive.
bunx @temps-sdk/cli flags archive checkout.v2
bunx @temps-sdk/cli flags restore checkout.v2
Archived flags keep their key reserved. Use --include-archived on flags list to see them.
Security
- Flags are not secrets. Values are stored unencrypted. Use secret environment variables for credentials.
- Flags are server-only by default. Browsers only receive the evaluated value of browser-visible flags, never rules, other users' targeting or server-only flags.
- Deployment tokens are read-only. The
TEMPS_API_TOKENin your container can read the flag snapshot but can never change a flag, so a compromised app can't flip production. - Changes are audited. Every change records who made it, when, and the old and new value. A flag change is a production change with no deployment behind it, so the audit log is the only record.
Limits
Not available yet:
- Reusable segments and cohorts in rules. Each rule lists its own conditions.
- Exposure events from server-side SDKs. Only browsers record them.
- Per-environment usage. "Last evaluated" is per flag, across all environments.
- Instant propagation between separate console and proxy processes. A change is live at once on a single-binary install, and in a split setup within about five seconds plus one cache refresh.