Documentation Index
Fetch the complete documentation index at: https://docs.monkepay.xyz/llms.txt
Use this file to discover all available pages before exploring further.
Installation
npm install @monkepay/sdk next
Import
import { MonkePayNext } from '@monkepay/sdk/next'
Import from @monkepay/sdk/next, not @monkepay/sdk. The Next.js adapter is a separate subpath export to avoid loading next/server in non-Next runtimes (Express, Hono, Fastify). Importing the wrong path will cause a crash in those environments.
Basic usage
// app/api/data/route.ts
import { MonkePayNext } from '@monkepay/sdk/next'
import { NextResponse } from 'next/server'
const monkePay = MonkePayNext({
apiKeyId: process.env.MONKEPAY_API_KEY_ID!,
apiKeySecret: process.env.MONKEPAY_API_KEY_SECRET!,
price: '0.001',
})
export const GET = monkePay(async (req) => {
return NextResponse.json({ result: 'paid content' })
})
Per-route pricing
Pass overrides as the second argument:
const monkePay = MonkePayNext({
apiKeyId: process.env.MONKEPAY_API_KEY_ID!,
apiKeySecret: process.env.MONKEPAY_API_KEY_SECRET!,
price: '0.001',
})
// Different price on POST
export const GET = monkePay(async () =>
NextResponse.json({ result: 'cheap' })
)
export const POST = monkePay(
async (req) => NextResponse.json({ result: 'expensive' }),
{ price: '0.10' }
)
One-time payment mode
// app/api/report/route.ts
import { MonkePayNext } from '@monkepay/sdk/next'
import { NextResponse } from 'next/server'
const monkePay = MonkePayNext({
apiKeyId: process.env.MONKEPAY_API_KEY_ID!,
apiKeySecret: process.env.MONKEPAY_API_KEY_SECRET!,
price: '1.00',
paymentMode: 'one_time',
})
export const GET = monkePay(async () => {
return NextResponse.json({ report: '...' })
})
Environment variables
Add your keys to .env.local:
MONKEPAY_API_KEY_ID=mk_live_...
MONKEPAY_API_KEY_SECRET=...
In production, set these in your Vercel project settings under Environment Variables.
Important constraints
App Router only. The Pages Router (pages/api/) is not supported. Use MonkePayNext only in app/api/ route files.
Do not use middleware.ts. Next.js middleware runs in the Edge runtime which does not have Node.js crypto APIs needed for HMAC signing. MonkePayNext must be used in route handlers which run in the Node.js runtime.
No streaming. Payment settlement requires the full response to be available before sending. Streaming responses (ReadableStream, SSE) are not supported on payment-gated routes.
baseUrl has no effect for Next.js. Resource URL construction is handled internally.