Part 1 of 3

API Route Basics

Creating a POST endpoint that receives messages and returns responses.

Now it's time to ask your AI IDE to build the chat feature. Here's how to frame the request:

The Prompt

"Create a chat API route at /api/chat that:

  • Receives messages from a chat widget
  • Uses the system prompt from ai-context.ts
  • Calls OpenRouter with Gemini 2.5 Flash
  • Returns the AI's response"

What Your AI IDE Will Create

It will generate a file at src/app/api/chat/route.ts that handles incoming messages and returns AI responses. You don't need to understand the code—just verify it works.

How to Verify

Ask your AI IDE: "Add a simple test button that sends a message to /api/chat and logs the response." Then check your browser console.