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 aipnpm add @merit-systems/echo-next-sdk aiyarn add @merit-systems/echo-next-sdk aibun add @merit-systems/echo-next-sdk aiQuick Start
Set up Echo in your Next.js app:
import Echo from "@merit-systems/echo-next-sdk";
export const { handlers, isSignedIn, openai, anthropic } = Echo({
appId: "your-echo-app-id",
});Create the API route:
import { handlers } from "@/echo";
export const { GET, POST } = handlers;Use in your app:
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.