Call the API from a Next.js server route
Use raw fetch to generate a PDF from a Next.js App Router route handler.
This example shows how to call the Paperbase API directly with fetch from a Next.js 15 Route Handler — no SDK required.
Setup
Add your API key to .env.local:
Route handler
Calling the route from a client component
Handling quota errors
Using idempotency keys
If your route handler can be retried (e.g. from a queue), pass an Idempotency-Key header to ensure only one PDF is generated per logical operation:
Paperbase returns the cached response on a duplicate key with X-Idempotent-Replayed: true.
Related
- Authentication — API key types and quota limits
- Errors & warnings — all error codes and how to handle them
- SDK quickstart — use the typed SDK instead of raw fetch