Echo
Next.js SDK

Overview

Server-side Echo integration for Next.js App Router

Next.js SDK

Server-side Echo integration for Next.js App Router with automatic session management.

The Next.js SDK handles OAuth authentication server-side, managing tokens automatically across your API routes and server components. Users authenticate once, and Echo handles billing for all subsequent AI calls.

Key features:

  • Server-side authentication with automatic token refresh
  • Type-safe API route helpers
  • Seamless integration with Vercel AI SDK
  • Zero client-side API key exposure

Installation

npm install @merit-systems/echo-next-sdk ai
pnpm add @merit-systems/echo-next-sdk ai
yarn add @merit-systems/echo-next-sdk ai
bun add @merit-systems/echo-next-sdk ai

Quick Start

Set up Echo in your Next.js app:

src/echo/index.ts
import Echo from "@merit-systems/echo-next-sdk";

export const { handlers, isSignedIn, openai, anthropic } = Echo({
  appId: "your-echo-app-id",
});

Create the API route:

src/app/api/echo/[...echo]/route.ts
import { handlers } from "@/echo";
export const { GET, POST } = handlers;

Use in your app:

app/page.tsx
import { signIn, isSignedIn } from "@merit-systems/echo-next-sdk/client";

export default function Home() {
  if (!isSignedIn()) {
    return <button onClick={() => signIn()}>Sign In</button>;
  }
  return <div>Ready to build!</div>;
}

Documentation Sections

  • Server - Server-side authentication and API routes
  • Client - Client-side utilities for Echo authentication

For a complete walkthrough, see the Next.js quickstart guide.