Skip to main content

SDK Configuration

Client Options

import { Mutagent } from '@mutagent/sdk';

const client = new Mutagent({
  // Authentication (required - use one)
  bearerAuth: string | (() => Promise<string>),
  // apiKey: string,       // TODO: Coming soon - simpler auth option

  // Optional configuration
  serverURL?: string,      // Custom API URL
  serverIdx?: number,      // Server index (0 = default)
  timeoutMs?: number,      // Request timeout in ms
  retryConfig?: RetryConfig,

  // Advanced
  httpClient?: HTTPClient, // Custom HTTP client
  debugLogger?: Logger,    // Debug logging
});
Coming Soon: The SDK will also support apiKey as a simpler authentication option. For now, use bearerAuth.

Basic Setup

import { Mutagent } from '@mutagent/sdk';

// Simple setup
const client = new Mutagent({
  bearerAuth: process.env.MUTAGENT_API_KEY,
});

// With custom server
const client = new Mutagent({
  bearerAuth: process.env.MUTAGENT_API_KEY,
  serverURL: 'https://api.mutagent.dev',
});

Environment Variables

# .env
MUTAGENT_API_KEY=sk_live_xxxxxxxxxxxx
import { Mutagent } from '@mutagent/sdk';

const client = new Mutagent({
  bearerAuth: process.env.MUTAGENT_API_KEY!,
});

Dynamic Authentication

For token refresh or dynamic keys:
const client = new Mutagent({
  bearerAuth: async () => {
    // Fetch or refresh token
    const token = await getToken();
    return token;
  },
});

Timeout Configuration

const client = new Mutagent({
  bearerAuth: process.env.MUTAGENT_API_KEY,
  timeoutMs: 60000, // 60 seconds
});

Retry Configuration

const client = new Mutagent({
  bearerAuth: process.env.MUTAGENT_API_KEY,
  retryConfig: {
    strategy: 'backoff',
    backoff: {
      initialInterval: 500,
      maxInterval: 60000,
      exponent: 1.5,
      maxElapsedTime: 300000,
    },
    retryConnectionErrors: true,
  },
});

Per-Request Options

Override configuration for individual requests:
const prompts = await client.prompt.getApiPrompt(
  { limit: 50 },
  {
    timeoutMs: 120000,  // 2 minute timeout for this request
    retries: {
      strategy: 'none', // No retries for this request
    },
  }
);

Debug Logging

const client = new Mutagent({
  bearerAuth: process.env.MUTAGENT_API_KEY,
  debugLogger: console, // Log all requests
});