Groq API Key
The chatbot requires a Groq API key to call the inference API. Without it the route will return an authentication error.Create a Groq account
Go to console.groq.com and sign up or log in.
Generate an API key
Navigate to API Keys in the left sidebar and click Create API Key. Copy the key — it is only shown once.
Add the key to your environment
Create or edit The key is read in
.env.local in the project root:app/api/chat/route.ts:Changing the AI Model
The model is specified inapp/api/chat/route.ts:
"llama-3.1-8b-instant" with any model ID available on Groq. Common options:
| Model ID | Strengths | Trade-offs |
|---|---|---|
llama-3.1-8b-instant | Very fast, low latency | Smaller context window, less nuanced |
llama-3.3-70b-versatile | Higher quality, stronger reasoning | Slower, higher token cost |
mixtral-8x7b-32768 | Large 32 k context window | Moderate speed |
gemma2-9b-it | Efficient, instruction-tuned | Less capable than 70B models |
Check the Groq model documentation for the current list of available models and their context limits.
Adjusting Model Parameters
ThestreamText call in app/api/chat/route.ts is where you tune model behaviour. The Vercel AI SDK accepts all standard parameters alongside the required fields:
maxDuration controls the maximum wall-clock time (in seconds) the serverless function is allowed to run before Vercel terminates it:
0 to force a rebuild on every request, which is useful when iterating on portfolio-context.ts.
Customising the UI
initialOpen prop
AIDrawer accepts one prop:
When
true, the chat sidebar opens immediately when the component mounts. AIDrawerLazy passes initialOpen={true} after the user’s first click so the drawer opens as soon as the bundle loads.Colors
The chat UI uses CSS custom properties defined in your Tailwind theme. The primary interactive color (bg-primary, text-primary, border-primary) is referenced throughout:
- Floating button background:
bg-primary - Chat header background:
bg-primary - User message bubble:
bg-primary - Send button:
bg-primary - Input focus ring:
focus:border-primary - Streaming cursor:
bg-primary/40 - The pulsing dot on the floating button uses
bg-accent
--primary and --accent CSS variables in your global stylesheet to retheme the entire chat UI at once.
Floating button placement
The floating button is rendered by theFloatingButton sub-component inside AIDrawer, and by the placeholder button inside AIDrawerLazy (shown before the bundle loads). Both use the same Tailwind classes:
bottom-8 and right-8 to reposition the button.
Where the component is mounted
AIDrawerLazy is the component you should place in your layout. It is a client component ("use client") that wraps the full AIDrawer behind a dynamic import with ssr: false:
API Endpoint Reference
POST /api/chat
The single endpoint consumed by the chatbot UI.
Request
The full conversation history, including the message just sent. Each entry is a
UIMessage from the Vercel AI SDK (ai package v6). User messages use role: "user" and assistant messages use role: "assistant". Each message carries a parts array rather than a plain content string.A plain-text stream of the assistant’s response tokens. The
Content-Type header is text/plain; charset=utf-8. The client reads this stream via TextStreamChatTransport.- Authentication: None. The endpoint relies on same-origin browser requests; there is no API key check on incoming requests.
- Timeout: 30 seconds (
maxDuration = 30). Vercel terminates the function after this limit. - Context: The system prompt is injected server-side and is not part of the request body.
