JamiDev

SDK

jami-sdk, the official TypeScript client for Node 18+, edge runtimes and browsers.

jami-sdk wraps the REST API in a typed client with no dependencies. It runs anywhere fetch exists: Node 18+, Bun, Deno, Cloudflare Workers, Vercel Edge and modern browsers. It ships three surfaces:

ImportFor
JamiYour organization: checkouts, products, subscriptions, orders, balance, withdrawals, webhook verification. Server-side, uses your API token.
JamiWalletA signed-in user's own Jami wallet over OAuth. Server-side, confidential client. See Wallet.
JamiStorefront (jami-sdk/storefront)Selling from your own site in the browser, with no token. See Storefront.
npm install jami-sdk

Custom-amount checkouts and checkout metadata need version 0.5.0 or later. Subscriptions and recurring products need 0.6.0 or later.

Create a client

import { Jami } from 'jami-sdk';

const jami = new Jami({ token: process.env.JAMI_TOKEN! });

jami.environment; // 'test' for jamidev_test_…, 'live' for jamidev_live_…

The constructor checks the token's shape and throws if it's malformed. Keep the token on the server; it can create checkouts and withdraw money.

Prop

Type

Create a checkout

Charge an amount your server decides, with no product:

const checkout = await jami.createCheckout({
  amount: 123700,                                   // 1,237.00 ETB, integer santim
  description: 'Order #1042',                       // what the buyer sees, 1–120 chars
  metadata: { orderId: '1042' },                    // optional, returned on webhooks
  customer: { email: 'buyer@example.com', phone: '251911223344' },
  gateway: 'telebirr',                              // 'telebirr' | 'mpesa' | 'cbe'
});

Or sell a product:

const checkout = await jami.createCheckout({
  productId: 'p_x7Kf3mQz9aBc',                      // product token or id
  customer: { email: 'buyer@example.com', phone: '251911223344' },
  gateway: 'telebirr',
});

Those two push the prompt to the buyer's phone (mode: 'direct'). Leave out gateway (and, if you like, customer) to get a payment link instead:

const { checkoutUrl } = await jami.createCheckout({ amount: 123700, description: 'Order #1042' });
// 'https://jami.bio/jamidev/pay/cs_…', send it to the buyer

The buyer picks the method on the link and can retry a failed attempt until it expires (30 minutes). See Collect the payment.

Every checkout returns one of these shapes:

if ('orderId' in checkout) {
  // Free product: the order already exists.
} else if (checkout.mode === 'redirect') {
  // Send the buyer to checkout.checkoutUrl (a payment link, or the sandbox simulator).
} else {
  // 'direct': a prompt was pushed to the buyer's phone. Wait for it.
}

isFreeCheckout(checkout) is the same check as 'orderId' in checkout, as a type guard.

The parameter type is ProductCheckoutParams | CustomAmountCheckoutParams, so TypeScript tells you when you mix the two. Without a productId, the SDK checks that amount is an integer of at least 100 and that description isn't empty, and throws JamiValidationError before sending.

Prop

Type

Products

Create and manage products from code. Each call returns a JamiProduct with its public url and p_… token:

const product = await jami.products.create({
  title: 'Ge’ez Calligraphy Course',   // 1–120 characters
  pricingModel: 'fixed',               // 'fixed' | 'pwyw' | 'free', locked after creation
  price: { amount: 250000 },           // pwyw: { minimumAmount, defaultAmount? }
  description: 'Six live classes.',    // optional
});
// → { id, token: 'p_…', url: 'https://jami.bio/jamidev/p_…', status: 'published', price: { amount: 250000, … }, … }

await jami.products.get(product.token);                               // by token or id
await jami.products.list({ status: 'published', limit: 20 });         // { items, total, page, limit }
await jami.products.update(product.token, { price: { amount: 300000 } });
await jami.products.archive(product.token);                           // stops new sales

For a subscription plan, add productType: 'recurring', billingInterval ('week', 'month' or 'year') and intervalCount (default 1) to a fixed-price product, e.g. price: { amount: 25000 } for 250.00 ETB a month. Needs 0.6.0.

create publishes the product unless you pass status: 'draft' (the REST default is draft). The SDK checks title is 1 to 120 characters before sending. Benefits and checkout fields are still attached in the dashboard. REST details: API: Products.

Subscriptions

Charge a payer's Jami wallet every period after they approve a recurring product on Jami. Your token proposes and manages subscriptions; it can't start one or charge a wallet. Needs 0.6.0 or later.

// 1. A subscribe link for one of your recurring products. Valid 24 hours, single use.
const { id, url, expiresAt, livemode } = await jami.subscriptions.createCheckout({
  productId: 'p_x7Kf3mQz9aBc',
  customer: { email: 'abebe@example.com', externalId: 'user_42' }, // optional
  successUrl: 'https://gebeta.club/welcome?sub={SUBSCRIPTION_ID}',  // optional
  cancelUrl: 'https://gebeta.club/pricing',                          // optional
  metadata: { plan: 'monthly' },                                     // optional
});
// Send the payer to url ('https://jami.bio/jamidev/subscribe/sc_…').

// 2. Read them.
await jami.subscriptions.list({ customerExternalId: 'user_42', status: 'active' }); // { items, total, page, limit }
const { subscription, charges } = await jami.subscriptions.get('sub_Qm3xT8vLp2NaR7kd');
subscription.amount;           // 25000, 250.00 ETB every period
subscription.currentPeriodEnd; // paid through this date

// 3. Cancel or resume.
await jami.subscriptions.cancel('sub_Qm3xT8vLp2NaR7kd');                         // ends at period end
await jami.subscriptions.cancel('sub_Qm3xT8vLp2NaR7kd', { atPeriodEnd: false }); // ends now
await jami.subscriptions.resume('sub_Qm3xT8vLp2NaR7kd'); // only undoes a cancel you scheduled

// 4. Sandbox only: run the next renewal now.
await jami.subscriptions.simulateRenewal('sub_Qm3xT8vLp2NaR7kd', { outcome: 'failure' });
// { result: 'retry_scheduled', subscription: { status: 'past_due', … } }

Resuming a cancel the payer made, or a subscription that ended, raises a JamiError with status: 409. The full flow, statuses and dunning are on Subscriptions; REST details on API: Subscriptions.

Wait for the payment

const status = await jami.waitForCheckout(checkout.sessionId);

if (status.status === 'completed') {
  console.log('paid', status.orderId);
} else {
  console.log('not paid:', status.failure?.code, status.failure?.message);
}

waitForCheckout polls getCheckoutStatus until the session completes, expires or gets an order. Each poll makes the server check the payment provider directly, so it resolves even when webhooks are late. It always ends: after timeoutMs (5 minutes by default) it rejects with code: 'poll_timeout'.

await jami.waitForCheckout(sessionId, {
  intervalMs: 2000,       // default
  timeoutMs: 120_000,     // default 300_000
  signal: AbortSignal.timeout(130_000),
});

await jami.getCheckoutStatus(sessionId); // a single check

When status is expired, failure.code says why. See the failure codes.

A payment link stays open between the buyer's attempts and lasts 30 minutes, longer than the default timeout. Either wait for the order.completed webhook, or pass timeoutMs: 30 * 60_000. While it's open, getCheckoutStatus (and the status endpoint) also returns attempt: { inFlight, lastFailure }, so you can see that a prompt is out or why the last try failed. Needs jami-sdk 0.5.0 or later.

List orders

const { items, total, page, limit } = await jami.listOrders({ status: 'paid', page: 1, limit: 20 });

items[0].amount;           // santim
items[0].productId;        // { _id, title }
items[0].customerId;       // { _id, email, name }
items[0].description;      // set for custom amounts; productId.title is "Custom payment"

Newest first. limit is 1 to 100 (default 20). status is pending, paid or failed.

Withdrawals

Jami.computeWithdrawalQuote(10000);
// { amount: 10000, feeAmount: 700, taxAmount: 0, netAmount: 9300, feeRate: 0.07, taxRate: 0 }

const { balanceMinor, eligible } = await jami.getBalance();

const withdrawal = await jami.createWithdrawal({
  amount: 10000,                      // gross santim; the fee is cut from this
  gateway: 'telebirr',
  account: '251911223344',
  idempotencyKey: 'payout-2026-10-16-001',
});

await jami.getWithdrawal(withdrawal._id);
await jami.listWithdrawals({ status: 'completed', limit: 20 });

The full guide, with statuses and errors, is on Withdrawals. The SDK also exports the limits as constants: MIN_WITHDRAWAL_MINOR (10000), AUTO_PAYOUT_CAP_MINOR (1000000), DAILY_PAYOUT_CAP_MINOR (10000000) and DEFAULT_WITHDRAWAL_FEE_RATE (0.07).

Verify webhooks

import { JamiSignatureError } from 'jami-sdk';

const event = await jami.webhooks.verify({
  payload: rawBody,                                  // the raw request body string
  signature: req.headers['x-jamidev-signature'],
  secret: process.env.JAMI_WEBHOOK_SECRET!,          // the endpoint's secret, not your token
});

switch (event.type) {
  case 'order.completed':          /* fulfil; event.data.sessionId matches your checkout */ break;
  case 'benefit.granted':          /* event.data.payload?.licenseKey */ break;
  case 'checkout.session.expired': /* event.data.failure?.code */ break;
  case 'withdrawal.paid':
  case 'withdrawal.failed':        /* event.data is the withdrawal */ break;
  case 'subscription.created':
  case 'subscription.renewed':     /* paid through event.data.currentPeriodEnd; event.data.charge */ break;
  case 'subscription.payment_failed': /* event.data.charge.failure?.code, event.data.nextRetryAt */ break;
  case 'subscription.updated':     /* event.data.change, event.data.changedBy */ break;
  case 'subscription.canceled':    /* event.data.cancellationReason; revoke access */ break;
}

event is a discriminated union, so event.data is typed for each event.type. It throws JamiSignatureError on a bad signature, a malformed header, a timestamp older than toleranceSec (default 300), or an unknown event type. verifyWebhookSignature is the same function without a client, for code that has no API token. Framework examples are on Webhooks.

Sign in with Jami + wallet

JamiWallet is separate from Jami. It runs the OAuth flow for an end user and then reads or sends from their wallet. It's a confidential client: the secret and the user's tokens stay on your server.

import { JamiWallet } from 'jami-sdk';

const wallet = new JamiWallet({
  apiKey: process.env.JAMI_API_KEY!,             // your jamidev_… key, sent as X-JamiDev-Key
  clientId: process.env.JAMI_CLIENT_ID!,
  clientSecret: process.env.JAMI_CLIENT_SECRET!,
  redirectUri: 'https://yourapp.com/callback',
});

// 1. Send the user to Jami. Save state and codeVerifier in their session.
const auth = await wallet.createAuthorization();
redirect(auth.url);

// 2. On the callback, check state matches, then exchange the code.
let tokens = await wallet.exchangeCode({ code, codeVerifier });
const me = wallet.parseIdentity(tokens.idToken); // { sub, name, handle, … } for display only

// 3. Refresh near expiry. Refresh tokens rotate, so save the new set.
if (tokens.expiresAt && Date.now() >= tokens.expiresAt) {
  tokens = await wallet.refresh(tokens.refreshToken!);
}

// 4. Use the wallet.
const balance = await wallet.getBalance(tokens.accessToken); // { currency, availableMinor, totalMinor }
const { transfer, deduped } = await wallet.send(tokens.accessToken, {
  recipientHandle: 'abebe',            // or recipientUserId; exactly one
  amountMinor: 5000,                   // 50.00 ETB
  idempotencyKey: crypto.randomUUID(), // at least 8 characters
});

The client always asks for a token bound to resource=https://jami.bio, which the wallet endpoints require. Default scopes are openid profile wallet:read wallet:send offline_access. Wallet failures raise JamiWalletError with the server's code (kyc_required, insufficient_funds, daily_cap_exceeded, recipient_not_found, self_transfer, …). A bad token or missing API key raises JamiAuthError. See Wallet for the full contract.

Errors

Every failure is a subclass of JamiError, with status, code and requestId when available.

ErrorWhen
JamiValidationError400. The message names the field. Also thrown before any request for invalid input, like a withdrawal under 100 ETB.
JamiAuthError401. .hint is set when the token belongs to the organization's other environment.
JamiRateLimitError429. Too many checkouts, or the daily payout cap; the message says which.
JamiWalletErrorA JamiWallet call failed. code is the server's reason.
JamiSignatureErrorWebhook verification failed.
JamiErrorAnything else: 402, 404, 409, 502, poll_timeout, network errors.
import { JamiAuthError, JamiError } from 'jami-sdk';

try {
  await jami.listOrders();
} catch (err) {
  if (err instanceof JamiAuthError && err.hint) {
    // The organization switched environment. Create a new token.
  } else if (err instanceof JamiError) {
    console.error(err.status, err.code, err.requestId, err.message);
  }
}

Methods

MethodEndpoint
jami.createCheckout(params)POST /checkout, for a product or a custom amount
jami.products.create(params)POST /products
jami.products.get(id) · .list(params?)GET /products/{id} · GET /products
jami.products.update(id, params)PATCH /products/{id}
jami.products.archive(id)DELETE /products/{id}
jami.getCheckoutStatus(sessionId)GET /checkout/{sessionId}
jami.waitForCheckout(sessionId, options?)Polls GET /checkout/{sessionId}
jami.listOrders({ page?, limit?, status? })GET /orders
jami.subscriptions.createCheckout({ productId, customer?, successUrl?, cancelUrl?, metadata? })POST /subscriptions/checkout
jami.subscriptions.list({ status?, productId?, customerExternalId?, page?, limit? })GET /subscriptions
jami.subscriptions.get(id)GET /subscriptions/{id}
jami.subscriptions.cancel(id, { atPeriodEnd? })POST /subscriptions/{id}/cancel
jami.subscriptions.resume(id)POST /subscriptions/{id}/resume
jami.subscriptions.simulateRenewal(id, { outcome })POST /subscriptions/{id}/simulate-renewal, sandbox only
jami.getBalance()GET /balance
jami.createWithdrawal({ amount, gateway, account, idempotencyKey? })POST /withdrawals
jami.getWithdrawal(id)GET /withdrawals/{id}
jami.listWithdrawals({ page?, limit?, status? })GET /withdrawals
jami.webhooks.verify(params)Local, no request
Jami.computeWithdrawalQuote(amount, rates?)Local, no request

Notes

  • The SDK never retries on its own. waitForCheckout is its only loop, and it always ends.
  • Amounts are integer santim everywhere. Passing a float to a withdrawal throws before any request is made.
  • Prefer working from an AI agent? The MCP server exposes these methods as tools.

On this page