# Install

### Prerequisites

Before installing, ensure you have:

* **FE\&R Credentials**: Environment ID and API Key from [https://app2.abtasty.com](https://app2.abtasty.com/)
* **Platform-specific requirements** (see each section below)

***

### Run Decision API from Source (Linux and macOS)

Running from source allows you to build and customize the Decision API for your specific needs.

#### Prerequisites

* **Go** 1.23.3 or higher
* **Git**
* **Make** (optional, for convenience)

#### Step 2: Clone the Repository

```bash
# Clone the Decision API repository
git clone https://github.com/flagship-io/decision-api.git

# Navigate to the project directory
cd decision-api
```

#### Step 3: Install Dependencies

```bash
# Download Go module dependencies
go mod download

# Verify dependencies
go mod verify
```

#### Step 4: Build the Binary

**Using Make (Recommended)**

```bash
# Build the server binary
make build

# The binary will be created at: bin/server
```

**Manual Build**

```bash
# Create bin directory
mkdir -p bin

# Build the binary
CGO_ENABLED=0 go build -o bin/server cmd/server/*.go
```

#### Step 5: Configure Environment Variables

Create a configuration file or set environment variables:

```bash
# Option 1: Export environment variables
export ENV_ID=your_env_id
export API_KEY=your_api_key
```

Or create a `.env` file:

```bash
cat > .env << EOF
ENV_ID=your_env_id
API_KEY=your_api_key
EOF
```

#### Step 6: Run the Server

```bash
# Run the binary
./bin/server
```

### Run Decision API from Source (Windows)

#### Prerequisites

* **Go** 1.23.3 or higher
* **Git for Windows**
* **PowerShell** or **Command Prompt**

#### Step 3: Clone the Repository

```powershell
# Clone the repository
git clone https://github.com/flagship-io/decision-api.git

# Navigate to the directory
cd decision-api
```

#### Step 4: Install Dependencies

```powershell
# Download Go module dependencies
go mod download

# Verify dependencies
go mod verify
```

#### Step 5: Build the Binary

```powershell
# Create bin directory
New-Item -ItemType Directory -Force -Path bin

# Build the binary
go build -o bin\server.exe .\cmd\server\
```

#### Step 6: Configure Environment Variables

**Option 1: Set in PowerShell Session**

```powershell
$env:ENV_ID="your_env_id"
$env:API_KEY="your_api_key"
```

**Option 2: Create a `.env` file**

Create a file named `.env` in the project root:

```
ENV_ID=your_env_id
API_KEY=your_api_key
```

#### Step 7: Run the Server

```powershell
# Run the binary
.\bin\server.exe
```

### Run the Decision API using the provided Docker image

Docker provides the easiest way to run the Decision API with minimal setup.

#### Prerequisites

* **Docker** 20.10 or higher
* **Docker Compose** (optional, for multi-container setup)

#### Method 1: Run with Docker (Simple)

```bash
# Pull the latest image
docker pull flagshipio/decision-api:latest

# Run the container
docker run -d \
  --name flagship-decision-api \
  -p 8080:8080 \
  -e ENV_ID=your_env_id \
  -e API_KEY=your_api_key \
  -e LOG_LEVEL=info \
  flagshipio/decision-api:latest
```

#### Method 2: Run with Docker Compose (Recommended)

Create a `docker-compose.yml` file:

```yaml
version: "3.9"
services:
  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    command: redis-server --appendonly yes
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 5
    restart: unless-stopped

  decision-api:
    image: flagshipio/decision-api:latest
    ports:
      - "8080:8080"
    environment:
      # FE&R credentials - UPDATE THESE
      ENV_ID: your_env_id
      API_KEY: your_api_key
      # Server configuration
      LOG_LEVEL: info
      LOG_FORMAT: json
      ADDRESS: ":8080"
      # Cache configuration (Redis for advanced features)
      CACHE_TYPE: redis
      CACHE_OPTIONS_REDISHOST: redis:6379
      # CORS configuration
      CORS_ENABLED: "true"
      CORS_ALLOWED_ORIGINS: "*"
      # Polling interval for config updates
      POLLING_INTERVAL: 60s
    depends_on:
      redis:
        condition: service_healthy
    restart: unless-stopped

volumes:
  redis_data:
    driver: local

networks:
  default:
    name: flagship-demo
```

### Configuration parameters

You can use the following parameters to customize the Decision API.\
Each parameter is named as in the config.yaml file, and the matching environment variable is parenthesis.

<table data-full-width="true"><thead><tr><th>Parameter</th><th align="center">Type</th><th align="right">Required</th><th align="center">Description</th></tr></thead><tbody><tr><td>env_id (ENV_ID)</td><td align="center">string</td><td align="right">yes</td><td align="center">The Flagship environment ID. You can get it from the Flagship platform. Default to empty string</td></tr><tr><td>api_key (API_KEY)</td><td align="center">string</td><td align="right">yes</td><td align="center">The Flagship API Key for this environment ID. You can get it from the Flagship platform. Default to empty string</td></tr><tr><td>address (ADDRESS)</td><td align="center">string</td><td align="right">no</td><td align="center">The server address to listen for requests. Default to ":8080"</td></tr><tr><td>cors.enabled (CORS_ENABLED)</td><td align="center">bool</td><td align="right">no</td><td align="center">If true, the server will return the cors response headers necessary for cross origins API calls. Default to true</td></tr><tr><td>cors.allowed_origins (CORS_ALLOWED_ORIGINS)</td><td align="center">string</td><td align="right">no</td><td align="center">If the cors are enabled, this option will set the Access-Control-Allow-Origin response headers. Default to "*"</td></tr><tr><td>log.level (LOG_LEVEL)</td><td align="center">string</td><td align="right">no</td><td align="center">Set the minimum log level that will be send to output. Can be trace, debug, info, warn, error, fatal, panic. Default to "warning"</td></tr><tr><td>log.format (LOG_FORMAT)</td><td align="center">string</td><td align="right">no</td><td align="center">Set the output log format. Can be either "text" or "json". Default to "text"</td></tr><tr><td>polling_interval (POLLING_INTERVAL)</td><td align="center">string</td><td align="right">no</td><td align="center">The polling frequency (as parsable by the <a href="https://pkg.go.dev/time#ParseDuration">ParseDuration</a> method) to synchronize with your Flagship configuration. Default to 60s</td></tr><tr><td>cache.type (CACHE_TYPE)</td><td align="center">string</td><td align="right">no</td><td align="center">If you want to enable caching for the visitor assignment. Can be "memory", "redis", "dynamo" or "local". Default to empty string.</td></tr><tr><td>cache.options.dbPath (CACHE_OPTIONS_DBPATH)</td><td align="center">string</td><td align="right">no</td><td align="center">If you chose local cache type, this is the path of the file where the cache will be stored. Default to empty string</td></tr><tr><td>cache.options.redisHost (CACHE_OPTIONS_REDISHOST)</td><td align="center">string</td><td align="right">no</td><td align="center">If you chose redis cache type, this is the host for your redis server</td></tr><tr><td>cache.options.redisUsername (CACHE_OPTIONS_REDISUSERNAME)</td><td align="center">string</td><td align="right">no</td><td align="center">If you chose redis cache type, this is the username for your redis server</td></tr><tr><td>cache.options.redisUsername (CACHE_OPTIONS_REDISPASSWORD)</td><td align="center">string</td><td align="right">no</td><td align="center">If you chose redis cache type, this is the password for your redis server</td></tr><tr><td>cache.options.redisDb (CACHE_OPTIONS_REDISDB)</td><td align="center">int</td><td align="right">no</td><td align="center">If you chose redis cache type, this is the db number for your redis server. Default to 0 (default DB)</td></tr><tr><td>cache.options.redisTls (CACHE_OPTIONS_REDISTLS)</td><td align="center">bool</td><td align="right">no</td><td align="center">If true, redis client will be set to connect using TLS to the redis server. Default to false</td></tr><tr><td>cache.options.dynamoTableName (CACHE_OPTIONS_DYNAMOTABLENAME)</td><td align="center">string</td><td align="right">no</td><td align="center">The table name to store cache assignments when using DynamoDB. Default to "visitor-assignments"</td></tr><tr><td>cache.options.dynamoPKSeparator (CACHE_OPTIONS_DYNAMOPKSEPARATOR)</td><td align="center">string</td><td align="right">no</td><td align="center">The primary key separator between env ID &#x26; visitor ID to store cache assignments when using DynamoDB. Default to "."</td></tr><tr><td>cache.options.dynamoPKField (CACHE_OPTIONS_DYNAMOPKFIELD)</td><td align="center">string</td><td align="right">no</td><td align="center">The primary key field name to store cache assignments when using DynamoDB. Default to "id"</td></tr><tr><td>cache.options.dynamoGetTimeout (CACHE_OPTIONS_DYNAMOGETTIMEOUT)</td><td align="center">string</td><td align="right">no</td><td align="center">The timeout for getting previously stored visitor cache assignment when using DynamoDB. Default to 1s</td></tr></tbody></table>

Start the services:

```bash
# Start in detached mode
docker compose up -d
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.abtasty.com/server-side/decision-api/run-on-premise/install.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
