How to Integrate Next.js for pension funds with Vercel AI SDK for AI agents
Combining Next.js for pension funds with the Vercel AI SDK gives you a clean path from pension-domain data to an interactive AI agent layer. The practical win is simple: your pension workflows stay in a Next.js app, while the Vercel AI SDK handles tool calling, streaming responses, and agent orchestration.
That means you can build member-facing assistants for contribution queries, retirement projections, document retrieval, and case triage without wiring everything into one monolith.
Prerequisites
- •Python 3.10+
- •Node.js 18+ for the Next.js app
- •A running Next.js for pension funds application with API routes enabled
- •A Vercel project with the AI SDK installed
- •Access to your pension system API or mock service
- •Environment variables configured:
- •
PENSION_API_BASE_URL - •
PENSION_API_KEY - •
OPENAI_API_KEYor your model provider key
- •
- •Python packages:
- •
requests - •
pydantic - •
httpx
- •
Integration Steps
- •
Expose pension capabilities from your Next.js app
Your Next.js layer should expose stable endpoints for the AI agent to call. In a pension context, keep these narrow: member lookup, contribution history, benefit estimate, and document status.
import requests from typing import Dict, Any PENSION_API_BASE_URL = "https://your-nextjs-pension-app.vercel.app/api" PENSION_API_KEY = "your-service-key" def get_member_profile(member_id: str) -> Dict[str, Any]: resp = requests.get( f"{PENSION_API_BASE_URL}/members/{member_id}", headers={"Authorization": f"Bearer {PENSION_API_KEY}"}, timeout=20, ) resp.raise_for_status() return resp.json() def get_benefit_estimate(member_id: str) -> Dict[str, Any]: resp = requests.get( f"{PENSION_API_BASE_URL}/members/{member_id}/estimate", headers={"Authorization": f"Bearer {PENSION_API_KEY}"}, timeout=20, ) resp.raise_for_status() return resp.json() - •
Wrap those endpoints as tools for the Vercel AI SDK
The Vercel AI SDK works best when you define tools with strict inputs and predictable outputs. In practice, that means your agent can ask for a member profile or estimate without guessing URL shapes.
from pydantic import BaseModel, Field import requests class MemberLookupInput(BaseModel): member_id: str = Field(..., description="Unique pension member identifier") class BenefitEstimateInput(BaseModel): member_id: str = Field(..., description="Unique pension member identifier") def fetch_member_profile(member_id: str): url = f"https://your-nextjs-pension-app.vercel.app/api/members/{member_id}" r = requests.get(url, headers={"Authorization": "Bearer your-service-key"}, timeout=20) r.raise_for_status() return r.json() def fetch_benefit_estimate(member_id: str): url = f"https://your-nextjs-pension-app.vercel.app/api/members/{member_id}/estimate" r = requests.get(url, headers={"Authorization": "Bearer your-service-key"}, timeout=20) r.raise_for_status() return r.json() - •
Create an agent runner that calls the Vercel AI SDK and forwards tool calls
In production you usually keep the model orchestration in one service and let it call your pension APIs through tools. The pattern below shows the Python side of that bridge: receive a user request, call the relevant endpoint, then feed structured data back into the agent flow.
from typing import Any, Dict def handle_pension_query(member_id: str) -> Dict[str, Any]: profile = fetch_member_profile(member_id) estimate = fetch_benefit_estimate(member_id) return { "member": profile, "estimate": estimate, "agent_hint": ( "Use this data to answer questions about contributions, " "retirement age, and projected monthly benefit." ), } if __name__ == "__main__": result = handle_pension_query("M123456") print(result) - •
Add a Next.js API route that returns agent-ready JSON
Your Next.js app should emit clean JSON so the agent doesn’t need to parse HTML or mixed payloads. Keep auth at the edge and normalize downstream responses before they hit the model.
import requests from typing import Dict def get_agent_ready_summary(member_id: str) -> Dict: resp = requests.get( f"https://your-nextjs-pension-app.vercel.app/api/agents/members/{member_id}/summary", headers={"Authorization": "Bearer your-service-key"}, timeout=20, ) resp.raise_for_status() return resp.json() summary = get_agent_ready_summary("M123456") print(summary["status"]) print(summary["projected_monthly_benefit"]) - •
Stream responses back to the UI through the Vercel AI SDK
The last piece is user experience. Let the Vercel AI SDK stream answers while it waits on pension data so members see progress instead of a blank screen.
import httpx async def stream_agent_response(prompt: str) -> None: async with httpx.AsyncClient(timeout=30) as client: response = await client.post( "https://your-agent-service.vercel.app/api/chat", json={"messages": [{"role": "user", "content": prompt}]}, headers={"Content-Type": "application/json"}, ) response.raise_for_status() print(response.json()) # Example usage in an async runtime: # await stream_agent_response("What will my monthly benefit be at age 65?")
Testing the Integration
Use a simple end-to-end check: call your pension summary endpoint and confirm the agent receives structured data it can reason over.
import requests
def test_integration():
url = "https://your-nextjs-pension-app.vercel.app/api/agents/members/M123456/summary"
resp = requests.get(url, headers={"Authorization": "Bearer your-service-key"}, timeout=20)
resp.raise_for_status()
payload = resp.json()
assert "member_name" in payload
assert "projected_monthly_benefit" in payload
assert payload["projected_monthly_benefit"] > 0
print("Integration OK")
print(payload)
if __name__ == "__main__":
test_integration()
Expected output:
Integration OK
{'member_name': 'Alicia Mensah', 'projected_monthly_benefit': 1840.55}
Real-World Use Cases
- •
Member self-service assistant
Answer “How much will I get at retirement?” by combining live pension data from Next.js with an AI agent that explains results in plain language. - •
Operations triage bot
Route cases like missing contributions, address changes, or benefit disputes to the right workflow based on structured responses from your pension backend. - •
Document-aware support
Pull policy docs, statements, and claim status from your Next.js app and let the Vercel AI SDK summarize them for agents or members.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit