# AI chat with Next.js

> A streaming chat interface for any OpenAI-compatible model, with the key kept on the server.

A Next.js chat app that streams replies from any OpenAI-compatible endpoint, such as OpenAI, Groq, OpenRouter or your own Ollama, with the API key kept on the server. Click Deploy, add your provider's address, key and model, and Naijacloud builds it from the public repo and gives you a live HTTPS address. No GitHub connection needed.

- Use case: AI
- Stack: Next.js
- Code: https://github.com/naijacloud/template-ai-chat-nextjs (branch `main`)
- Deploy: https://naijacloud.com/new?template=ai-chat-nextjs&ref=template-ai-chat-nextjs
- Free tier: fits (1 app per workspace)
- Last verified on Naijacloud: 9 Oct 2026
- Page: https://naijacloud.com/templates/ai-chat-nextjs

## What's inside

- Next.js 15 with the App Router and TypeScript
- /api/chat streams from <AI_BASE_URL>/chat/completions, so the key never reaches the browser
- Works with OpenAI, Groq, Together, OpenRouter or Ollama
- Until the variables are set, it says which ones are missing instead of failing

## What you get after deploying

- A live address at https://ai-chat-nextjs.naijacloud.app with HTTPS
- Build and runtime logs, metrics and redeploys from the dashboard

## Environment variables

| Name | What it is for | Default |
| --- | --- | --- |
| `AI_BASE_URL` | Your provider's API address, e.g. https://api.openai.com/v1 | none, you set it |
| `AI_API_KEY` | Your provider's key | none, you set it |
| `AI_MODEL` | The model name from your provider | none, you set it |
| `AI_SYSTEM_PROMPT` | Instructions sent before every conversation | none, you set it |

## Run it locally

```bash
git clone https://github.com/naijacloud/template-ai-chat-nextjs
cd template-ai-chat-nextjs
cp .env.example .env
npm install
npm run dev
```

Learn how it works: [Environment variables](https://naijacloud.com/docs/deploy/environment-variables)

All templates: https://naijacloud.com/templates
