Docs / SDK Reference

SDK Reference

Methods, types, and examples for the Chargly JavaScript/TypeScript SDK.

Overview

  • new Chargly() — create a client
  • meterEvent() — record usage and deduct credits

Installation

terminal
$ npm install @chargly/sdk

Constructor

Create a Chargly client with your API key.

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

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

apiKey

string · required

Your Chargly secret API key.

meterEvent

Record a usage event and deduct credits from the customer's wallet.

Behavior

  • Records the usage event
  • Deducts credits from the wallet
  • Updates the balance in real time
app.js
await chargly.meterEvent({
  customerId: "user_123",
  event: "image.generate",
  credits: 40
})

customerId

string · required

Your customer's unique identifier.

event

string · required

Event name, e.g. image.generate, chat.reply.

credits

number · required

Number of credits to deduct.

Next