Skip to content

tsengtinghan/stockbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Echo Next.js Chat Template

A full-featured chat application built with Next.js and Echo, showcasing AI billing, user management, and authentication.

Quick Start

Use the Echo CLI to create a new project with this template:

npx echo-start@latest --template next-chat

You'll be prompted for your Echo App ID. Don't have one? Get it at echo.merit.systems/new.


This is a demonstration Next.js application showcasing the power and simplicity of Echo - a platform that provides AI billing, user management, and authentication for AI applications.

πŸš€ What is Echo?

Echo is a comprehensive platform that handles the complex infrastructure needed for AI applications, including:

  • AI Billing & Usage Tracking - Automatic cost tracking and billing for AI API calls
  • User Authentication - Secure sign-in and session management
  • Balance Management - Real-time balance tracking and top-ups
  • Multi-Model Support - Seamless integration with OpenAI, Anthropic, and other AI providers

πŸ“‹ Demo Features

This demo application demonstrates:

  • βœ… AI Chat Interface - Interactive chat with GPT-4o and GPT-5 nano models
  • βœ… Echo Authentication - Secure user sign-in with Echo accounts
  • βœ… Real-time Balance Display - Live balance tracking in the header
  • βœ… Automatic Billing - AI usage automatically tracked and billed through Echo
  • βœ… Modern UI Components - Beautiful, responsive interface with Tailwind CSS
  • βœ… Streaming Responses - Real-time AI response streaming with reasoning display

πŸ—οΈ Architecture Overview

Application Structure

src/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ _components/
β”‚   β”‚   β”œβ”€β”€ chat.tsx              # Main chat interface component
β”‚   β”‚   β”œβ”€β”€ echo/
β”‚   β”‚   β”‚   β”œβ”€β”€ balance.tsx       # Real-time balance display
β”‚   β”‚   β”‚   └── sign-in-button.tsx # Echo authentication button
β”‚   β”‚   └── header.tsx            # App header with auth state
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ chat/
β”‚   β”‚   β”‚   └── route.ts          # Chat API endpoint using Echo OpenAI
β”‚   β”‚   └── echo/
β”‚   β”‚       └── [...echo]/
β”‚   β”‚           └── route.ts      # Echo webhook handlers
β”‚   β”œβ”€β”€ layout.tsx                # Root layout with Echo integration
β”‚   └── page.tsx                  # Main page with auth guard
β”œβ”€β”€ echo/
β”‚   └── index.ts                  # Echo SDK configuration
└── components/
    β”œβ”€β”€ ai-elements/              # Reusable AI chat components
    └── ui/                       # Base UI components (shadcn/ui)

Key Components

1. Echo SDK Configuration (src/echo/index.ts)

import Echo from '@merit-systems/echo-next-sdk';

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

2. Authentication Flow

  • Sign-in: Uses Echo's built-in authentication system
  • Session Management: Automatic session handling across requests
  • Auth Guards: Pages check authentication status server-side

3. AI Integration

  • Model Access: Direct access to OpenAI models through Echo
  • Automatic Billing: All AI usage is tracked and billed automatically
  • Streaming: Real-time response streaming with reasoning display

4. Balance Management

  • Real-time Updates: Live balance display in the header
  • Automatic Deduction: Costs automatically deducted from user balance
  • Top-up Integration: Users can add funds through Echo platform

πŸ”§ Echo Integration Details

Authentication

The app uses Echo's authentication system which provides:

  • Secure OAuth-based sign-in
  • Session management
  • User identity verification
// Check if user is signed in (server-side)
const signedIn = await isSignedIn();

// Sign in user (client-side)
import { signIn } from '@merit-systems/echo-next-sdk/client';
signIn();

AI Model Access

Echo provides direct access to AI models with automatic billing:

import { openai } from '@/echo';

// Use OpenAI models with automatic billing
const result = streamText({
  model: openai('gpt-4o'), // or "gpt-5-nano"
  messages: convertToModelMessages(messages),
});

Balance Management

Real-time balance tracking and display:

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

const echoClient = useEcho();
const balanceData = await echoClient.balance.getBalance();

API Endpoints

Echo provides webhook handlers for various platform events:

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

🚦 Getting Started

Prerequisites

  • Node.js 18+
  • pnpm (recommended) or npm
  • An Echo account (sign up here)

Setup

  1. Clone the repository

    git clone <repository-url>
    cd my-next-ai-app
  2. Install dependencies

    pnpm install
  3. Configure Echo

    • Visit echo.merit.systems
    • Create a new app and get your App ID
    • Update src/echo/index.ts with your App ID
  4. Run the development server

    pnpm dev
  5. Open the app Navigate to http://localhost:3000

Environment Setup

No environment variables needed! Echo handles all configuration through the App ID.

πŸ“š Learn More

Echo Documentation

Technology Stack

  • Framework: Next.js 15 with App Router
  • AI SDK: Vercel AI SDK with Echo integration
  • Styling: Tailwind CSS
  • UI Components: Radix UI primitives with shadcn/ui
  • Authentication: Echo built-in auth system
  • Billing: Automatic through Echo platform

πŸ”„ How It Works

  1. User Authentication: Users sign in through Echo's secure authentication system
  2. Balance Check: App displays user's current balance in real-time
  3. AI Interaction: Users chat with AI models (GPT-4o, GPT-5 nano)
  4. Automatic Billing: Each AI request is automatically tracked and billed
  5. Balance Updates: User balance is updated in real-time after each request

πŸ’‘ Key Benefits of Echo

  • Zero Infrastructure Setup: No need to manage API keys, billing systems, or user databases
  • Automatic Cost Tracking: Every AI request is tracked and billed automatically
  • Built-in Authentication: Secure user management out of the box
  • Multi-Model Support: Access to multiple AI providers through one interface
  • Real-time Balance: Users can see their usage and remaining balance instantly
  • Developer Friendly: Simple SDK integration with minimal boilerplate

πŸš€ Deployment

This app can be deployed to any platform that supports Next.js:

  • Vercel (recommended): vercel deploy
  • Netlify: Connect your git repository
  • Railway: railway deploy
  • Docker: Use the included Dockerfile

Make sure to update your Echo app configuration with your production domain.

πŸ“ž Support


Built with ❀️ using Echo - The simplest way to build AI applications with built-in billing and user management.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors