Remote config

Boolean and multivariate flags are helpful for dynamic values that differ from user to user, but sometimes you need a simple way to pass configuration related to your application without having to make code changes or redeploy your app.

Remote config flags enable you to configure a simple flag that always returns the same payload wherever it is called. Remote config flags can also be stored as encrypted values and decrypted on the server side when requested. Encryption/decryption is handled automatically.

There are 3 steps to start using remote config flags:

Step 1: Get a secret API key

Local evaluation requires a secret API key that gives the SDK access to the feature flag definitions for your project. This key needs to be kept secret, and should not be used in the frontend or exposed to users.

We recommend using a project secret API key with the feature_flag:read scope. Project secret API keys are hashed at rest, scoped to only what they need, and you can create up to 50 per project, so you can issue and roll keys per deployment without affecting the others.

Note: Existing feature flags secure API keys and personal API keys continue to work for local evaluation, but both are deprecated. We recommend switching to a project secret API key.

How to create a project secret API key

  1. Go to the project secret API keys section of your project settings

  2. Create a new key with the Local feature flag evaluation preset (the feature_flag:read scope) and give it a label.

  3. Copy the key. It's only displayed once, so store it somewhere safe, like a secrets manager.

  4. Use it to initialize the PostHog client.

Step 2: Initialize PostHog with your secret API key in options

const client = new PostHog(
'<ph_project_token>',
{
host: 'https://us.i.posthog.com',
personalApiKey: 'your secret API key from step 1',
featureFlagsPollingInterval: 30000 // Optional. Measured in milliseconds. Defaults to 30000 (30 seconds)
}
)

Note: By default, initializing PostHog with your secret API key enables local evaluation, but this can be disabled in posthog-node by setting enableLocalEvaluation: false in your config.

Step 3: Use remote config flags

const config = posthog.getRemoteConfigPayload('landing-page-config')
// config is a JsonType

You can think of remote config flags as multivariate flags with a single variant which is served for all flag requests. By default, enabled remote config flags roll out to 100% of all users.

Note: Remote config flags are meant to always serve payloads and be called with the flag payload function in each SDK. If getFeatureFlag is called instead, the SDK simply returns true

Community questions

Was this page useful?

Questions about this page? or post a community question.