Configuration
The SDK is configured via the SonarSDKConfig object passed to the SonarSDK constructor.
Options
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
apiKey | string | Yes | — | Your Sonar API key. Must start with sk_. |
instanceName | string | No | — | The Sonar instance name used to construct the base URL. |
baseUrl | string | No | — | Full override for the API base URL. Takes precedence over instanceName. |
timeout | number | No | 30000 | Request timeout in milliseconds. |
headers | Record<string, string> | No | {} | Additional custom headers to include with every request. |
TypeScript Definition
interface SonarSDKConfig { apiKey: string; instanceName?: string; baseUrl?: string; timeout?: number; headers?: Record<string, string>;}URL Resolution
- If
baseUrlis provided, it is used directly as the API base URL. - If only
instanceNameis provided, the base URL is constructed as:https://session.sonar.de/{instanceName} - If neither is provided, a default base URL is used.
Examples
// Using instance name (recommended for production)const sdk = new SonarSDK({ apiKey: 'sk_live_abc123', instanceName: 'acme-corp',});// Base URL → https://session.sonar.de/acme-corp
// Using custom base URL (for development/testing)const sdk = new SonarSDK({ apiKey: 'sk_test_xyz789', baseUrl: 'https://staging.sonar.de/acme-corp',});
// With custom timeout and headersconst sdk = new SonarSDK({ apiKey: 'sk_live_abc123', instanceName: 'acme-corp', timeout: 60000, headers: { 'X-Custom-Header': 'my-value', },});