> ## Documentation Index
> Fetch the complete documentation index at: https://docs.integrateledger.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript SDK source

> Explore generated client methods while public package distribution is being prepared.

The TypeScript SDK source is generated from Ledger's OpenAPI specification. **There is no public package release or installation path yet.** The TypeScript snippets in the API reference document the generated client surface; they require a local copy of the repository. Use the [cURL quickstart](https://docs.integrateledger.com/quickstart.md) for a runnable public integration today.

## Build from a repository checkout

If you have access to the Ledger source repository, run `bun run sdk:build` at its root. Another local project can then install the built package with `bun add /absolute/path/to/ledger/packages/sdk`. The build provides CommonJS and ES modules. This is a source checkout workflow, not a public install command.

```typescript theme={null}
import { Ledger } from "@ledger/sdk";

const ledger = new Ledger({ apiKey: process.env.LEDGER_API_KEY ?? "" });
```

Use a `ledger_test_` key for Sandbox or a `ledger_live_` key for Live. The key selects the environment; the SDK uses the same methods and API URL for both. See [Sandbox and live environments](https://docs.integrateledger.com/environments.md).

For a local API server, pass `serverURL: "http://127.0.0.1:3001"` to the constructor. Do not use the SDK in a browser: its key grants organization access.

## Catalog operations

`createFeature`, `createPlan`, and `createAddOn` accept one item at a time. Use `listFeatures`, `listPlans`, or `listAddOns` to read active items. For a single item, use `getPlan({ id })` and its feature and add-on equivalents.

```typescript theme={null}
const plan = await ledger.createPlan({ id: "starter", name: "Starter", monthlyCredits: 100, monthlyPriceCents: 1900 });
const plans = await ledger.listPlans();
await ledger.updatePlan({ id: "starter", body: { name: "Starter", monthlyCredits: 150, monthlyPriceCents: 1900 } });
await ledger.archivePlan({ id: "starter" });
```

Updates require the full editable body. Plan updates create a new version when changed. See [Catalog](https://docs.integrateledger.com/catalog.md).

## Customer and usage operations

```typescript theme={null}
await ledger.createOrGetCustomer({ customerId: "user_123" });
const customer = await ledger.getCustomer({ customerId: "user_123" });
const checkout = await ledger.attach({ customerId: "user_123", planId: "starter" });
const check = await ledger.checkCredits({ customerId: "user_123", featureId: "api_call" });
if (check.allowed) {
  // Run the action, then record successful use.
  await ledger.trackUsage({ customerId: "user_123", featureId: "api_call", requestId: "operation_123" });
}
const packCheckout = await ledger.attach({ customerId: "user_123", addOnId: "extra_credits" });
```

For a paid plan or add-on, `attach` returns a `checkoutUrl` plus `subscriptionId` or `addOnPurchaseId`. A free plan returns `subscriptionId` and `status: "active"` without Checkout; its monthly credits are available immediately. `trackUsage` uses `requestId` in TypeScript and sends `request_id` on the wire. See [Customers](https://docs.integrateledger.com/customers.md) and [Credits and usage](https://docs.integrateledger.com/credits.md).

The **API reference** tab shows the exact body, response, errors, and cURL, [Python SDK source](https://docs.integrateledger.com/python-sdk.md), and TypeScript SDK source examples for each endpoint.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.