### Install Comet Go SDK Source: https://commet.co/llms-full.txt Use `go get` to install the Comet Go SDK. This command fetches and installs the specified package. ```bash go get github.com/commet-labs/commet-go ``` -------------------------------- ### FastAPI Application Setup Source: https://commet.co/docs/integrate-with-fastapi This snippet shows a more complete setup for a FastAPI application, including importing necessary modules and initializing the router. It's a common starting point for building web services. ```python from fastapi import FastAPI from fastapi.routing import APIRouter router = APIRouter() webhooks = APIRouter() ``` -------------------------------- ### Install Subscription Patterns Skill Source: https://commet.co/llms-full.txt Use this command to install the Subscription Patterns skill. Ensure you have npx installed. ```bash npx skills add commet-labs/subscription-patterns ``` -------------------------------- ### Install Pricing Models Skill Source: https://commet.co/llms-full.txt Use this command to install the Pricing Models skill. Ensure you have npx installed. ```bash npx skills add commet-labs/pricing-models ``` -------------------------------- ### Install Standalone Billing Skills Source: https://commet.co/llms-full.txt Installs universal billing knowledge skills that can be used with any stack. Examples use @commet/node. ```bash npx skills add commet-labs/billing-best-practices ``` ```bash npx skills add commet-labs/pricing-models ``` ```bash npx skills add commet-labs/subscription-patterns ``` -------------------------------- ### Install Commet SDK Source: https://commet.co/llms-full.txt Commands to create a new Encore project and install the Commet Go SDK. ```bash encore app create --example=hello-world myapp cd myapp go get github.com/commet-labs/commet-go ``` -------------------------------- ### Install Commet SDK Source: https://commet.co/llms-full.txt Install the SDK using your preferred package manager. ```bash pip install commet-sdk ``` ```bash uv add commet-sdk ``` ```bash poetry add commet-sdk ``` -------------------------------- ### Simple Upgrade Calculation Example Source: https://commet.co/docs/how-is-proration-calculated-when-changing-plans A practical example showing a mid-month upgrade from a $29/mo plan to a $99/mo plan. ```text Your customer is on Starter at $29/mo, paid on January 1. They upgrade to Pro at $99/mo on January 15 (15 days remaining). Credit for unused Starter days: $29 × (15/30) = $14.50 Charge for remaining Pro days: $99 × (15/30) = $49.50 They pay today: $35.00 Next full invoice: $99 on February 15 ``` -------------------------------- ### Install All Commet Skills Source: https://commet.co/llms-full.txt Installs all available Commet skills with a single command. Ensure you have npx installed. ```bash npx skills add commet-labs/commet-skills ``` -------------------------------- ### Install Commet SDK and dependencies Source: https://commet.co/docs/integrate-with-fastapi Install the necessary packages using your preferred package manager. ```bash pip install commet-sdk fastapi uvicorn ``` ```bash uv add commet-sdk fastapi uvicorn ``` ```bash poetry add commet-sdk fastapi uvicorn ``` -------------------------------- ### Install Single Commet Skill Source: https://commet.co/llms-full.txt Installs a specific Commet skill by its name. Use this for modular installation. ```bash npx skills add commet-labs/commet-skills --skill commet ``` ```bash npx skills add commet-labs/commet-skills --skill ai-billing ``` ```bash npx skills add commet-labs/commet-skills --skill billing-behaviors ``` ```bash npx skills add commet-labs/commet-skills --skill commet-webhooks ``` ```bash npx skills add commet-labs/commet-skills --skill commet-cli ``` -------------------------------- ### Install Commet SDKs Source: https://commet.co/llms-full.txt Install the required Node.js and Next.js packages using your preferred package manager. ```bash pnpm add @commet/node @commet/next ``` ```bash npm install @commet/node @commet/next ``` ```bash yarn add @commet/node @commet/next ``` ```bash bun add @commet/node @commet/next ``` -------------------------------- ### Install SDK for Laravel Source: https://commet.co/docs/integrate-with-laravel Use this command to install the SDK. Ensure you are in your Laravel project directory. ```bash composer require --dev laravel/pint ``` -------------------------------- ### Install Billing Best Practices Skill Source: https://commet.co/llms-full.txt Install the specific billing best practices skill for production-ready billing integration knowledge. ```bash npx skills add commet-labs/billing-best-practices ``` -------------------------------- ### Install Commet AI SDK Source: https://commet.co/docs/ai-token-billing Install the package to enable automatic token tracking with the Vercel AI SDK. ```bash npm install @commet/ai-sdk ``` -------------------------------- ### Install Commet SDK Source: https://commet.co/llms-full.txt Install the Commet Node package using the Bun package manager. ```bash bun add @commet/node ``` -------------------------------- ### Full Server Setup with Commet Plugin Source: https://commet.co/llms-full.txt Comprehensive server-side setup for Better Auth, including the Commet plugin with customer creation, portal, subscriptions, features, usage, and seats. ```typescript import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { commet as commetPlugin, portal, subscriptions, features, usage, seats, } from "@commet/better-auth"; import { Commet } from "@commet/node"; import { db } from "./db"; import * as schema from "./schema"; const commetClient = new Commet({ apiKey: process.env.COMMET_API_KEY!, environment: process.env.COMMET_ENVIRONMENT as "sandbox" | "production", }); export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", schema }), emailAndPassword: { enabled: true }, plugins: [ commetPlugin({ client: commetClient, createCustomerOnSignUp: true, getCustomerCreateParams: ({ user }) => ({ legalName: user.name, }), use: [ portal({ returnUrl: "/dashboard" }), subscriptions(), features(), usage(), seats(), ], }), ], }); ``` -------------------------------- ### Install commet-sdk for Flask using pip Source: https://commet.co/docs/integrate-with-flask Use this command to install the commet-sdk and the Flask integration package via pip. Ensure you have pip installed. ```bash pip install commet-sdk flask ``` -------------------------------- ### Install Commet Node SDK with Remix Source: https://commet.co/llms-full.txt Install the necessary Commet and Remix packages using your preferred package manager. ```bash pnpm add @commet/node @remix-run/node ``` ```bash npm install @commet/node @remix-run/node ``` ```bash yarn add @commet/node @remix-run/node ``` ```bash bun add @commet/node @remix-run/node ``` -------------------------------- ### Install Commet CLI Source: https://commet.co/llms-full.txt Global installation commands for the Commet CLI using various package managers. ```bash pnpm add -g commet ``` ```bash npm install -g commet ``` ```bash yarn global add commet ``` -------------------------------- ### Install Commet SDK for Django Source: https://commet.co/docs/integrate-with-django Install the Commet SDK and Django using pip, uv, or poetry. Ensure you have the necessary packages for integration. ```bash pip install commet-sdk django ``` ```bash uv add commet-sdk django ``` ```bash poetry add commet-sdk django ``` -------------------------------- ### Install Commet SDK and Flask Source: https://commet.co/docs/integrate-with-flask Install the necessary packages for integrating Commet with Flask using pip, uv, or poetry. ```bash pip install commet-sdk flask ``` ```bash uv add commet-sdk flask ``` ```bash poetry add commet-sdk flask ``` -------------------------------- ### Quarterly Plan Billing Example Source: https://commet.co/docs/how-do-monthly-quarterly-and-yearly-billing-work This example outlines the billing process for a quarterly plan, detailing how usage charges are handled each month and how the full invoice is generated at renewal. ```text Month 1: → Your customer used extra API calls? They get a small invoice for just the overage. → No extra usage? No invoice at all. Month 2: → Same thing — only charged if they had extra usage. Month 3 (renewal month): → Full invoice: plan base ($300) + any extra usage + any extra seats. → Billing cycle resets for the next quarter. ``` -------------------------------- ### Install Commet SDK with pip Source: https://commet.co/docs/integrate-with-django Use this command to install the Commet SDK for Django using pip. ```bash pip install commet-sdk django ``` -------------------------------- ### Install Commet SDK for FastAPI Source: https://commet.co/docs/integrate-with-fastapi Commands to install the necessary packages using different Python package managers. ```bash pip install commet-sdk fastapi uvicorn ``` -------------------------------- ### Install Commet Node and Hono Source: https://commet.co/llms-full.txt Install the necessary packages for Commet Node and Hono using your preferred package manager. ```bash pnpm add @commet/node hono ``` ```bash npm install @commet/node hono ``` ```bash bun add @commet/node hono ``` -------------------------------- ### Start Hono Server with Node.js Source: https://commet.co/llms-full.txt Set up and start a Hono server using Node.js, routing billing-related requests to the billing router. ```typescript import { serve } from '@hono/node-server' import { Hono } from 'hono' import billing from './routes/billing' const app = new Hono() app.route('/billing', billing) serve({ fetch: app.fetch, port: 3000 }) ``` -------------------------------- ### Quarterly Plan Example Header Source: https://commet.co/docs/how-do-monthly-quarterly-and-yearly-billing-work Displays a header for a quarterly plan example, including the plan details and a link to a specific section. ```jsx

Example: Quarterly plan at $300/quarter

``` -------------------------------- ### Example JSON Object Source: https://commet.co/docs/add-ons An example JSON object representing a subscription activation, including the activation timestamp. ```json { "activatedAt": "2026-03-11T00:00:00.000Z" } ``` -------------------------------- ### Start Express Server Source: https://commet.co/llms-full.txt Initializes an Express application, sets up JSON body parsing, and mounts the billing routes. Starts the server on port 3000. ```typescript import express from 'express' import billingRoutes from './routes/billing' const app = express() app.use(express.json()) app.use('/billing', billingRoutes) app.listen(3000) ``` -------------------------------- ### SDK Reference - Setup Source: https://commet.co/docs/sdk-reference Instructions on how to set up the SDK. ```APIDOC ## Setup ### Description Instructions on how to set up the SDK. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Setup Commet CLI Source: https://commet.co/llms-full.txt Initial authentication and project linking commands. ```bash commet login # Authenticate in browser commet link # Link project to organization commet pull # Generate TypeScript types ``` -------------------------------- ### Start Server Configuration Source: https://commet.co/docs/integrate-with-flask Initializes the Flask application and imports billing routes. ```python from flask import Flask from routes.billing import billing ``` -------------------------------- ### Define Commet Route and Feature Check Source: https://commet.co/docs/integrate-with-symfony Example of defining a GET route and a corresponding public function to validate features for a specific customer. ```php #[Route('/billing/features/{feature}/{customerId}', methods: ['GET'])] public function checkFeature(string $feature, string $customerId): JsonResponse { $result = $this->commet->features ``` -------------------------------- ### Redirect to Customer Portal Source: https://commet.co/llms-full.txt Implement a GET endpoint to generate and redirect the user to the Commet customer portal. A hardcoded customer ID is used as an example. ```typescript export default defineEventHandler(async (event) => { const customerId = 'user_123' const { data } = await commet.portal.getUrl({ customerId }) return sendRedirect(event, data.portalUrl) }) ``` -------------------------------- ### Mid-Cycle Plan Upgrade Example Source: https://commet.co/llms-full.txt Demonstrates the billing impact of upgrading a plan mid-cycle, including credit for unused time and the start of a new billing cycle. ```text Your customer is on Plan A at $300/quarter (January 1 – April 1). They upgrade to Plan B at $600/quarter on February 15. → They get credit for the unused portion of Plan A. → They're charged a prorated amount for Plan B. → Their new cycle starts February 15, next renewal May 15. ``` -------------------------------- ### Initialize Commet Client Source: https://commet.co/llms-full.txt Setup the Commet client using secrets managed by Encore. ```go package billing import ( commet "github.com/commet-labs/commet-go" ) var secrets struct { CommetAPIKey string CommetWebhookSecret string } var client *commet.Client func initClient() error { var err error client, err = commet.New( secrets.CommetAPIKey, commet.WithEnvironment(commet.Sandbox), ) return err } ``` -------------------------------- ### Usage in React Components Source: https://commet.co/llms-full.txt Example of using the auth client within a React component to manage billing and check feature access. Requires client-side setup. ```tsx "use client"; import { authClient } from "@/lib/auth-client"; export function BillingSection() { const handlePortal = async () => { await authClient.customer.portal(); }; const checkFeature = async () => { const { data } = await authClient.features.canUse("api_calls"); if (data?.allowed) { // Proceed with action await authClient.usage.track({ feature: "api_calls" }); } }; return (
); } ``` -------------------------------- ### SDK Initialization and Configuration Source: https://commet.co/llms-full.txt How to initialize the Commet client with an API key and optional configuration settings. ```APIDOC ## SDK Initialization ### Description Initialize the Commet client to interact with the API. ### Parameters #### Options - **apiKey** (string) - Required - Your API key (starts with ck_) - **environment** ('sandbox' | 'production') - Optional - Target environment (default: 'sandbox') - **debug** (boolean) - Optional - Log requests/responses (default: false) - **timeout** (number) - Optional - Request timeout in ms (default: 30000) - **retries** (number) - Optional - Max retry attempts (default: 3) ### Request Example ```typescript import { Commet } from '@commet/node' const commet = new Commet({ apiKey: process.env.COMMET_API_KEY!, debug: true }) ``` ``` -------------------------------- ### Handle Stripe Webhook Events in PHP Source: https://commet.co/docs/integrate-with-symfony This example shows how to set up a webhook endpoint to receive and process events from Stripe. It includes signature verification for security. The Stripe PHP SDK must be installed. ```php 'Webhook signature verification failed.']); exit(); } // Handle the event switch ($event->type) { case 'payment_intent.succeeded': $paymentIntent = $event->data->object; // contains a // Then define and call a function to handle the successful payment intent. // handle_payment_intent_succeeded($paymentIntent); break; case 'payment_method.attached': $paymentMethod = $event->data->object; // contains a // Then define and call a function to handle the attached payment method. // handle_payment_method_attached($paymentMethod); break; // ... handle other event types default: // Unexpected event type http_response_code(400); exit(); } http_response_code(200); ``` -------------------------------- ### LLM Response: Redirect to Portal URL Source: https://commet.co/docs/integrate-with-fastapi This example shows how to construct a redirect response using data from an LLM. It extracts a portal URL from the LLM's result to guide the user to the correct destination. ```python return RedirectResponse(result.data["portal_url"]) ``` -------------------------------- ### SDK Initialization and Configuration Source: https://commet.co/docs/sdk-reference How to initialize the Commet client and configure options like API keys, environments, and debug mode. ```APIDOC ## SDK Initialization ### Description Initialize the Commet client using your API key. The SDK supports sandbox and production environments. ### Parameters - **apiKey** (string) - Required - Your API key (starts with ck_) - **environment** ('sandbox' | 'production') - Optional - Target environment (default: 'sandbox') - **debug** (boolean) - Optional - Log requests/responses (default: false) - **timeout** (number) - Optional - Request timeout in ms (default: 30000) - **retries** (number) - Optional - Max retry attempts (default: 3) ### Request Example ```javascript import { Commet } from '@commet/node' const commet = new Commet({ apiKey: process.env.COMMET_API_KEY!, environment: 'sandbox', debug: true }) ``` ``` -------------------------------- ### GET /subscription/active Source: https://commet.co/docs/how-do-free-plans-work-without-payment Get the active subscription. ```APIDOC ## GET /subscription/active ### Description Get active subscription. ### Method GET ### Endpoint /subscription/active ``` -------------------------------- ### Initialize Flask and Commet Source: https://commet.co/docs/integrate-with-flask Basic setup for a Flask application and the Commet client initialization. ```python from routes.webhooks import webhooks_bp app = Flask(__name__) ``` ```python commet = Commet( api_key= ``` -------------------------------- ### GET /seats/balances Source: https://commet.co/docs/how-do-free-plans-work-without-payment Get all seat balances. ```APIDOC ## GET /seats/balances ### Description Get all seat balances. ### Method GET ### Endpoint /seats/balances ``` -------------------------------- ### Install SDK for Symfony Source: https://commet.co/docs/integrate-with-symfony Use this command to install the necessary SDK for integrating billing and payments into your Symfony application. Ensure you have Composer installed. ```bash composer require --dev "stripe/stripe-php" ``` -------------------------------- ### Initialize HTTP Server in Go Source: https://commet.co/llms-full.txt Configures routes for billing operations and starts the server on port 3000. ```go package main import ( "billing" "log" "net/http" ) func main() { billing.Init() defer billing.Client.Close() mux := http.NewServeMux() mux.HandleFunc("POST /billing/subscribe", billing.Subscribe) mux.HandleFunc("GET /billing/subscription/{customerID}", billing.GetSubscription) mux.HandleFunc("GET /billing/features/{feature}/{customerID}", billing.CheckFeature) mux.HandleFunc("POST /billing/usage", billing.TrackUsage) mux.HandleFunc("GET /billing/portal", billing.Portal) mux.HandleFunc("POST /webhooks/commet", billing.HandleWebhook) log.Println("Listening on :3000") log.Fatal(http.ListenAndServe(":3000", mux)) } ``` -------------------------------- ### GET /features/access Source: https://commet.co/docs/integrate-with-fastapi Get feature access information. ```APIDOC ## GET /features/access ### Description Get feature access. ### Method GET ### Endpoint /features/access ``` -------------------------------- ### Install Commet SDK with uv Source: https://commet.co/llms-full.txt Use uv to add the Commet SDK and Django to your project. ```bash uv add commet-sdk django ``` -------------------------------- ### GET /seats/balance Source: https://commet.co/docs/how-do-free-plans-work-without-payment Get a specific seat balance. ```APIDOC ## GET /seats/balance ### Description Get seat balance. ### Method GET ### Endpoint /seats/balance ``` -------------------------------- ### Configure Commet SDK Source: https://commet.co/llms-full.txt Set your API key in the environment file and initialize the Commet client. ```text COMMET_API_KEY=ck_sandbox_xxx ``` ```php validate([ 'email' => 'required|email', 'customer_id' => 'required|string', ]); $this->commet->customers->create( email: $request->input('email'), id: $request->input('customer_id'), ); $subscription = $this->commet->subscriptions->create( customerId: $request->input('customer_id'), planCode: 'pro', ); } ``` -------------------------------- ### GET /docs/api-reference/seats/get-seat-balance Source: https://commet.co/docs/customer-portal Get current balance for a specific seat type. ```APIDOC ## GET /docs/api-reference/seats/get-seat-balance ### Description Get current balance for a specific seat type. ``` -------------------------------- ### GET /docs/api-reference/subscriptions/get-active-subscription Source: https://commet.co/docs/customer-portal Get the active subscription for a customer. Returns null if none. ```APIDOC ## GET /docs/api-reference/subscriptions/get-active-subscription ### Description Get the active subscription for a customer. Returns null if none. ``` -------------------------------- ### Calculate Free to Paid Upgrade Source: https://commet.co/llms-full.txt Example showing the immediate payment required when moving from a free plan to a paid plan. ```text Your customer is on a Free plan with $100 included balance. They upgrade to Pro at $99/mo. Credit from free plan: $0 (it's free) They pay today: $99 (full month) ``` -------------------------------- ### GET /plans/{id} Source: https://commet.co/docs/how-do-trial-periods-work Get detailed plan information by code or ID. ```APIDOC ## GET /plans/{id} ### Description Get detailed plan information by code or ID. ``` -------------------------------- ### Add Seats Example Source: https://commet.co/docs/seat-management Example of adding seats using an asynchronous operation. ```javascript await this.addSeats({ seatType: "editor", count: 5, billing: "$25/seat/month" }); ``` -------------------------------- ### Initialize Commet SDK Source: https://commet.co/docs/sdk-reference Import and initialize the Commet SDK with your API key. Ensure the COMMET_API_KEY environment variable is set. ```javascript import { Commet } from '@commet/node' const commet = new Commet({ apiKey: process.env.COMMET_API_KEY! }) ``` -------------------------------- ### Client Setup with Commet Plugin Source: https://commet.co/llms-full.txt Initialize the Better Auth client on the frontend, including the Commet plugin for client-side authentication interactions. ```typescript import { createAuthClient } from "better-auth/react"; import { commetClient } from "@commet/better-auth"; export const authClient = createAuthClient({ baseURL: process.env.NEXT_PUBLIC_BETTER_AUTH_URL, plugins: [commetClient()], }); export const { signIn, signUp, signOut, useSession } = authClient; ``` -------------------------------- ### GET /docs/api-reference/seats/get-all-seat-balances Source: https://commet.co/docs/customer-portal Get the current balance for all seat types in a customer's subscription. ```APIDOC ## GET /docs/api-reference/seats/get-all-seat-balances ### Description Get the current balance for all seat types in a customer's subscription. ``` -------------------------------- ### Seat Type Examples Source: https://commet.co/docs/seat-management Examples of seat types and their corresponding counts and billing information. ```html
Component Description Example
Seat Type Category of user license editor, admin, viewer
Count Number of seats to add, remove, or set 5, 10, 50
Billing Seats are billed per unit on the plan $25/seat/month
``` -------------------------------- ### Start FastAPI Server with Commet Routers Source: https://commet.co/docs/integrate-with-fastapi This script sets up a FastAPI application and includes the billing and webhooks routers. It also shows the command to run the server using uvicorn. ```python from fastapi import FastAPI from routes.billing import router as billing_router from routes.webhooks import router as webhooks_router app = FastAPI() app.include_router(billing_router) app.include_router(webhooks_router) ``` ```bash uvicorn main:app --port 3000 ``` -------------------------------- ### Initialize Commet client Source: https://commet.co/docs/integrate-with-fastapi Create a reusable Commet client instance using the API key from environment variables. ```python import os from commet import Commet commet = Commet( api_key=os.environ["COMMET_API_KEY"], environment="sandbox", ) ``` -------------------------------- ### Initialize Comet Client in Go Source: https://commet.co/llms-full.txt Initialize the Comet client using your API key and environment settings. Ensure the API key is loaded from environment variables. ```go package billing import ( "log" "os" commet "github.com/commet-labs/commet-go" ) var Client *commet.Client func Init() { var err error Client, err = commet.New( os.Getenv("COMMET_API_KEY"), commet.WithEnvironment(commet.Sandbox), ) if err != nil { log.Fatal(err) } } ``` -------------------------------- ### Install Commet Node Package Source: https://commet.co/llms-full.txt Install the Commet Node.js package using your preferred package manager. ```bash pnpm add @commet/node ``` ```bash npm install @commet/node ``` ```bash yarn add @commet/node ``` ```bash bun add @commet/node ``` -------------------------------- ### Instantiate Commet Factory Source: https://commet.co/docs/integrate-with-symfony Shows how to instantiate the Commet Factory and call its 'create' method. This is the primary way to get a Commet instance. ```php factory : '@App\\Factory\\CommetFactory', create ``` -------------------------------- ### Install Commet Better Auth dependencies Source: https://commet.co/llms-full.txt Install the required packages using your preferred package manager. ```bash pnpm add better-auth @commet/better-auth @commet/node ``` ```bash npm install better-auth @commet/better-auth @commet/node ``` ```bash yarn add better-auth @commet/better-auth @commet/node ``` ```bash bun add better-auth @commet/better-auth @commet/node ``` -------------------------------- ### Implement subscription route Source: https://commet.co/docs/integrate-with-fastapi Create a FastAPI route to handle customer creation and subscription initiation. ```python from fastapi import APIRouter from pydantic import BaseModel from commet_client import commet router = APIRouter(prefix="/billing") class SubscribeRequest(BaseModel): customer_id: str email: str @router.post("/subscribe") def subscribe(body: SubscribeRequest): commet.customers.create( email=body.email, id=body.customer_id, ) subscription = commet.subscriptions.create( customer_id=body.customer_id, plan_code="pro", ) return {"checkout_url": subscription.data["checkout_url"]} ``` -------------------------------- ### Install Commet Node Package Source: https://commet.co/llms-full.txt Install the Commet Node.js package and Express using your preferred package manager. ```bash pnpm add @commet/node express ``` ```bash npm install @commet/node express ``` ```bash yarn add @commet/node express ```