Skip to main content
The easiest way to integrate ParaLens into a Next.js app is to create an API route that proxies requests. This hides the Railway URL from client-side code, forwards future API keys securely via server-side environment variables, and gives you a single place to add caching or logging as your app grows.

Prerequisites

  • Next.js 13+ with the App Router (app/ directory)
  • TypeScript (recommended — types shown throughout this guide)

Setup

1

Create the API route file

Create a new file at app/api/analyze/route.ts. Next.js will automatically expose this as POST /api/analyze when the app is running.
The route reads PARALENS_API_URL from the server environment and forwards the request body as-is. The upstream HTTP status is preserved so your frontend error handling works correctly.
2

Add the environment variable

Add the Railway base URL to .env.local. This file is read only by Next.js server-side code and is never included in the client bundle.
Never prefix this variable with NEXT_PUBLIC_. Public variables are embedded in the client bundle and visible to anyone who inspects your JavaScript. Keep the Railway URL server-side only.
3

Call the proxy from your frontend

In any client component, call /api/analyze instead of the Railway URL directly.
4

(Optional) Add response caching

Ethereum transactions are immutable once confirmed, so the same hash will always produce the same report. Add caching at the proxy layer to avoid redundant upstream calls.See the Adding Caching section below for an in-memory and Redis example.

Adding Caching

Because confirmed transactions never change, you can safely cache responses indefinitely. A 24-hour TTL is a practical default that balances freshness with performance. In-memory cache — suitable for single-instance deployments or development:
Redis cache — recommended for multi-instance or serverless deployments (e.g., Vercel). Use ioredis or the @upstash/redis client:

Future API Key Support

ParaLens does not require authentication today, but future-compatible clients should be prepared to send an x-api-key header. When API keys are introduced, update your proxy to read PARALENS_API_KEY from the server environment and forward it — no changes needed in your frontend components.
Add the key to .env.local when you receive one:
Never expose your Railway URL or API key in client-side code or public environment variables (i.e., variables prefixed with NEXT_PUBLIC_). Always read credentials in server-only code such as API routes, Server Components, or getServerSideProps.

Next Steps

Now that your proxy is set up, head to Dashboard Layouts to learn how to use classification.intent_kind to choose the right UI layout for each transaction type.