API

The API is one way to keep cached features up-to-date on your servers.

With the API, your servers pull feature definitions from GrowthBook in a cronjob (or similar).

With Webhooks, GrowthBook calls out to your servers as soon as features change in GrowthBook.

Environments and API Keys

When you first start setting up features in GrowthBook, we create a "production" environment for you with an API key.

You can add new environments by going to Settings -> Environments.

Feature Definitions Endpoint

The primary API endpoint is for fetching feature definitions.

For self-hosted deployments, the endpoint is at http://localhost:3100/api/features/{myKey} (note: port 3000 is the default front-end app, port 3100 is the default for the API)

For GrowthBook Cloud, the endpoint is on our global CDN: https://cdn.growthbook.io/api/features/{myKey}

Here is an example API response:

{
  "status": 200,
  "features": {
    "feature-key": {
      "defaultValue": true
    },
    "another-feature": {
      "defaultValue": "blue",
      "rules": [
        {
          "condition": {
            "browser": "firefox"
          },
          "force": "green"
        }
      ]
    }
  }
}

The status field mirrors the HTTP status. The features field has feature definitions indexed by the feature key.

Each feature definition has a default value and optional rules that override the value based on targeting conditions. Rules can also be experiments or rollouts where values are randomly assigned to users.

Project-scoping

If you've set up multiple projects within GrowthBook, you can optionally add a querystring to this endpoint to only include features in a specific project. By default, features from all projects are returned.

To do this, add the querystring ?project={projectId}. You can find the id for your project under Settings > Projects (will start with prj_).

For example:

/api/features/key_dev_abc123?project=prj_456def

Official SDKs

We offer official SDKs that work with these data structures in a few popular languages with more coming soon.