An AI-powered full-stack web app that generates unique, branching choose-your-own-adventure stories on demand. Enter a theme — "pirates", "space exploration", "medieval fantasy" — and GPT-4o-mini builds a complete story graph with multiple paths and endings for you to play through in the browser.
Live demo: https://adventure-story-ai.vercel.app
| Layer | Technology |
|---|---|
| Frontend | React 19 + Vite |
| Backend | FastAPI (Python) |
| AI | LangChain + OpenAI GPT-4o-mini |
| Database | PostgreSQL (Neon serverless) |
| Deployment | Vercel |
Story generation requires an OpenAI API key. If you see "Request failed with status code 500" or a quota error, follow these steps:
Go to platform.openai.com and sign up (or log in if you already have an account).
- Click your profile icon → Billing
- Click Add to credit balance
- Add at least $5 — this is enough for hundreds of stories
GPT-4o-mini is very cheap (~$0.001 per story). $5 will last a long time.
- Go to platform.openai.com/api-keys
- Click Create new secret key
- Give it a name (e.g.
adventure-story-ai) - Copy the key — it starts with
sk-proj-...
⚠️ You only see the key once. Copy it now and store it somewhere safe.
For local development — add it to backend/.env:
OPENAI_API_KEY=sk-proj-your-key-here
For Vercel (production) — go to your Vercel project → Settings → Environment Variables → update OPENAI_API_KEY with your new key, then redeploy.
- Python 3.12+
- Node.js 18+
git clone https://github.com/srak71/AdventureStoryAI.git
cd AdventureStoryAIcd backend
pip install -r ../requirements.txtCreate backend/.env:
DEBUG=True
OPENAI_API_KEY=sk-proj-your-key-hereWhen DEBUG=True the app uses a local SQLite database automatically — no PostgreSQL needed.
Start the backend:
uvicorn main:app --reloadAPI will be at http://localhost:8000
cd frontend
npm installCreate frontend/.env.local:
VITE_DEBUG=trueStart the frontend:
npm run devApp will be at http://localhost:5173
| Variable | Required | Description |
|---|---|---|
OPENAI_API_KEY |
✅ | Your OpenAI API key |
DEBUG |
True for local dev (uses SQLite). Default: False |
|
DATABASE_URL |
Full PostgreSQL URL (e.g. from Neon). Auto-set when DEBUG=True |
|
ALLOWED_ORIGINS |
Comma-separated CORS origins, or * to allow all |
| Variable | Description |
|---|---|
VITE_DEBUG |
Set to true to proxy /api requests to localhost:8000 |
VITE_API_BASE_URL |
Override the API base URL for custom deployments |
The project is configured for Vercel with vercel.json at the root. Both the React frontend and FastAPI backend deploy together.
- Install the Vercel CLI:
npm install -g vercel - Run
vercel linkinside the project directory to connect to your Vercel project - Set your environment variables in the Vercel dashboard under Settings → Environment Variables:
OPENAI_API_KEY— your OpenAI keyDATABASE_URL— your Neon PostgreSQL connection string
vercel deploy --prodThe production deployment uses Neon serverless PostgreSQL (free tier). Tables are created automatically on first startup.
AdventureStoryAI/
├── api/
│ └── index.py # Vercel Python ASGI entry point
├── backend/
│ ├── core/
│ │ ├── config.py # Settings (pydantic-settings)
│ │ ├── models.py # LLM response schemas
│ │ ├── prompts.py # Story generation prompt
│ │ └── story_generator.py # LangChain + OpenAI logic
│ ├── db/
│ │ └── database.py # SQLAlchemy engine + session
│ ├── models/ # SQLAlchemy ORM models
│ ├── routers/ # FastAPI route handlers
│ ├── schemas/ # Pydantic request/response schemas
│ └── main.py # FastAPI app entry point
├── frontend/
│ └── src/
│ ├── components/ # React components
│ └── util.js # Shared constants
├── requirements.txt # Python dependencies
└── vercel.json # Vercel build + routing config
- User enters a theme in the browser
- Frontend
POST /api/stories/create→ FastAPI generates a job - Backend calls OpenAI GPT-4o-mini via LangChain, asking it to produce a complete branching story as structured JSON
- The full story graph (nodes + options) is saved to PostgreSQL
- Frontend polls
GET /api/jobs/:iduntil complete, then loadsGET /api/stories/:id/complete - The story is rendered as an interactive choose-your-own-adventure game entirely client-side — no extra fetches needed per choice