Docs / Quickstart

Quickstart

Install the SDK, meter your first event, and test a credit deduction in minutes.

In this guide

  • Install the SDK
  • Initialize Chargly
  • Meter your first AI event
  • Verify wallet deduction behavior

Prerequisites

  • Node.js / TypeScript app
  • Chargly API key
  • Optional: Stripe account for credit top-ups

1. Install the SDK

terminal
$ npm install @chargly/sdk

2. Initialize Chargly

app.js
import { Chargly } from "@chargly/sdk"

const chargly = new Chargly({
  apiKey: process.env.CHARGLY_SECRET_KEY,
})

3. Meter your first event

app.js
await chargly.meterEvent({
  customerId: "user_123",
  event: "image.generate",
  credits: 40
})

4. What happens next

When you call meterEvent:

  • Chargly records the event
  • Credits are deducted from the wallet
  • The balance updates in real time

5. Next step: connect top-ups

To let users buy credits, connect Stripe. Chargly handles checkout sessions and syncs purchases to wallet balances automatically.

Next