Skip to main content

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.

Fastify

Fastify requires explicit baseUrl config when deployed behind a proxy:
const monkePay = MonkePayFastify({
  apiKeyId: process.env.MONKEPAY_API_KEY_ID!,
  apiKeySecret: process.env.MONKEPAY_API_KEY_SECRET!,
  price: '0.001',
  baseUrl: 'https://api.yourcompany.com', // your public URL
})
If baseUrl is not set, the Fastify adapter falls back through this order:
  1. baseUrl config — highest priority
  2. X-Forwarded-Proto request header — set by most reverse proxies
  3. request.protocol — Fastify’s detected protocol
  4. 'http' — last resort
Most Railway and Render deployments set X-Forwarded-Proto: https automatically, so baseUrl may not be strictly required. If you see payment failures with incorrect resource URLs in the 402 response, set baseUrl explicitly.

Express

Configure Express to trust your proxy so it reads X-Forwarded-* headers correctly:
// Trust one level of proxy (e.g. Railway, Render, Fly)
app.set('trust proxy', 1)

// Or trust all proxies (if behind multiple layers like Cloudflare + Nginx)
app.set('trust proxy', true)
With trust proxy set, Express correctly reads X-Forwarded-Proto and X-Forwarded-For. The x402-express package uses this to construct the correct resource URL.

Hono

Hono handles proxy headers automatically in most runtimes. No additional configuration needed for standard deployments on Railway, Render, or Fly. If you’re seeing incorrect resource URLs, check that your proxy is setting X-Forwarded-Proto correctly.

Next.js

Next.js on Vercel handles this automatically. No configuration needed.

Verifying your resource URLs

To check what resource URLs are being constructed, look at the 402 response body:
curl -i https://api.yourcompany.com/api/data
The accepts[0].resource field should match your public HTTPS URL exactly:
{
  "accepts": [{
    "resource": "https://api.yourcompany.com/api/data",
    ...
  }]
}
If it shows http:// or an internal hostname, set baseUrl (Fastify) or trust proxy (Express).