@credits-dev/sdk
v0.0.1
Published
TypeScript/JavaScript SDK for the Credits.dev API — accounts, plans, transactions, reservations, and usage
Downloads
59
Maintainers
Readme
@credits-dev/sdk
TypeScript/JavaScript SDK for the Credits API. Use it in Node.js (v18+) or in the browser. Authenticate with your API key (dashboard → API Keys); all requests use the X-API-Key header.
Install
npm install @credits-dev/sdk
# or
pnpm add @credits-dev/sdk
# or
yarn add @credits-dev/sdkUsage
import { CreditsClient } from "@credits-dev/sdk";
const client = new CreditsClient({
apiKey: process.env.CREDITS_API_KEY!,
baseUrl: "https://api.credits.dev", // optional, default production API
});
// Accounts — use accountId or externalId
const { accounts } = await client.listAccounts();
const account = await client.getAccount({ accountId: "..." });
const balance = await client.getBalance({ accountId: "..." });
// Add/deduct credits
await client.addCredits({ accountId: "...", amount: 100 });
await client.deductCredits({ externalId: "user_123", amount: 50, description: "Usage" });
// Reservations (reserve → use → confirm or cancel)
const { reservation } = await client.createReservation({ accountId: "...", amount: 100 });
await client.confirmReservation(reservation.id, 95);See the API docs for full endpoint coverage. All methods mirror the REST API and support both accountId and externalId where the API allows. Paginated endpoints (e.g. listTransactions) return { items, pagination }.
Exports
- Default:
import { CreditsClient } from "@credits-dev/sdk" - Types only:
import type { Account, Transaction } from "@credits-dev/sdk" - Subpaths:
@credits-dev/sdk/types,@credits-dev/sdk/client
License
MIT
