Originally forked from nextjs-example
This is a updated version of the Next.js demo application for the OpenRouter SDK. Main changes include:
- Upgraded to Next.js 16
- OAuth re-implementation
Original README below (adapted as needed):
This is a demonstration application that shows how to create a chat interface using the OpenRouter SDK. The app implements OAuth 2.0 authentication flow and provides a complete chat experience with multiple AI models.
⚠️ Security Notice: This demo application stores unencrypted API keys in localStorage for demonstration purposes only. Do not use this approach in production applications.
- OAuth 2.0 Integration: Secure authentication flow with OpenRouter
- Multi-Model Chat: Access to various AI models (GPT-4, Claude, Gemini, etc.)
- Real-time Streaming: Live response streaming for better user experience
- Modern UI: Clean interface built with Tailwind CSS and shadcn/ui components
- TypeScript: Full type safety with the OpenRouter SDK
- Node.js 22 or later
- An OpenRouter account
- OpenRouter application configured with OAuth callback
- Clone the repository and navigate to the example directory:
git clone <repository-url>
cd or-nextchat- Install dependencies:
npm install- Start the development server:
npm run dev- Open http://localhost:3000 in your browser
The application is pre-configured to use http://localhost:3000/ as the OAuth
callback URL. If you need to change this:
- Update the
OAUTH_CALLBACK_URLinsrc/lib/config.ts - Configure your OpenRouter application with the matching callback URL
No environment variables are required for this demo, as it uses client-side OAuth flow.
- Connect Your Account: Click "Connect OpenRouter Account" to authenticate via OAuth
- Start Chatting: Once connected, navigate to the chat interface
- Select Models: Choose from available AI models using the dropdown menu
- Send Messages: Type your message and press Enter to send
src/
├── app/
│ ├── page.tsx # Home page with OAuth flow
│ ├── chat/page.tsx # Chat interface
│ └── oauth/callback/ # OAuth callback handler
├── components/ui/ # Reusable UI components
├── lib/
│ ├── config.ts # OAuth and app configuration
│ └── hooks/ # Custom React hooks
└── ...
- Uses OpenRouter's OAuth 2.0 implementation
- Handles authorization codes and token exchange
- Stores credentials in localStorage (demo only)
- Implements streaming responses using the OpenRouter SDK
- Supports multiple AI models through a single interface
- Real-time message updates with proper state management
import { OpenRouterCore } from "@openrouter/sdk/core";
import { chatSend } from "@openrouter/sdk/funcs/chatSend";
const openRouter = new OpenRouterCore({ apiKey });
const result = await chatSend(openRouter, {
model: "openai/gpt-4o",
messages: conversationHistory,
stream: true,
});npm run dev- Start development servernpm run build- Build for productionnpm run start- Start production servernpm run lint- Run ESLint
This project is licensed under the MIT License, see the LICENSE file for details.