DOCS · JAVASCRIPT / TYPESCRIPT

JavaScript/TypeScript Examples

UPDATED 22 NOVEMBER 2025

Note on the SDK. There is no published @aiva/sdk package. The wrapper below shows the shape we intend, but the supported integration path today is a direct REST call against https://api.getaiva.ai with an X-API-Key header. See the Developers page for working examples in four languages.

import { AivaClient } from '@aiva/sdk';

const client = new AivaClient({
  apiKey: process.env.AIVA_API_KEY!,
  merchantId: process.env.AIVA_MERCHANT_ID!
});

// Get customers by segment
const champions = await client.customers.list({ segment: 'Champions' });
console.log(`You have ${champions.total} champion customers`);

// Calculate MRR
const subscriptions = await client.subscriptions.list({ status: 'active' });
const mrr = subscriptions.items.reduce((sum, sub) => {
  return sum + (sub.interval === 'year' ? sub.price / 12 : sub.price);
}, 0);
console.log(`MRR: $${mrr.toFixed(2)}`);

// Create prize draw
const draw = await client.prizeDraws.create({
  name: 'Summer Giveaway 2025',
  description: 'Win $500!',
  totalPrizePool: 500,
  startDate: '2025-06-01T00:00:00Z',
  endDate: '2025-06-30T23:59:59Z',
  drawDate: '2025-07-01T12:00:00Z',
  useBlockchain: true
});
console.log(`Prize draw created: ${draw.id}`);

Install:

npm install @aiva/sdk
`"
Building something with the AIVA API or MCP server? We read every developer message.
Talk to us