init()
init(config: InitConfig): void
Initialize the SDK. Must be called before any other method.
Parameters
| Name | Type | Description | |
|---|---|---|---|
| apiKey | string | Required | Your CostCanary API key. Must start with cck_live_ or cck_test_. |
| endpoint | string | Optional | Override ingestion endpoint. Defaults to production URL. Also settable via COSTCANARY_ENDPOINT env var. |
| autoCapture | boolean | Optional, default: false | Automatically intercept all LLM API calls via fetch and http.request patching. |
| contextProvider | () => CostCanaryContext | Optional | Fallback context provider for each LLM event when no AsyncLocalStorage context is set. |
| inferFeatureFromStack | boolean | Optional, default: true | Enable stack-based feature inference from call site file paths. |
| debug | boolean | Optional | Enable debug logging. Also enabled via COSTCANARY_DEBUG=true env var. |
| batchSize | number | Optional, default: 25 | Events per batch flush. Range: 1–100. |
| flushInterval | number | Optional, default: 5000 | Ms between batch flushes. Range: 500–30000. |
Throws
→ Error if apiKey is missing
→ Error if batchSize is outside 1–100 range
→ Error if flushInterval is outside 500–30000ms range
Warnings
⚠ Warns if apiKey doesn't start with cck_live_ or cck_test_
Example