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 Nuxt

Add billing and payments to your Nuxt application.

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

Install

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

Configure

.env
COMMET_API_KEY=ck_sandbox_xxx
nuxt.config.ts
export default defineNuxtConfig({
  runtimeConfig: {
    commetApiKey: process.env.COMMET_API_KEY,
  },
})

Nuxt auto-imports from server/utils/, so the client is available in all server routes.

server/utils/commet.ts
import { Commet } from '@commet/node'

const config = useRuntimeConfig()

export const commet = new Commet({
  apiKey: config.commetApiKey,
  environment: 'sandbox',
})

Subscribe

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

server/api/billing/subscribe.post.ts
export default defineEventHandler(async (event) => {
  const { customerId, email } = await readBody(event)

  await commet.customers.create({ email, id: customerId })

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

  return { checkoutUrl: subscription.data.checkoutUrl }
})

Check Access

server/api/billing/access/[customerId].get.ts
export default defineEventHandler(async (event) => {
  const customerId = getRouterParam(event, 'customerId')!

  const { data: subscription } = await commet.subscriptions.get(customerId)

  const { data: feature } = await commet.features.check({
    code: 'api_calls',
    customerId,
  })

  return {
    status: subscription.status,
    allowed: feature.allowed,
  }
})

Track Usage

server/api/billing/usage.post.ts
export default defineEventHandler(async (event) => {
  const { customerId } = await readBody(event)

  await commet.usage.track({
    customerId,
    feature: 'api_calls',
    value: 1,
  })

  return { tracked: true }
})

Usage is aggregated and billed at end of period.

Customer Portal

server/api/billing/portal.get.ts
export default defineEventHandler(async (event) => {
  const customerId = 'user_123'

  const { data } = await commet.portal.getUrl({ customerId })

  return sendRedirect(event, data.portalUrl)
})

Related

  • Subscriptions
  • Track Usage
  • Customer Portal
  • SDK Reference

How is this guide?

Integrate with Remix

Add billing and payments to your Remix application.

Integrate with SvelteKit

Add billing and payments to your SvelteKit application.

On this page

Install
Configure
Subscribe
Check Access
Track Usage
Customer Portal
Related