Skip to content

Next.js Vercel Adapter

View the complete sample on GitHub

A create-next-app-shaped chat sample where the Vercel AI SDK owns the client and the providers, and Strands Agents runs the loop, tools, sessions, and hooks inside the Next.js route handler through the VercelModel adapter. One-click deploy to Vercel, plus a container path to Amazon Bedrock AgentCore.

Overview

Sample Details

InformationDetails
Agent ArchitectureSingle-agent
Native Toolscalculator, current_time
Custom ToolsNone (Zod-typed tools defined inline in lib/tools.ts)
MCP ServersNone
Use Case VerticalDeveloper tooling / Conversational AI
ComplexityIntermediate
Model ProviderAmazon Bedrock (default) or OpenAI
SDK UsedStrands Agents SDK (TypeScript) + Vercel AI SDK

Architecture

Architecture — AI SDK on the client, Strands on the server

The route handler translates Strands stream events into the AI SDK UI message stream protocol (text-delta, tool-input-available, tool-output-available), so useChat renders tokens and tool activity as they arrive.

Key Features

  • AI SDK on the client — useChat from @ai-sdk/react manages the conversation and streaming UI.
  • Strands on the server — the agent loop, Zod-typed tools, session persistence, and lifecycle hooks run in app/api/chat/route.ts.
  • VercelModel adapter — Strands wraps any Vercel AI SDK provider (@ai-sdk/amazon-bedrock, @ai-sdk/openai, …). Switch providers with one env var, no code changes.
  • One-click deploy to Vercel — ships as a serverless Node function.
  • Container path to Amazon Bedrock AgentCore — the same agent, served over the AgentCore HTTP contract (/ping + /invocations) on an ARM64 container.

Prerequisites

  • Node.js 18+
  • One model provider configured:
    • Amazon Bedrock (default): AWS credentials and model access enabled for the configured model, or
    • OpenAI: an OPENAI_API_KEY.
  • (Optional) Docker, for the AgentCore / Node host container paths.

Setup

  1. Configure environment variables:

    Terminal window
    cp .env.example .env.local
    # then fill in credentials (see Configuration below)
  2. Install dependencies:

    Terminal window
    npm install

Usage

Run the dev server:

Terminal window
npm run dev

Open http://localhost:3000. Try:

  • “what is 128 divided by 4?” → calls the calculator tool
  • “what time is it in America/Mexico_City?” → calls the current_time tool

Configuration

All configuration is via environment variables — see .env.example.

Model provider (the AI SDK owns the provider; Strands wraps it)

VariableDefaultDescription
MODEL_PROVIDERbedrockbedrock or openai.
AWS_REGIONus-east-1Region for Amazon Bedrock.
AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY—AWS credentials (Bedrock).
BEDROCK_MODEL_IDus.anthropic.claude-sonnet-4-20250514-v1:0Bedrock model id.
OPENAI_API_KEY—Required when MODEL_PROVIDER=openai.
OPENAI_MODEL_IDgpt-4o-miniOpenAI model id.

To switch to OpenAI, set MODEL_PROVIDER=openai and OPENAI_API_KEY — no code changes.

Sessions (Strands persists conversation state)

VariableDefaultDescription
SESSION_BACKENDmemorymemory, file, or s3.
SESSION_DIR./.sessionsDirectory for the file backend.
SESSION_S3_BUCKET—Bucket for the s3 backend.
SESSION_S3_PREFIXsessions/Key prefix for the s3 backend.

Deploy to Vercel

Vercel serverless architecture

Deploy with Vercel

The /api/chat route runs on the Node.js runtime. Set your provider env vars in the Vercel dashboard (see Configuration). For persistence across serverless instances, use SESSION_BACKEND=s3.

Container path → Amazon Bedrock AgentCore

The same Strands agent (lib/agent.ts) is also served over the AgentCore HTTP contract: GET /ping and POST /invocations (SSE streaming) on 0.0.0.0:8080, ARM64.

Amazon Bedrock AgentCore container architecture

Terminal window
# Run the AgentCore runtime locally
npm run agentcore
curl localhost:8080/ping
curl -N -X POST localhost:8080/invocations \
-H 'content-type: application/json' \
-d '{"prompt":"what is 21 * 2?","sessionId":"demo"}'
# Build the ARM64 image for AgentCore
docker build --platform linux/arm64 -f agentcore/Dockerfile -t strands-agentcore .

Push the image to Amazon ECR and create an AgentCore Runtime pointing at it. Use SESSION_BACKEND=s3 so conversation state survives across instances. See the AgentCore HTTP protocol contract.

Container path → any Node host

A production Dockerfile (standalone Next.js output) is included for running the full web app anywhere:

Docker on any Node host architecture

Terminal window
docker build -t strands-nextjs .
docker run -p 3000:3000 --env-file .env.local strands-nextjs

Project Structure

ComponentFile(s)Description
Chat UIapp/page.tsxClient chat UI (useChat).
API routeapp/api/chat/route.tsStrands loop bridged to the AI SDK UI stream.
Modellib/model.tsProvider selection → VercelModel.
Toolslib/tools.tsZod-typed tools.
Hookslib/hooks.tsLoggingPlugin — lifecycle hooks.
Sessionslib/session.tsPluggable session storage.
Agentlib/agent.tsAssembles the Agent.
AgentCoreagentcore/Container path to Amazon Bedrock AgentCore.

Additional Resources


Disclaimer

This sample is provided for educational and demonstration purposes only. It is not intended for production use without further development, testing, and hardening.

For production deployments, consider:

  • Implementing appropriate content filtering and safety measures
  • Following security best practices for your deployment environment
  • Conducting thorough testing and validation
  • Reviewing and adjusting configurations for your specific requirements