Configuration
Pass the API key as the first constructor argument and optional client settings as the second.
import { Usagey } from "@usagey/sdk";
const usagey = new Usagey(process.env.USAGEY_API_KEY!, {
environment: "sandbox",
timeoutMs: 5_000,
});
Options
| Option | Type | Default | Purpose |
|---|---|---|---|
environment | "sandbox" | "production" | Inferred from the key | Select the canonical Usagey API host. |
baseUrl | string | Environment host | Override the complete versioned API root. |
timeoutMs | number | 10000 | Abort requests that exceed the timeout. |
Environment selection
The SDK automatically maps keys to versioned hosts:
| Key prefix | Environment | API root |
|---|---|---|
usg_test_ | Sandbox | https://sandbox.usagey.com/v1 |
usg_live_ | Production | https://api.usagey.com/v1 |
Usagey rejects keys sent to the wrong environment host. Keep separate client instances if a service intentionally works with both environments.
Local API development
Override the complete versioned API root only when testing against a local Usagey server:
const usagey = new Usagey(process.env.USAGEY_API_KEY!, {
baseUrl: "http://localhost:3000/v1",
});
Do not use baseUrl to route production traffic through an untrusted proxy because every request includes your secret API key.