Skip to content

Configuration

The SDK is configured via the SonarSDKConfig object passed to the SonarSDK constructor.

Options

ParameterTypeRequiredDefaultDescription
apiKeystringYesYour Sonar API key. Must start with sk_.
instanceNamestringNoThe Sonar instance name used to construct the base URL.
baseUrlstringNoFull override for the API base URL. Takes precedence over instanceName.
timeoutnumberNo30000Request timeout in milliseconds.
headersRecord<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 baseUrl is provided, it is used directly as the API base URL.
  • If only instanceName is 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 headers
const sdk = new SonarSDK({
apiKey: 'sk_live_abc123',
instanceName: 'acme-corp',
timeout: 60000,
headers: {
'X-Custom-Header': 'my-value',
},
});