Docs Quickstart

Quickstart

Get Holdify running in 5 minutes.

1

Create an account

Sign up at app.holdify.io to create your account. You will get a project API key that you will use to authenticate with the Holdify API.

Create account
2

Connect your payment provider

Go to Settings → Integrations in the Holdify dashboard. This syncs your subscriptions so entitlements are automatically updated when customers subscribe, upgrade, or cancel.

Polar Stripe (Beta) LemonSqueezy (Beta)
3

Install the SDK

Install the @holdify/sdk package in your project.

Terminal
bash
npm install @holdify/sdk
# or
pnpm add @holdify/sdk
# or
yarn add @holdify/sdk

Add your project API key to your environment variables:

.env
env
# .env
HOLDIFY_PROJECT_KEY=hpk_live_your_project_key
4

Add middleware to your API

Choose your framework and add budget protection in one line. The middleware automatically verifies API keys and enforces budget limits.

// middleware.ts
import { withHoldify } from '@holdify/nextjs';

// Budget protection in one line
export default withHoldify();

export const config = {
  matcher: '/api/:path*',
};
5

Manual verification (optional)

For more control, you can use the SDK directly to verify API keys. The verify method returns the key's validity, remaining budget, and entitlements.

api/route.ts
typescript
import { Holdify } from '@holdify/sdk';

const holdify = new Holdify({
  apiKey: process.env.HOLDIFY_PROJECT_KEY,
});

// In your API route
export async function handleRequest(req: Request) {
  const apiKey = req.headers.get('x-api-key');

  const result = await holdify.verify(apiKey, {
    resource: 'api-calls',
    units: 1,
  });

  if (!result.valid) {
    return new Response('Invalid API key', { status: 401 });
  }

  if (result.remaining <= 0) {
    return new Response('Budget exceeded', { status: 402 });
  }

  // Process the request...
  return new Response('Success');
}

Response shape

The verify method returns the following fields:

VerifyResponse
typescript
{
  valid: boolean;        // Is the key valid?
  remaining: number;     // Remaining budget for this period
  reset: number;         // Unix timestamp when budget resets
  plan: string | null;   // Customer's plan (e.g., "pro")
  entitlements: string[]; // Feature flags
}

Next steps

You are all set!

Make sure you have completed these steps:

  • Created a Holdify account
  • Connected your payment provider
  • Installed the SDK
  • Added middleware to your API