API Reference

Manage subscriptions, check entitlements, and view usage.

Endpoints

Get Current Subscription

GET /v1/billing/subscription

Response:

{
  "id": "sub_123",
  "plan": "pro",
  "status": "active",
  "currentPeriodStart": "2024-01-01T00:00:00Z",
  "currentPeriodEnd": "2024-02-01T00:00:00Z",
  "cancelAtPeriodEnd": false
}

Check Entitlement

GET /v1/billing/entitlement?product=send

Response:

{
  "hasAccess": true,
  "product": "send",
  "limits": {
    "apiCalls": 10000,
    "emails": 5000
  },
  "usage": {
    "apiCalls": 1234,
    "emails": 567
  }
}

Get Usage

GET /v1/billing/usage?period=current

Response:

{
  "period": {
    "start": "2024-01-01T00:00:00Z",
    "end": "2024-02-01T00:00:00Z"
  },
  "usage": {
    "apiCalls": 1234,
    "emails": 567,
    "storage": 104857600
  }
}

List Invoices

GET /v1/billing/invoices?limit=10

Response:

{
  "data": [
    {
      "id": "inv_123",
      "amount": 2000,
      "currency": "usd",
      "status": "paid",
      "createdAt": "2024-01-01T00:00:00Z",
      "pdfUrl": "https://..."
    }
  ],
  "pagination": {
    "hasMore": false
  }
}

Create Checkout Session

For client-side subscription flows:

POST /v1/billing/checkout

Request:

{
  "priceId": "price_pro",
  "successUrl": "https://your-app.com/success",
  "cancelUrl": "https://your-app.com/cancel"
}

Response:

{
  "url": "https://checkout.stripe.com/..."
}

Webhooks

Subscribe to billing events:

EventDescription
subscription.createdNew subscription started
subscription.updatedSubscription changed
subscription.canceledSubscription canceled
invoice.paidPayment successful
invoice.failedPayment failed

Cross-Domain Usage

For subdomains (send.dev, transcribe.dev, etc.):

// Report usage from subdomain
await fetch('https://do.dev/api/billing/usage', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${token}`,
  },
  body: JSON.stringify({
    product: 'send',
    usageType: 'email_send',
    quantity: 1,
  }),
});

On this page