An OpenAI-compatible chat app written in ReScript on the Next.js 16 App Router, using Bun and Tailwind CSS v4.
The UI streams tokens from POST /api/chat. That route calls ${OPENAI_BASE_URL}/chat/completions, so it works with OpenAI, OpenRouter, Groq, Ollama, Azure-compatible proxies, vLLM, and other Chat Completions servers.
Without OPENAI_API_KEY or OPENAI_BASE_URL, the API streams a local demo response so you can try the UI immediately.
Install dependencies:
bun installCopy the env file. Leave the key and base URL empty to keep demo mode; fill them in for a real model:
cp .env.example .env.localCompile ReScript and start the development server:
bun run res:build
bun devFor ReScript watch mode (auto-recompile on save), run in a separate terminal:
bun run res:devOpen http://localhost:3000.
| Variable | Default | Notes |
|---|---|---|
OPENAI_API_KEY |
unset | Bearer token. Optional for local servers that skip auth. |
OPENAI_BASE_URL |
unset (code default https://api.openai.com/v1) |
Must include /v1 when the provider uses it. |
OPENAI_MODEL |
unset (code default gpt-4o-mini) |
Sent as model in the Chat Completions body. |
OPENAI_SYSTEM_PROMPT |
unset | Prepended as a system message on the server. |
If both OPENAI_API_KEY and OPENAI_BASE_URL are unset, the route runs in demo mode.
OpenAI:
OPENAI_API_KEY=sk-...
OPENAI_BASE_URL=https://api.openai.com/v1
OPENAI_MODEL=gpt-4o-miniOpenRouter:
OPENAI_API_KEY=sk-or-...
OPENAI_BASE_URL=https://openrouter.ai/api/v1
OPENAI_MODEL=openai/gpt-4o-miniOllama:
OPENAI_BASE_URL=http://localhost:11434/v1
OPENAI_MODEL=llama3.2
OPENAI_API_KEY=ollamasrc/
├── app/
│ ├── layout.res # Root layout (fonts, metadata, CSS)
│ ├── page.res # Home page
│ ├── Chat.res # Client chat UI
│ ├── globals.css # Tailwind CSS + theme variables
│ └── api/chat/route.res # GET config + POST streaming completions
├── chat/
│ ├── Message.res # Message types and JSON decoding
│ ├── OpenAI.res # OpenAI-compatible client + demo stream
│ └── Sse.res # SSE parser for Chat Completions chunks
└── bindings/
├── Next.res # Metadata (add Next APIs as needed)
└── WebApi.res # fetch, streams, abort
| Command | Description |
|---|---|
bun dev |
Start development server |
bun run build |
Compile ReScript + build for production |
bun run res:build |
Compile ReScript files |
bun run res:dev |
ReScript watch mode |
bun run res:clean |
Clean ReScript build artifacts |
bun run lint |
Run Biome linter and formatter checks |
bun run format |
Auto-format code with Biome |