← Back to docs

Quickstart

Wire up per-user credit metering in about 30 minutes. No infrastructure required.

1

Install the SDK

bash
npm install agensor
2

Create a meter

ts
import { createMeter } from 'agensor'

const meter = createMeter({
  apiKey: process.env.AGENSOR_API_KEY!, // sk_... from app.agensor.dev
})
3

Wrap your AI client

Pass your Anthropic or OpenAI client through the meter. The wrapped client is a drop-in replacement — all existing call syntax is preserved.

ts
import Anthropic from '@anthropic-ai/sdk'

const raw = new Anthropic()
const client = meter.wrapAnthropic(raw, {
  getUserId: (req) => req.user.id, // return a stable user identifier
})

Or for OpenAI:

ts
import OpenAI from 'openai'

const raw = new OpenAI()
const client = meter.wrapOpenAI(raw, {
  getUserId: (req) => req.user.id,
})
4

Call as normal

ts
// Exact same API as the unwrapped client
const msg = await client.messages.create({
  model:      'claude-sonnet-4-6',
  max_tokens: 1024,
  messages:   [{ role: 'user', content: req.body.message }],
})

// Behind the scenes, Agensor:
// 1. Checks the user has enough credits
// 2. Estimates the cost pessimistically
// 3. Calls Anthropic
// 4. Reconciles the actual cost
// 5. Syncs the debit to Agensor in the background
5

Set your API key

Get your secret key from app.agensor.dev, then add it to your environment:

bash
AGENSOR_API_KEY=sk_xxxxxxxxxxxx

You're metered 🎉

Credits are deducted per API call. Your users start with 0 credits — add some via the dashboard or embed the top-up widget.