Skip to main content

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​

OptionTypeDefaultPurpose
environment"sandbox" | "production"Inferred from the keySelect the canonical Usagey API host.
baseUrlstringEnvironment hostOverride the complete versioned API root.
timeoutMsnumber10000Abort requests that exceed the timeout.

Environment selection​

The SDK automatically maps keys to versioned hosts:

Key prefixEnvironmentAPI root
usg_test_Sandboxhttps://sandbox.usagey.com/v1
usg_live_Productionhttps://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.