Skip to main content
The @crevio/sdk package provides a type-safe TypeScript client for the Crevio API. It works in Node.js, browsers, Cloudflare Workers, and Deno.

Installation

npm install @crevio/sdk

Quick start

import { Crevio } from "@crevio/sdk";

const crevio = new Crevio({
  apiKeyAuth: "YOUR_API_TOKEN",
});

Usage examples

List products

const products = await crevio.products.list();

for (const product of products) {
  console.log(product.name, product.id);
}

Get a product

Retrieve by ID or slug:
// By ID
const product = await crevio.products.get({ id: "prod_abc123" });

// By slug
const product = await crevio.products.get({ id: "my-course" });

Get a product with reviews expanded

const product = await crevio.products.get({
  id: "my-course",
  expand: "reviews",
});

for (const review of product.reviews ?? []) {
  console.log(review.rating, review.customerName, review.content);
}

Create a checkout

const checkout = await crevio.checkouts.create({
  email: "customer@example.com",
  lineItems: [
    {
      priceVariant: "pv_xyz789",
      quantity: 1,
    },
  ],
});

console.log(checkout.clientSecret); // Use with Stripe.js

List orders with expanded data

const orders = await crevio.orders.list({
  expand: "line_items,customer",
  limit: 50,
});

Create a customer

const customer = await crevio.customers.create({
  email: "customer@example.com",
  firstName: "Jane",
  lastName: "Doe",
});

Create a discount

const discount = await crevio.discounts.create({
  code: "SUMMER20",
  discountType: "percent_off",
  percentOff: 20,
  duration: "once",
  maxRedemptions: 100,
});

Manage webhook endpoints

// Create a webhook endpoint
const webhook = await crevio.webhookEndpoints.create({
  url: "https://example.com/webhooks/crevio",
  enabledEvents: ["order.paid", "checkout.created"],
});

// Save the secret for signature verification
console.log(webhook.secret);

// List available event types
const events = await crevio.webhookEndpoints.listEvents();

Pay an invoice

Create a checkout to pay an existing invoice:
const checkout = await crevio.checkouts.create({
  invoice: "inv_abc123",
});

// Redirect customer to checkout.url
console.log(checkout.url);

List refunds

// List all refunds
const refunds = await crevio.refunds.list();

// List refunds for a specific order
const orderRefunds = await crevio.refunds.list({
  order: "ord_abc123",
});

Manage files

// Upload a file via external URL
const file = await crevio.files.create({
  sourceType: "external",
  url: "https://example.com/image.png",
});

// Create a direct upload
const upload = await crevio.files.create({
  sourceType: "upload",
  filename: "document.pdf",
});
// Use upload.uploadUrl and upload.uploadHeaders to PUT the file,
// then confirm: await crevio.files.uploaded({ id: upload.id });

Send an email

const email = await crevio.emails.create({
  subject: "Your purchase is ready",
  html: "<h1>Thank you!</h1><p>Your download is ready.</p>",
  to: ["customer@example.com"],
});

List webhook events

// List recent webhook events
const events = await crevio.webhookEvents.list();

// Filter by event type
const orderEvents = await crevio.webhookEvents.list({
  type: "order.paid",
});

Error handling

The SDK throws typed errors that you can catch:
try {
  const product = await crevio.products.get({
    id: "prod_nonexistent",
  });
} catch (error) {
  if (error.statusCode === 404) {
    console.log("Product not found");
  }
}

Runtime support

RuntimeSupported
Node.js 18+Yes
BrowsersYes
Cloudflare WorkersYes
DenoYes
BunYes
The SDK is generated with Speakeasy and includes Zod validation, automatic retries, and full TypeScript type definitions.