Skip to main content
This is the starting point for integrating Alguna from code. Alguna is one system for the whole quote-to-cash flow — pricing and packaging, subscriptions, usage metering, credits, invoicing, payment collection and revenue recognition — and everything the dashboard does for a sales-led deal is available to your application through the same API for a self-serve one. This page takes you from an API key to a metered, invoiced subscription, and links out to the deeper reference for each step. If you are new to the objects involved — customers, products, plans, subscriptions and their versions, metrics, invoices — read How Alguna works first. It is short, and every endpoint below maps onto it.

1. Get an API key

  1. Sign in to the dashboard: app.alguna.io for production, app.sandbox.alguna.io for sandbox.
  2. Go to Settings → Connections → Developers → API keys and create a key.
  3. Store it as an environment variable. It is a server-side secret — never ship it to a browser or a mobile app.
Sandbox and production are separate environments with separate keys and separate data. Build against sandbox first.

2. Base URL, authentication and versioning

Every request carries two headers: Bodies are JSON in snake_case; amounts are decimal strings; timestamps are RFC 3339. Every response carries an X-Request-Id header — log it. Full details: API overview.

3. First request: create a customer

A customer is the account you bill. Give it your own identifier as an alias so you never need to store Alguna IDs: anywhere the API takes a customer, an alias works in place of the ID.
name and currency are required. The response is the customer object, including its id. Reference: Create a customer, Look up a customer ID by alias.
Install the SDK with npm install @alguna/sdk. It is generated from the same OpenAPI spec as this reference, so every endpoint has a typed method and failed calls throw typed errors. See the TypeScript SDK.

4. Start a subscription

Pricing lives on products and is packaged into plans. The simplest way to subscribe a customer is to reference a plan; the subscription’s items are materialized from it. Subscriptions are created in draft — pass auto_activate: true to go live in one call, or call Activate a subscription later.
The Idempotency-Key makes the call safe to retry: a repeat with the same key returns the original subscription instead of creating a second one. See Idempotency. Once active, Alguna generates invoices on the schedule the plan defines and collects payment with the customer’s stored payment method. For inline pricing, per-customer overrides and bundles, see Creating a subscription; for upgrades and downgrades, Updating a subscription.

5. Meter usage

Usage-based prices read a billable metric: a named aggregation (count, count_unique, sum, average, min, max) over events with a given event_name, optionally filtered by event properties. Create the metric once, attach it to a metered product, then send events as usage happens.

Create a metric

Send events

Up to 100 events per request. The response lists which unique_ids were ingested and which failed. Batch and buffer on your side; send asynchronously. Full guide: Send usage events. Reference: Ingest billable events.

6. Gate features and credits

Two read paths tell your application what a customer is allowed to do:
  • Entitlements — feature flags and limits attached to the customer’s active subscription. GET /customers/{id}/entitlements returns them keyed by key with a type and value. See Entitlements and List active entitlements for a customer.
  • Credits — for prepaid or usage-gated products, POST /credits/check prices an intended action against the customer’s balance and can reserve the amount while the work runs; POST /credits/track settles it. See Credit consumption.

7. Sell self-serve

For product-led signups you do not need to build a payment form. Mint a session server-side, hand the returned url to the browser: Both sessions are short-lived and are created with your secret key; only the url (and, for embedded checkout, the session_token) is safe to expose. The end-to-end flow with trials and credits is in Launch self-serve.

8. Receive webhooks

Webhooks push events to your endpoint so you do not poll. Configure them under Settings → Connections → Developers → Webhooks: add your endpoint URL, choose events, and copy the signing secret. Events you will most likely subscribe to first: Payloads are camelCase, wrapped as { "type", "timestamp", "data" }. Delivery is through Svix with signed requests; verify with the Svix library for your language rather than a hand-rolled check:
Respond with a 2xx quickly and do the work asynchronously; failed deliveries are retried on a backoff. The full event catalogue, payloads and retry schedule are on the Webhooks page; the dashboard walkthrough is the Webhooks quick start.

9. Errors, retries and idempotency

Every error is { "status": <code>, "detail": "<message>" }. Branch on the status, never on the text. The SDK raises ValidationError (400), AuthenticationError (401), NotFoundError (404), RateLimitError (429, with retryAfter) and ApiError for everything else, each carrying requestId. Details and retry guidance: Errors, Idempotency.

10. Test in sandbox

  1. Sign in at app.sandbox.alguna.io and create a sandbox API key.
  2. Point your integration at https://api.sandbox.alguna.io (with the SDK, pass baseUrl).
  3. Connect your payment processor’s test mode and use its test cards at checkout.
  4. Point webhooks at a tunnel (for example ngrok) or a request-capture service while you develop.
Run the whole lifecycle in sandbox — create, activate, meter, invoice, pay, cancel — before switching keys and base URL to production.

11. Use the API from an AI assistant

The same operations are exposed as tools on Alguna’s MCP server at https://api.alguna.io/mcp, with OAuth sign-in for clients that support it and an API key via mcp-remote for those that do not. Connect Claude, Cursor or ChatGPT to look up customers, create subscriptions or ingest events in natural language. See Model Context Protocol.

Limits


Common patterns

Provision on signup
  1. User signs up → POST /customers with your user ID as an alias
  2. POST /subscriptions with plan_id and auto_activate: true (or send them through checkout)
  3. Webhook subscription.activated → enable features; read entitlements as needed
Usage-based billing
  1. POST /events as usage happens, batched, with a stable unique_id
  2. End of period: Alguna aggregates the metric and issues the invoice → webhook invoice.issued
  3. Payment collected → webhook invoice.paid
Prepaid credits
  1. Grant credits (POST /subscriptions/{id}/credits/grant) → webhook account.credits.granted
  2. Before expensive work, POST /credits/check; after it, POST /credits/track
  3. Balance hits zero → webhook account.credits.balance_depleted → prompt an upgrade or top-up

Reference

API overview

Base URLs, headers, filtering, pagination.

TypeScript SDK

Typed client, errors and idempotency options.

Webhooks

Every event and payload.

Send usage

Event shape, batching and CSV import.

Metrics reference

Aggregations and filter operators.

Credits & wallets

Grants, consumption and wallets.

Subscriptions

Lifecycle, versions and amendments.

Model Context Protocol

Drive Alguna from an AI assistant.

AI & Infrastructure

Token-based and usage billing.

Self-Serve (PLG)

Checkout and upgrade flows.

Fintech & Payments

Transaction-based metering.

← Back to Quick Starts

See all quick start guides