Skip to content

Nuxt tutorial

In this tutorial, you’ll build the Nuxt UI for Bargain Chef and connect it to your existing Genkit backend. It uses two AI patterns Genkit simplifies: streaming structured output and tool calling.

The user types what they’re craving, Gemini drafts a recipe, and the model calls a tool to look up mock grocery sale prices so it can prefer on-sale ingredients. The recipe streams into the UI incrementally, so users see progress before the full recipe is ready.

You can find the finished code on GitHub.

You’ll call the existing bargainChefFlow over HTTP and render the streamed recipe as fields arrive.

  • Node.js v20 or later
  • npm (or another Node package manager)
  • Familiarity with Nuxt and TypeScript

You should have already completed the Chi, Echo, or other backend tutorial. This tutorial picks up where those leave off and adds a Nuxt UI to the bargainChefFlow you already built there. Make sure your backend is running and note the port it serves on, since you’ll need it later.

Create the Nuxt project:

Terminal window
npx nuxi@latest init my-genkit-nuxt
cd my-genkit-nuxt

Install the Genkit web client, which lets the browser call your backend:

Terminal window
npm install genkit

Your backend should already expose bargainChefFlow. For reference, here’s the shape the Nuxt app expects:

// Input
{ craving: string }
// Streamed output (partial: fields fill in over time)
{
title?: string;
description?: string;
servings?: number;
ingredients?: { name: string; quantity: string; onSale: boolean }[];
steps?: string[];
}

If your backend exposes a flow with a different name or shape, adjust the URL and the Recipe interface in the next section accordingly.

At this point, your Nuxt app is ready to call the backend flow you already created.

The Nuxt side calls the flow with streamFlow from genkit/beta/client, then stores each partial recipe in a Vue ref so the template re-renders as fields arrive.

Replace the contents of app.vue with the following. The FLOW_URL points to your backend, so adjust the port or route if your backend doesn’t run at http://localhost:8080/bargainChefFlow.

app.vue
<script setup lang="ts">
import { ref } from 'vue';
import { streamFlow } from 'genkit/beta/client';
interface RecipeIngredient {
name?: string;
quantity?: string;
onSale?: boolean;
}
interface Recipe {
title?: string;
description?: string;
servings?: number;
ingredients?: RecipeIngredient[];
steps?: string[];
}
// Point this at the URL where your bargainChefFlow is served
const FLOW_URL = 'http://localhost:8080/bargainChefFlow';
const craving = ref('something warm with chicken');
const recipe = ref<Recipe | null>(null);
const isStreaming = ref(false);
async function generateRecipe() {
if (!craving.value.trim()) return;
recipe.value = null;
isStreaming.value = true;
try {
const result = streamFlow({
url: FLOW_URL,
input: { craving: craving.value },
});
// result.stream is an async iterable of partial recipes.
// Each chunk is the accumulated output so far.
for await (const partial of result.stream) {
recipe.value = partial as Recipe;
}
// Wait for the final validated output and surface any errors.
await result.output;
} catch (err) {
console.error('Failed to generate recipe', err);
} finally {
isStreaming.value = false;
}
}
</script>
<template>
<main>
<h1>Bargain Chef</h1>
<p class="tagline">
Tell me what you feel like eating and I'll suggest a recipe built around
today's grocery deals.
</p>
<form class="prompt" @submit.prevent="generateRecipe">
<input
type="text"
v-model="craving"
name="craving"
placeholder="What are you in the mood for?"
:disabled="isStreaming"
/>
<button type="submit" :disabled="isStreaming">
{{ isStreaming ? 'Cooking…' : 'Suggest a recipe' }}
</button>
</form>
<article v-if="recipe">
<h2 v-if="recipe.title">{{ recipe.title }}</h2>
<p v-if="recipe.description" class="description">
{{ recipe.description }}
</p>
<p v-if="recipe.servings" class="serves">
<strong>Serves:</strong> {{ recipe.servings }}
</p>
<template v-if="recipe.ingredients?.length">
<h3>Ingredients</h3>
<ul class="ingredients">
<li v-for="(ing, i) in recipe.ingredients" :key="i">
{{ ing.quantity }} {{ ing.name }}
<span v-if="ing.onSale" class="badge">on sale</span>
</li>
</ul>
</template>
<template v-if="recipe.steps?.length">
<h3>Steps</h3>
<ol class="steps">
<li v-for="(step, i) in recipe.steps" :key="i">{{ step }}</li>
</ol>
</template>
</article>
</main>
</template>
<style scoped>
main {
max-width: 640px;
margin: 0 auto;
padding: 3rem 1.5rem;
font-family:
-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
Arial, sans-serif;
color: #1a1a1a;
}
h1 {
font-size: 2rem;
margin: 0 0 0.25rem;
letter-spacing: -0.01em;
}
.tagline {
color: #555;
margin: 0 0 2rem;
}
.prompt {
display: flex;
gap: 0.5rem;
margin-bottom: 2.5rem;
}
.prompt input {
flex: 1;
font: inherit;
font-size: 1rem;
padding: 0.75rem 1rem;
border: 1px solid #d0d0d0;
border-radius: 8px;
background: #fff;
transition:
border-color 120ms ease,
box-shadow 120ms ease;
}
.prompt input:focus {
outline: none;
border-color: #2563eb;
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.prompt input:disabled {
background: #f1f1f1;
color: #888;
}
.prompt button {
font: inherit;
font-size: 1rem;
font-weight: 500;
padding: 0.75rem 1.25rem;
border: 0;
border-radius: 8px;
background: #1a1a1a;
color: #fff;
cursor: pointer;
transition: background 120ms ease;
white-space: nowrap;
}
.prompt button:hover:not(:disabled) {
background: #2563eb;
}
.prompt button:disabled {
background: #999;
cursor: not-allowed;
}
article {
background: #fff;
border: 1px solid #e5e5e5;
border-radius: 12px;
padding: 1.5rem 1.75rem;
}
article h2 {
font-size: 1.5rem;
margin: 0 0 0.5rem;
}
article h3 {
font-size: 1rem;
text-transform: uppercase;
letter-spacing: 0.06em;
color: #666;
margin: 1.5rem 0 0.5rem;
}
.description {
color: #444;
margin: 0 0 1rem;
}
.serves {
color: #555;
margin: 0;
font-size: 0.95rem;
}
.ingredients,
.steps {
padding-left: 1.25rem;
line-height: 1.6;
}
.ingredients li {
margin-bottom: 0.25rem;
}
.steps li {
margin-bottom: 0.5rem;
}
.badge {
display: inline-block;
margin-left: 0.4rem;
padding: 0.05rem 0.5rem;
font-size: 0.75rem;
font-weight: 500;
background: #e8f5e9;
color: #2e7d32;
border-radius: 999px;
}
@media (max-width: 480px) {
.prompt {
flex-direction: column;
}
.prompt button {
width: 100%;
}
}
</style>

streamFlow returns an object with two useful properties: stream, an async iterable of partial recipe objects, and output, a promise that resolves with the final validated recipe. The component stores each partial recipe in a Vue ref, so the template re-renders on every update.

Each recipe section uses v-if so it only renders after that field arrives in the stream. The result is a UI that fills in progressively: title first, then description, then ingredients, then steps.

Wrapping the input and button in a <form> lets the user submit by pressing Enter. The @submit.prevent modifier stops the browser from reloading the page, then kicks off the streaming request.

Start your Genkit backend in one terminal by following the run instructions in the backend tutorial you used. Then start the Nuxt development server in another terminal:

Terminal window
npm run dev

Open http://localhost:3000, enter a craving like something warm with chicken, and submit. The recipe streams in field by field: title first, then description, then ingredients (with “on sale” badges on the ones the model picked from the tool), then steps.

If the request fails, check the browser console first. The most common issue is a CORS error or a FLOW_URL that doesn’t match the backend route.

The Genkit Developer UI is a local console for testing flows and inspecting traces. It records every tool call, model invocation, and streamed chunk, so you can see what the model called, what it received back, and how the recipe was assembled.

If your backend is running under genkit start, the Developer UI is already running at http://localhost:4000.

In the Developer UI:

  • The Traces tab shows every invocation of bargainChefFlow, including requests from your Nuxt app. Open one and you’ll see the getIngredientsOnSale tool call with the dayType the model chose, the model invocation, and each streamed chunk that the browser received.
  • The Flows tab lets you run bargainChefFlow directly with custom input, which is useful for iterating on the prompt without round-tripping through the UI.

You now have a working Genkit app that streams structured output from Gemini into a Nuxt UI incrementally, calls a tool during generation to ground the model’s response in mock sale-price data, validates input and output against schemas, and surfaces every step in a local trace UI.

  • Creating flows: Compose multi-step flows, branch on input, and chain model calls.
  • Generating content: Swap Gemini for another provider, tune sampling parameters, and work with multimodal input.
  • Deploy your app: Ship to Cloud Run, Vercel, Firebase, or your own infrastructure.
  • Developer tools: Dig deeper into the Developer UI, tracing, and evaluation.