Quickstart for Agent

Provides steps on how to quickly get started with Optimizely Agent using Node and explores Agent's REST APIs.

Running locally via Node

Watch this 4-minute video on implementing Optimizely Agent with example microservices or follow the instructions here to install Agent on your preferred operating system.

Evaluating Agent REST APIs



The Agent REST APIs are defined via OpenAPI (Swagger) and can be found on localhost or in our developer documentation. The following examples use Python code for brevity, but can be expanded for any programming language.

Start an HTTP session

Each request made into Optimizely Agent is in the context of an Optimizely SDK key. SDK keys map API requests to a specific Optimizely Project and Environment. We can set up a global request header by using the requests.Session object.

import requests
s = requests.Session()
s.headers.update({'X-Optimizely-SDK-Key': '<<YOUR-SDK-KEY>>'})

To authenticate, pass your SDK key as a header named X-Optimizely-SDK-Key in your API calls to Optimizely Agent. You can find your SDK key in app.optimizely.com under Settings > Environments > SDK Key. Remember you have a different SDK key for each environment.


️ You must start an HTTP session

Future examples will assume this session is being maintained.

Get current environment configuration

The [/config](https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/reference/getconfig) endpoint returns a manifest of the current working environment.

resp = s.get('http://localhost:8080/v1/config')
env = resp.json()

for key in env['featuresMap']:

Run a feature flag rule

The [/decide?keys={keys}](https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/reference/decide) endpoint decides whether to enable a feature flag or flags for a given user. You can decide multiple flags with this syntax: /v1/decide?keys=flagA&keys=flagB. We will provide a userId via the request body. The API evaluates the userId to determine which flag rule and flag variation the user buckets into.

Rule types include:

  • [A/B tests](doc:intro-a-b-tests): flag variations are measured against one another
  • Flag delivery: progressively make the flag available to the selected audience

This endpoint returns an array of OptimizelyDecision objects, which contains information about the flag and rule the user was bucketed into.

params = { "keys": "my-feature-flag" }
payload = {
    "userId": "test-user",
    "userAttributes": {
        "attr1": "sample-attribute-1",
        "attr2": "sample-attribute-2"
resp = s.post(url = 'http://localhost:8080/v1/decide', params=params, json=payload)


The decide API is a POST to signal to the caller that there are side-effects. Namely, this endpoint results in a "decision" event sent to Optimizely analytics for the purpose of analyzing A/B test results. By default a "decision" is not sent if the feature flag is simply part of a delivery.

Did this page help you?