Configuration

Configure the LegionEdge SDK and platform settings

The LegionEdge SDK supports multiple configuration methods. Options are resolved in the following order of precedence: constructor arguments, configuration file, environment variables, defaults.

Environment Variables

Set these environment variables to configure the SDK without code changes:

VariableDescriptionDefault
LEGIONEDGE_API_KEYAPI key for authentication--
LEGIONEDGE_ORG_IDDefault organization ID--
LEGIONEDGE_ENVTarget environment (development, staging, production)production
LEGIONEDGE_BASE_URLOverride the API base URLhttps://api.legionedge.com/v2
LEGIONEDGE_TIMEOUTRequest timeout in milliseconds30000
LEGIONEDGE_LOG_LEVELLogging level (debug, info, warn, error)info

Configuration File

Create a legionedge.config.ts file in your project root for persistent configuration:

import { defineConfig } from "@legionedge/sdk";

export default defineConfig({
  apiKey: process.env.LEGIONEDGE_API_KEY!,
  organizationId: process.env.LEGIONEDGE_ORG_ID,
  environment: "production",
  baseUrl: "https://api.legionedge.com/v2",
  timeout: 30_000,
  retries: {
    maxRetries: 3,
    backoffMultiplier: 2,
    retryableStatusCodes: [429, 502, 503, 504],
  },
  logging: {
    level: "info",
    format: "json",
  },
});

The SDK auto-discovers this file when you instantiate the client without arguments:

import { LegionEdge } from "@legionedge/sdk";

// Automatically loads legionedge.config.ts
const client = new LegionEdge();

Constructor Options

Pass options directly to the constructor to override all other configuration:

import { LegionEdge } from "@legionedge/sdk";

const client = new LegionEdge({
  apiKey: "le_live_abc123",
  environment: "staging",
  timeout: 10_000,
  retries: { maxRetries: 5 },
  hooks: {
    beforeRequest: (request) => {
      console.log(`[${request.method}] ${request.url}`);
      return request;
    },
    afterResponse: (response) => {
      console.log(`Response: ${response.status}`);
      return response;
    },
  },
});

Environment-Specific Settings

Use the environment option to target different platform environments. Each environment has isolated data and configuration:

// Development -- uses sandbox data, relaxed rate limits
const devClient = new LegionEdge({
  apiKey: process.env.LEGIONEDGE_DEV_KEY!,
  environment: "development",
});

// Production -- uses live data, standard rate limits
const prodClient = new LegionEdge({
  apiKey: process.env.LEGIONEDGE_PROD_KEY!,
  environment: "production",
});

Proxy and Network Configuration

For environments behind a corporate proxy:

const client = new LegionEdge({
  apiKey: process.env.LEGIONEDGE_API_KEY!,
  httpAgent: new HttpsProxyAgent("http://proxy.corp.internal:8080"),
  baseUrl: "https://api.legionedge.com/v2",
});

Validating Configuration

Use the built-in validation helper to verify your configuration at startup:

import { LegionEdge, validateConfig } from "@legionedge/sdk";

const config = {
  apiKey: process.env.LEGIONEDGE_API_KEY!,
  environment: "production" as const,
};

const issues = validateConfig(config);
if (issues.length > 0) {
  console.error("Configuration issues:", issues);
  process.exit(1);
}

const client = new LegionEdge(config);

Next Steps