integrateledger
Released under the MIT license.
Speakeasy-generated TypeScript SDK for Ledger's client API.
The SDK calls the hosted Ledger API by default. Pass serverURL to use a local instance or a future custom domain.
Ledger API keys grant organization-wide access. Use this SDK only in trusted server code; never ship its key to a browser or client bundle.
Fail open. When Ledger can't answer (a network error, a timeout after 2 seconds, a 5xx or a 429), checkCredits returns allowed: true and trackUsage queues the usage for replay with the same requestId, both marked failedOpen: true with a reason, instead of throwing. Business answers such as 409 insufficient_credits throw as usual. Call await client.flushQueuedTracks() before a serverless handler returns, pass failOpen: { onFailOpen } to log events, or failOpen: false to throw. See Fail open.

Install the server-side SDK from npm. See the Ledger setup guide for catalog, customer, usage, and Checkout examples.
Summary
Ledger's server-side SDK creates catalog items, manages customers and plans, records usage, and starts Stripe Checkout. The API reference shows each operation with cURL, Python, and TypeScript examples.
Table of Contents
- integrateledger
- SDK Installation
- Requirements
- SDK Example Usage
- Authentication
- Available Resources and Operations
- Standalone functions
- Retries
- Error Handling
- Server Selection
- Custom HTTP Client
- Debugging
- Development
SDK Installation
npm install integrateledger or bun add integrateledger. The package provides both CommonJS and ES Modules. Keep your Ledger API key on the server.
Requirements
For supported JavaScript runtimes, please consult RUNTIMES.md.
SDK Example Usage
Example
import ledger from "integrateledger";
const client = new ledger({ apiKey: process.env.LEDGER_API_KEY ?? "" });
async function main() {
await client.createFeature({ id: "api_call", name: "API call", creditCost: 1 });
await client.createPlan({ id: "starter", name: "Starter", monthlyCredits: 100, monthlyPriceCents: 1900 });
await client.createAddOn({ id: "extra_credits", name: "Extra credits", type: "credit_pack", creditAmount: 50, priceCents: 500 });
}
main().catch((error) => { console.error(error); process.exitCode = 1; });
Authentication
Set LEDGER_API_KEY in a trusted server environment. The key authorizes access to your organization, so do not include it in client code.
import ledger from "integrateledger";
const client = new ledger({ apiKey: process.env.LEDGER_API_KEY ?? "" });
const feature = await client.createFeature({ id: "api_call", name: "API call", creditCost: 1 });
console.log(feature.item.id);
Available Resources and Operations
Ledger SDK
Standalone functions
All the methods listed above are available as standalone functions. They can reduce bundle size in trusted server or serverless deployments. They use the same secret organization API key as the SDK class.
To read more about standalone functions, check FUNCTIONS.md.