intermediate~30 minutesai-app

AI App Starter — Cursor + D1 + Railway

Chat interface with streaming, history, and auth

Build your own ChatGPT-style app with streaming responses, conversation history, and usage limits. Powered by Claude or GPT-4.

CursorNext.js 14Cloudflare D1ClerkRailwayTailwind + shadcn/ui

What's Included

🤖

Streaming Chat

Real-time streaming responses from Claude or GPT-4

💬

Conversation History

Full chat history stored in D1

🔐

Auth + Usage Limits

Clerk auth with 50 messages/day free tier

📝

Markdown Rendering

AI responses rendered as formatted markdown

📊

Usage Dashboard

Track token usage and costs per user

Setup Guide

1

Clone and install

Clone the AI app starter.

$ git clone https://github.com/gptsters/ai-chat-starter my-ai-app && cd my-ai-app && npm install
2

Set up Clerk

Create Clerk account and add API keys.

Add to .env.local

NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=

CLERK_SECRET_KEY=

3

Create D1 database

For conversation history and usage tracking.

$ npx wrangler d1 create ai-chat-db
4

Add AI API key

Get your API key from Anthropic (Claude) or OpenAI (GPT-4).

Add to .env.local

ANTHROPIC_API_KEY=

💡 Claude Sonnet is the best balance of quality and cost for chat apps.

5

Deploy

Deploy to Railway.

$ npx railway login && npx railway up
Deploy free →

Cursor Prompt

Paste this into Cursor to generate the full codebase

Build an AI chat application:
- Next.js 14 App Router with streaming
- Cloudflare D1 for conversation history
- Clerk auth with usage limits
- Anthropic Claude API (claude-sonnet-4-20250514)
- Vercel AI SDK for streaming

Database tables:
- conversations: id, user_id, title, created_at
- messages: id, conversation_id, role (user/assistant), content, created_at
- usage: id, user_id, tokens_used, date

Features:
1. Chat interface with real-time streaming
2. Conversation list in sidebar
3. New conversation button
4. Message history per conversation
5. Usage counter (50 messages/day free)
6. Markdown rendering for AI responses

Start with schema, then streaming API route, then chat UI.

Tools You'll Need

Based on this starter's stack

Some links are affiliate links.

Common Issues

Related Starters

Frequently Asked Questions

~30 minutes. The setup guide walks you through every step with copy-paste commands. No guesswork.

$0-5/month (API costs). Railway's free tier includes 500 hours/month.

Yes. The starter kit gives you a working foundation. Use the included Cursor prompt to add features specific to your product.

Check our integration guides at /integrations and prompt library at /prompts for step-by-step instructions on adding any feature.