TypeScript SDK Configuration
Learn how to configure and instantiate the Edgee TypeScript SDK.
The Edgee TypeScript SDK provides flexible ways to instantiate a client. All methods support automatic fallback to environment variables if configuration is not fully provided.
Overview
The Edgee class constructor accepts multiple input types:
undefinedor no arguments - reads from environment variablesstring- API key string (backward compatible)EdgeeConfig- Configuration interface (type-safe)
Method 1: Environment Variables (Recommended for Production)
The simplest and most secure approach is to use environment variables.
The SDK automatically reads EDGEE_API_KEY (required) and optionally EDGEE_BASE_URL from your environment variables.
import Edgee from 'edgee';
// EDGEE_API_KEY and (optionally) EDGEE_BASE_URL are loaded from the environment
const edgee = new Edgee();
Method 2: String API Key (Quick Start)
For quick testing or simple scripts, pass the API key directly as a string:
import Edgee from 'edgee';
// API key only (uses default base URL: https://edgee.io)
const edgee = new Edgee('your-api-key');
Note: The base URL can also come from EDGEE_BASE_URL; otherwise it defaults to https://edgee.io. To set a base URL explicitly, use the configuration object below.
Method 3: Configuration Object (Type-Safe)
For better type safety, IDE support, and code clarity, use the EdgeeConfig interface:
import Edgee, { type EdgeeConfig } from 'edgee';
// Full configuration
const edgee = new Edgee({
apiKey: 'your-api-key',
baseUrl: 'https://edgee.io' // optional, defaults to https://edgee.io
});
// Or Using the EdgeeConfig type
const config: EdgeeConfig = {
apiKey: 'your-api-key',
baseUrl: 'https://edgee.io'
};
const edgee = new Edgee(config);
Configuration Priority
The SDK uses the following priority order when resolving configuration:
- Constructor argument (if provided)
- Environment variable (if constructor argument is missing)
- Default value (for
baseUrlonly, defaults tohttps://edgee.io)
Complete Examples
Additional configuration recipes
Example 1: Production Setup
// .env file
// EDGEE_API_KEY=prod-api-key
// EDGEE_BASE_URL=https://edgee.io
import 'dotenv/config';
import Edgee from 'edgee';
const edgee = new Edgee(); // Reads from environment
Example 2: Multi-Environment Setup
import Edgee from 'edgee';
const ENV = process.env.NODE_ENV || 'development';
let edgee: Edgee;
if (ENV === 'production') {
edgee = new Edgee(); // Use environment variables
} else if (ENV === 'staging') {
edgee = new Edgee({
apiKey: process.env.EDGEE_API_KEY!
});
} else {
edgee = new Edgee({
apiKey: 'dev-api-key',
baseUrl: 'https://eu.edgee.io'
});
}
Example 3: Next.js Setup
// lib/edgee.ts
import Edgee from 'edgee';
export function createEdgeeClient() {
return new Edgee({
apiKey: process.env.EDGEE_API_KEY!
});
}
Troubleshooting
"EDGEE_API_KEY is not set" Error
Problem: The SDK can't find your API key.
Solutions:
-
Set the environment variable:
export EDGEE_API_KEY="your-api-key" -
Pass it directly:
const edgee = new Edgee('your-api-key'); -
Use configuration object:
const edgee = new Edgee({ apiKey: 'your-api-key' });
Custom Base URL Not Working
Problem: Your custom base URL isn't being used.
Check:
- Verify the base URL in your configuration
- Check whether an explicit constructor URL takes precedence over
EDGEE_BASE_URL - Ensure you're using the correct configuration method
// This will use the baseUrl from config object
const edgee = new Edgee({
apiKey: 'key',
baseUrl: 'https://custom.example.com'
});
// This will use EDGEE_BASE_URL env var if set, otherwise default
const edgee = new Edgee('key');
Related Documentation
- TypeScript SDK Overview - Complete SDK documentation
- API Reference - REST API documentation
- Quickstart Guide - Get started with Edgee