HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityLog In

Quickstart for Agent

This topic describes how to quickly get started with Optimizely Agent using Docker or as a Node microservice.

This brief quickstart describes how to run Agent, using two examples:

  • To get started using Docker, see Running locally via Docker.

  • To get started using example Node microservices, see the following video link.

Running locally via Node



Implementing feature flags across microservices with Optimizely Agent

4-minute video on implementing Optimizely Agent with example microservices

Running locally via Docker

Follow these steps to deploy Optimizely Agent locally via Docker and access some of the common API endpoints.

If you do not have Docker installed, you download it here.

First pull the Docker image with:

docker pull optimizely/agent

Then start the service in the foreground with the following command:

docker run -p 8080:8080 --env OPTIMIZELY_LOG_PRETTY=true optimizely/agent



Note that we are enabling "pretty" logs which provide colorized and human readable formatting.

The default log output format is structured JSON.

Evaluating REST APIs

The rest of the getting started guide will demonstrate the APIs capabilities. For brevity, we've chosen to illustrate the API usage with Python. Note that the APIs are also defined via OpenAPI (Swagger) and can be found on localhost here.

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 get your SDK key, navigate to the project settings of your Optimizely account.

Future examples will assume this session is being maintained.

Get current environment configuration

The /config 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} 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, in which flag variations are measured against one another, or a flag delivery, which 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 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?