> ## Documentation Index
> Fetch the complete documentation index at: https://www.edgee.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 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:

* `undefined` or no arguments - reads from environment variables
* `string` - 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.

```typescript theme={"dark"}
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:

```typescript theme={"dark"}
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:

```typescript theme={"dark"}
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:

1. **Constructor argument** (if provided)
2. **Environment variable** (if constructor argument is missing)
3. **Default value** (for `baseUrl` only, defaults to `https://edgee.io`)

## Complete Examples

<Accordion title="Additional configuration recipes">
  ### Example 1: Production Setup

  ```typescript theme={"dark"}
  // .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

  ```typescript theme={"dark"}
  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

  ```typescript theme={"dark"}
  // lib/edgee.ts
  import Edgee from 'edgee';

  export function createEdgeeClient() {
    return new Edgee({
      apiKey: process.env.EDGEE_API_KEY!
    });
  }
  ```
</Accordion>

## Troubleshooting

### "EDGEE\_API\_KEY is not set" Error

**Problem**: The SDK can't find your API key.

**Solutions**:

1. Set the environment variable:
   ```bash theme={"dark"}
   export EDGEE_API_KEY="your-api-key"
   ```

2. Pass it directly:
   ```typescript theme={"dark"}
   const edgee = new Edgee('your-api-key');
   ```

3. Use configuration object:
   ```typescript theme={"dark"}
   const edgee = new Edgee({ apiKey: 'your-api-key' });
   ```

### Custom Base URL Not Working

**Problem**: Your custom base URL isn't being used.

**Check**:

1. Verify the base URL in your configuration
2. Check whether an explicit constructor URL takes precedence over `EDGEE_BASE_URL`
3. Ensure you're using the correct configuration method

```typescript theme={"dark"}
// 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](/docs/llm-router/sdk/typescript) - Complete SDK documentation
* [API Reference](/docs/llm-router/api-reference) - REST API documentation
* [Quickstart Guide](/docs/quickstart) - Get started with Edgee
