Commet
  • Pricing
Log InTry out
Introduction

Quickstart

Integrate with Next.jsIntegrate with RemixIntegrate with NuxtIntegrate with SvelteKitIntegrate with AstroIntegrate with ExpressIntegrate with HonoIntegrate with Bun

Learn

Resources

SDK ReferenceError HandlingTestingCLI

Plugins

Better Auth
DocumentationKnowledge BaseBuild with AIAPI ReferenceWebhooks

Integrate with Next.js

Add billing and payments to your Next.js application.

Use this pre-built prompt to integrate Commet faster with AI assistants.

Install

pnpm add @commet/node @commet/next
npm install @commet/node @commet/next
yarn add @commet/node @commet/next
bun add @commet/node @commet/next

Configure

.env.local
COMMET_API_KEY=ck_sandbox_xxx
lib/commet.ts
import { Commet } from '@commet/node'

export const commet = new Commet({
  apiKey: process.env.COMMET_API_KEY!,
  environment: 'sandbox',
})

Create Customer and Subscribe

customers.create is idempotent — if a customer with the same id already exists, it returns the existing record.

app/actions/billing.ts
'use server'

import { redirect } from 'next/navigation'
import { commet } from '@/lib/commet'

export async function subscribe(customerId: string) {
  await commet.customers.create({
    email: 'user@example.com',
    id: customerId,
  })

  const subscription = await commet.subscriptions.create({
    customerId,
    planCode: 'pro',
  })

  redirect(subscription.data.checkoutUrl!)
}

The customer is redirected to checkout to complete payment.

Check Access

app/actions/billing.ts
export async function getSubscription(customerId: string) {
  const { data } = await commet.subscriptions.get(customerId)

  return data
}
app/actions/features.ts
export async function canUseFeature(customerId: string, feature: string) {
  const { data } = await commet.features.check({ code: feature, customerId })

  return data.allowed
}

Track Usage

app/actions/usage.ts
export async function trackApiCall(customerId: string) {
  await commet.usage.track({
    customerId,
    feature: 'api_calls',
    value: 1,
  })
}

Usage is aggregated and billed at end of period.

Customer Portal

app/api/commet/portal/route.ts
import { CustomerPortal } from '@commet/next'

export const GET = CustomerPortal({
  apiKey: process.env.COMMET_API_KEY!,
  getCustomerId: async (req) => {
    return 'user_123'
  },
})
<a href="/api/commet/portal">Manage Billing</a>

Related

  • Subscriptions
  • Track Usage
  • Customer Portal
  • SDK Reference

How is this guide?

Introduction

Commet is a billing and payments platform for SaaS and AI products.

Integrate with Remix

Add billing and payments to your Remix application.

On this page

Install
Configure
Create Customer and Subscribe
Check Access
Track Usage
Customer Portal
Related