@trackingkoala/sdk
v1.0.0
Published
SDK for TrackingKoala API
Readme
@trackingkoala/sdk
Official Node.js SDK for TrackingKoala.
Installation
npm install @trackingkoala/sdk
# or
pnpm add @trackingkoala/sdkUsage
import {
TrackingKoala,
TrackingKoalaApiError,
TrackingKoalaNetworkError,
TrackingKoalaValidationError
} from "@trackingkoala/sdk";
const koala = new TrackingKoala("YOUR_API_KEY", {
timeoutMs: 10000
});
try {
await koala.track({
cost: 150,
// amount: 150, // alias for cost
charge: 299,
currency: "USD",
environment: "production",
provider: "openai",
action: "signup",
userId: "usr_123",
traces: ["trace_abc"],
tags: ["signup", "conversion"],
metadata: {
plan: "pro",
source: "google_ads"
}
});
} catch (error) {
if (error instanceof TrackingKoalaValidationError) {
console.error("Validation failed", error.issues);
} else if (error instanceof TrackingKoalaApiError) {
console.error("API failed", error.status, error.responseBody);
} else if (error instanceof TrackingKoalaNetworkError) {
console.error("Network failed", error.message);
} else {
throw error;
}
}Template Execution
const result = await koala.rateTemplate({
templateId: "tmpl_openai_pricing",
mode: "preview", // or "track"
inputs: {
model: "gpt-4.1",
input_tokens: 1200,
output_tokens: 450
},
event: {
source: "template",
provider: "openai",
action: "summarize"
}
});
console.log(result.cost, result.charge, result.breakdown);Client Validation
cost(oramount) must be a finite number greater than0.charge, when provided, must be a finite number greater than0.- If both
costandamountare provided, they must be equal. userIdis the canonical identity field.customerIdis still accepted as a backward-compatible alias.- If both
userIdandcustomerIdare provided, they must be equal. tagsandtracesdefault to[]when omitted.
IntelliSense and Method Docs
The SDK ships with TypeScript declarations and JSDoc comments on constructor options, methods, and errors so editors show inline usage details.
Publishing to Private Registry
To publish this package to a private registry (e.g. GitHub Packages or a self-hosted Verdaccio instance):
Configure
.npmrc: Create a.npmrcfile in the project root or user home directory with the registry URL and authentication token.//npm.pkg.github.com/:_authToken=YOUR_TOKEN @trackingkoala:registry=https://npm.pkg.github.comUpdate
package.json: Ensure thepublishConfigpoints to your registry."publishConfig": { "registry": "https://npm.pkg.github.com" }Publish: Run
npm publishorpnpm publish.
Development
pnpm build: Build the packagepnpm dev: Watch mode
