A small, real AI chatbot repository powered by the official Google Gemini API. It is designed to work on its own and to be copied into an existing hackathon project with minimal changes.
The app provides a responsive chat interface for general-purpose questions, including explanations, coding, math, writing, planning, brainstorming, and everyday questions. It keeps the current conversation in browser memory and sends that history to Gemini for every new turn.
It does not claim to know live information. Current events, live prices, and other time-sensitive questions may require a separate search or tools integration.
- Next.js App Router with TypeScript and React.
app/page.tsx: client-side chat UI and in-session message state.app/api/chat/route.ts: server-side API route. It validates the request, readsGEMINI_API_KEY, sends the conversation to Gemini using@google/genai, and returns the model response.app/globals.css: dependency-free responsive styling.prompts/integration-agent-prompt.md: ready-to-copy instructions for integrating the chatbot into another project.
The browser never receives the API key. The client only calls /api/chat; the server route calls Gemini.
- Node.js 18.18 or newer.
- A Gemini API key from Google AI Studio.
pnpm install
copy .env.example .env.localAdd your key to .env.local:
GEMINI_API_KEY=your_key_here
GEMINI_MODEL=gemini-3.8-flash
GEMINI_FALLBACK_MODELS=gemini-3.7-flash,gemini-3.6-flashGEMINI_MODEL and GEMINI_FALLBACK_MODELS are optional. If the primary model is temporarily busy, the server retries the configured fallback models. Keep GEMINI_API_KEY server-only: do not rename it with a NEXT_PUBLIC_ prefix and do not place it in client code.
Start the app:
pnpm devOpen http://localhost:3000.
- Run
pnpm lintto run the TypeScript check. - Run
pnpm buildto verify the production build. - Run
pnpm dev, open the browser, and send a question. - Ask a follow-up such as “What was the main point of my last question?” to verify conversation context.
- Stop the server, remove the key, restart, and confirm the UI shows a helpful configuration error.
- Check that
.env.localis ignored by Git and that no source file contains the key.
Start with the main project. Identify its framework, language, frontend and backend structure, package manager, routing, and environment-variable conventions. Then inspect this repository and choose the smallest compatible strategy.
Copy or adapt app/api/chat/route.ts into the existing App Router API route structure. Reuse the request validation and GoogleGenAI call. Adapt app/page.tsx and app/globals.css to the existing component and styling conventions. Add GEMINI_API_KEY to the main project's environment file.
Keep the chat component in the Vite client, but do not move the Gemini call into the browser. Add a small server endpoint using the project's existing backend, or add a compatible serverless function. The Vite client should call that endpoint with the message history. Use the project's existing .env convention only for public client values; keep the Gemini key in the server environment.
Adapt the markup, styles, and browser event logic from app/page.tsx into the existing page. Add a server endpoint in the existing backend or hosting platform's function format. The browser calls that endpoint; it must not call Gemini directly with the secret key.
Reuse the validation and Gemini call from app/api/chat/route.ts in an Express POST /api/chat handler. Put GEMINI_API_KEY in the server process environment. Serve or embed the UI using the existing frontend approach.
Preserve the host project's framework and conventions. The portable contract is simple: send { "messages": [{ "role": "user" | "model", "text": "..." }] } to a server-side POST /api/chat endpoint and receive { "message": { "role": "model", "text": "..." } } or { "error": "..." }.
Important integration files are app/api/chat/route.ts for server behavior, app/page.tsx for interaction behavior, app/globals.css for styling, .env.example for configuration, and prompts/integration-agent-prompt.md for the integration workflow.
When the integrated project is deployed to Vercel:
- Open the Vercel project settings.
- Add
GEMINI_API_KEYunder Environment Variables for Development, Preview, and Production as appropriate. - Optionally add
GEMINI_MODELif a different supported model is needed. - Redeploy after adding or changing environment variables when Vercel requires it.
Never commit the key to GitHub, expose it through NEXT_PUBLIC_*, or send it to the browser. Restrict the API key in Google AI Studio where possible.
The UI is intentionally dependency-free. Change the colors, spacing, typography, and responsive rules in app/globals.css. Change the assistant behavior in the systemInstruction inside app/api/chat/route.ts. Keep the server boundary intact when customizing the UI.
- Give Codex the main project URL and this repository URL.
- Ask Codex to read
prompts/integration-agent-prompt.mdand follow it. - Let Codex inspect the main project before editing anything.
- Have it reuse the server route and client behavior using the main project's own framework and package manager.
- Add
GEMINI_API_KEYto the main project's local and deployment environment settings. - Test a first question, a context-dependent follow-up, a clear-chat action, and the missing-key error.
- Run the main project's type check, lint, build, and the smallest practical browser/API smoke test.
- Review the changed-file list and confirm no secrets were added.
The goal is a working feature with minimal edits during the three-hour window, not a framework migration or a new product subsystem.
This project uses the current @google/genai JavaScript SDK style documented by Google: Generate content with the Gemini API.