npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@merit-systems/echo-next-sdk

v0.0.32

Published

Next.js SDK for Echo

Readme

Echo Next.js SDK

The official Next.js SDK for the Echo platform, providing seamless authentication, AI provider integration, and easy access to Echo APIs in Next.js applications.

Installation

pnpm install @merit-systems/echo-next-sdk

Features

  • OAuth Authentication - Complete authentication flow with automatic token management
  • AI Provider Integration - Pre-configured OpenAI, Anthropic, and Google AI providers
  • Server & Client Components - Support for both server-side and client-side usage
  • Automatic Token Refresh - Handles token refresh automatically
  • TypeScript Support - Full TypeScript support with type definitions
  • Cookie-based Sessions - Secure HTTP-only cookie authentication

Quick Start

1. Server Setup

Create an Echo instance in your server code:

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

export const {
  // Echo Auth Routes
  handlers,

  // Server-side utilities
  getUser,
  isSignedIn,
  getEchoToken,

  // AI Providers
  openai,
  anthropic,
  google,
} = Echo({
  appId: process.env.NEXT_PUBLIC_ECHO_APP_ID!,
});

2. API Route Setup

Export the handlers in your API route:

// app/api/echo/[...echo]/route.ts
import { handlers } from '@/echo';

export const { GET, POST } = handlers;

This automatically sets up these authentication endpoints:

  • /api/echo/signin - Initiates OAuth flow
  • /api/echo/callback - OAuth callback handler
  • /api/echo/refresh - Token refresh endpoint
  • /api/echo/session - Session status endpoint
  • /api/echo/signout - Sign out endpoint

3. Client Provider Setup

Wrap your app with the Echo provider:

// providers.tsx
'use client';

import { EchoProvider } from '@merit-systems/echo-next-sdk/client';

export function Providers({ children }: { children: React.ReactNode }) {
  return (
    <EchoProvider config={{ appId: process.env.NEXT_PUBLIC_ECHO_APP_ID! }}>
      {children}
    </EchoProvider>
  );
}
// app/layout.tsx
import { Providers } from './providers';

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        <Providers>{children}</Providers>
      </body>
    </html>
  );
}

Usage

Server-Side Authentication

import { getUser, isSignedIn } from '@/echo';

export default async function Page() {
  const signedIn = await isSignedIn();

  if (!signedIn) {
    return <SignInButton />;
  }

  const user = await getUser();
  return <Dashboard user={user} />;
}

Client-Side Hook

'use client';

import { useEcho } from '@merit-systems/echo-next-sdk/client';

export default function MyComponent() {
  const {
    user,
    balance,
    freeTierBalance,
    signIn,
    signOut,
    echoClient,
    isLoading
  } = useEcho();

  if (isLoading) {
    return <div>Loading...</div>;
  }

  if (!user) {
    return <button onClick={signIn}>Sign In with Echo</button>;
  }

  return (
    <div>
      <p>Welcome {user.name}!</p>
      <p>Balance: ${balance?.balance || 0}</p>
      <button onClick={signOut}>Sign Out</button>
    </div>
  );
}

AI Provider Integration

Use Echo-wrapped AI providers with automatic billing:

// app/api/chat/route.ts
import { openai } from '@/echo';
import { streamText, convertToModelMessages } from 'ai';

export async function POST(req: Request) {
  const { messages } = await req.json();

  const result = streamText({
    model: openai('gpt-4o'),
    messages: convertToModelMessages(messages),
  });

  return result.toUIMessageStreamResponse();
}

Direct API Access

Access the full Echo API through the client:

'use client';

import { useEcho } from '@merit-systems/echo-next-sdk/client';

export default function PaymentComponent() {
  const { echoClient } = useEcho();

  const createPaymentLink = async () => {
    if (!echoClient) return;

    const paymentLink = await echoClient.payments.createPaymentLink({
      amount: 10,
      description: 'Credits for my account',
    });

    window.open(paymentLink.url, '_blank');
  };

  return <button onClick={createPaymentLink}>Add Credits</button>;
}

Configuration

The Echo constructor accepts the following configuration:

| Option | Type | Required | Default | Description | | ---------- | -------- | -------- | ----------- | ------------------------ | | appId | string | ✅ | - | Your Echo App ID | | basePath | string | ❌ | /api/echo | Base path for API routes |

Environment Variables

Set these environment variables in your .env.local:

NEXT_PUBLIC_ECHO_APP_ID=your_echo_app_id_here

Components

The SDK re-exports helpful components from the React SDK:

import {
  EchoSignIn,
  EchoSignOut,
  EchoTokens,
  InsufficientFundsModal,
} from '@merit-systems/echo-next-sdk/client';

TypeScript Support

The SDK is built with TypeScript and provides full type definitions for all methods and responses. Import types as needed:

import type { EchoConfig, EchoResult } from '@merit-systems/echo-next-sdk';

Documentation

For complete documentation and examples, visit:

Requirements

  • Next.js 15.0.0 or higher
  • React 18.0.0 or 19.0.0
  • Node.js 18 or higher