Voice Profile Onboarding โ€” replace a signup form with a two-minute voice chat, and cut its cost by 70%

New users don't like long profile forms. But a household or finance app needs to know a lot about...

Gustavo Sanchez (Open-Source)12 min read2 kali dilihat
Voice Profile Onboarding โ€” replace a signup form with a two-minute voice chat, and cut its cost by 70%

New users don't like long profile forms. But a household or finance app needs to know a lot about them: who they live with, if they rent, how they move around, what they pay for every month.

So I asked a simple question: what if the user could just talk for two minutes instead?

In this tutorial I'll show you how I built that experiment, step by step. You'll see the architecture, the important code, and the real numbers, including the mistakes that cost me money.

What we're building

Voice Profile Onboarding is a Next.js app with this flow:

  1. The user signs up and verifies their email.
  2. They type a few basic details (name, phone, addresses with a map).
  3. They talk for about two minutes with a voice guide about their everyday life.
  4. Claude turns the conversation into a structured profile.
  5. The app suggests up to 25 providers near their home: landlord, utilities, healthcare, supermarkets, restaurants and entertainment. Each one has a logo and a reason.
  6. The user ticks the ones they want, and they are saved.

The voice guide speaking: a violet audio sphere and the guide's first question

Suggested providers grouped by priority, with logos and reasons

It is also an A/B experiment. Half of the users record a single voice note, and the other half have a guided conversation with a voice agent. The app logs time, completeness and cost for both.

The stack:

| Job | Tool | |---|---| | App | Next.js 16, React 19, TypeScript, Tailwind CSS 4 | | Auth | Better Auth (email + password + email verification), Resend | | Database | Neon Postgres + Drizzle ORM | | Voice | ElevenLabs Agents (conversation) and Scribe (speech-to-text) | | LLM | Claude API with structured outputs | | Places | Google Maps Platform (Places, Geocoding, Maps JavaScript) |

The most important decision: agent or workflow?

Before writing code, I had to answer a question that many AI projects skip: which parts really need an agent?

An agent is great when the next step is not known in advance. A workflow is better when the steps are fixed, because it is cheaper, faster and easier to test.

This is how I split it:

  • Voice conversation โ†’ agent. Turn-taking, short follow-up questions and knowing when to finish are open-ended. That is real agent work.
  • Profile extraction โ†’ one LLM call. The transcript goes in, a JSON object comes out. Nothing to explore.
  • Provider suggestions โ†’ fixed workflow. Claude plans the searches, my code runs Google Places, Claude ranks the results. My code controls the order, so cost and latency have a cap.

So the honest description is: an AI app with one agentic component, not an "agentic app". This decision saved me a lot of money later.

Prerequisites

  • Node.js 22.18+ and pnpm 10
  • Accounts for Neon, Anthropic, ElevenLabs and Google Cloud (Resend is optional)
  • Basic knowledge of React and API routes

The full code is open source, so you can follow along or just clone it:

Step 1: Start the voice call safely

The browser talks to ElevenLabs directly, for low latency. But the API key must never reach the browser. The solution is a signed URL: my server asks ElevenLabs for a short-lived URL, and the browser uses it to connect.

// src/app/api/elevenlabs/signed-url/route.ts
export async function GET() {
  const { error } = await requireUser(); // only signed-in users
  if (error) return error;
  const { signedUrl } = await elevenlabs().conversationalAi.conversations.getSignedUrl({
    agentId: process.env.ELEVENLABS_AGENT_ID!,
  });
  return Response.json({ signedUrl });
}

I also turn on authentication in the agent settings (platformSettings: { auth: { enableAuth: true } }). Without it, anyone who finds your agent ID can start conversations and spend your credits.

Step 2: Create the voice agent as code

I don't configure the agent by clicking in a dashboard. A script creates it, so I can version the prompt and repeat the setup:

// scripts/setup-elevenlabs-agent.mts (simplified)
conversationConfig: {
  agent: {
    firstMessage: "Hi {{user_name}}! A few quick questions so we can suggest places near you. Who do you live with?",
    prompt: {
      prompt: PROMPT,              // 5 topics, short turns, no read-backs
      llm: "claude-haiku-5-5",     // small and fast is enough here
      toolIds: [finishToolId],     // one client tool: finish_onboarding
      builtInTools: { endCall: { name: "end_call", params: { systemToolType: "end_call" } } },
    },
  },
  conversation: { maxDurationSeconds: 360 },   // hard cap: 6 minutes
  turn: { silenceEndCallTimeout: 25 },          // hang up after 25 s of silence
  asr: { keywords: ["UDR", "Greystar", "Netflix", "Platzi" /* ... */] },
}

Two commands manage it: pnpm setup:agent creates it once, and pnpm update:agent applies prompt changes to the same agent ID.

Step 3: Connect React to the agent

The @elevenlabs/react package gives you a provider and hooks. The agent can call client tools, which are functions that run in the browser. My agent has only one, and it marks the conversation as finished:

// src/components/voice-onboarding.tsx (simplified)
useConversationClientTool("finish_onboarding", () => {
  setFinished(true);
  return "Done. Say one short goodbye. The call ends automatically after that.";
});

// After the goodbye finishes playing, hang up. Every connected minute is billed.
useEffect(() => {
  if (!connected || !finished) return;
  const fallback = setTimeout(() => endSession(), 20000);
  const afterGoodbye = mode === "listening" ? setTimeout(() => endSession(), 1500) : undefined;
  return () => {
    clearTimeout(fallback);
    if (afterGoodbye) clearTimeout(afterGoodbye);
  };
}, [connected, finished, mode, endSession]);

When the call starts, I send the agent what the user already typed, using a contextual update:

onConnect: ({ conversationId }) => {
  sendContextualUpdate(`Form status: the user typed these details on screen: ${describeForm(draft)}.`);
},

Why not put this in the system prompt? Because a system prompt that is the same for every user can be cached by the LLM. Personal data goes in the conversation, not in the prompt.

I also added a small sphere that moves with the audio, violet when the guide speaks and green when the user speaks. It uses getOutputByteFrequencyData() and getInputByteFrequencyData() from the same hook, drawn on a canvas. Before the call starts, the sphere is grey:

The voice card before the call: details typed above, a grey sphere and a Start button

When the user answers, the sphere turns green and follows the microphone:

The voice guide listening: a green audio sphere reacting to the user's voice

Step 4: Turn the transcript into a profile

This is a single Claude call with structured outputs. I describe the profile with Zod, and the SDK returns a typed object that matches the schema:

// src/lib/profile-schema.ts (part of it)
export const ExtractedProfileSchema = z.object({
  household: z.array(z.object({ relation: z.string(), name: z.string().nullable(), notes: z.string().nullable() })),
  housing: z.object({
    tenure: z.enum(["owner", "tenant", "living_with_family", "unknown"]),
    landlordOrManager: z.string().nullable().describe("Only if the user named one"),
  }),
  hobbies: z.array(z.string()),
  subscriptions: z.array(z.object({ name: z.string(), category: Category })),
  summary: z.string(),
  missingTopics: z.array(z.enum(["family", "housing", "transportation", "hobbies", "routines", "subscriptions"])),
});
// src/lib/claude.ts
const response = await client.beta.messages.parse({
  model: "claude-opus-5-5",
  max_tokens: 16000,
  betas: ["server-side-fallback-2026-07-01"],
  fallbacks: "default",
  output_config: { effort: "medium", format: betaZodOutputFormat(schema) },
  system,
  messages: [{ role: "user", content: user }],
});
if (response.stop_reason === "refusal") throw new Error("Claude declined");
return response.parsed_output;

The system prompt has one important rule: only record what the user actually said. Never guess. Empty is better than invented. The missingTopics field becomes a free completeness metric for the experiment.

Step 5: Suggest providers with a fixed workflow

This part has four steps:

  1. Household services (Claude). From the home address it names the landlord (only if the user said it), water, energy, gas, internet, mobile and health options, using local names. In San Francisco it suggests SFPUC, PG&E, Kaiser Permanente and Medi-Cal. In Chicago it suggests ComEd, Peoples Gas and Cook County Health.
  2. Search plan (Claude). For example "climbing gym near work" or "ramen near home". This runs in parallel with step 1.
  3. Search (my code). Google Places text search, then a hard filter at 5 miles and a filter for parks and neighborhoods.
  4. Rank (Claude). It picks the best candidates for the free slots, each with a reason tied to the profile.
// src/lib/suggest-providers.ts (simplified)
const [household, plan] = await Promise.all([
  structured({ system: HOUSEHOLD_SYSTEM, schema: HouseholdSchema, user: homeAndProfile }),
  structured({ system: PLAN_SYSTEM, schema: PlanSchema, user: homeWorkAndProfile }),
]);

const results = await Promise.all(
  plan.localSearches.slice(0, 14).map((s) => searchPlaces(s.query, anchors[s.anchor] ?? home, 4)),
);

// ...rank the remaining slots with Claude, then:
const suggestions = [...fixed, ...picked].sort((a, b) => priorityOf(a) - priorityOf(b));

The order is simple and explicit: landlord โ†’ utilities โ†’ healthcare โ†’ supermarkets โ†’ restaurants โ†’ entertainment โ†’ the rest. Utilities and health plans named by the LLM are saved as unverified, and the UI shows that tag. I prefer to be honest about what the model inferred.

Google Places doesn't return logos. So a small /api/logo route fetches the site's apple-touch-icon or favicon, and the UI shows initials if there is no logo.

Step 6: Measure before you optimize

This is the part I learned the most from. My first voice version asked for everything by voice, including name, phone, birthday and addresses. It worked, but how much did it cost?

I wrote a small script that reads each conversation from the ElevenLabs API:

// scripts/agent-usage.mts (simplified)
const c = await client.conversationalAi.conversations.get(id);
console.log(c.metadata.callDurationSecs, c.metadata.cost, c.metadata.charging?.llmCharge);

The result surprised me:

  • About 84% of the cost was a per-minute charge (around 219 credits per connected minute).
  • The LLM was only about 16%.

So the real problem was minutes, not tokens. These are the changes I made, in order of impact:

  1. Voice only for open questions. Typing a phone number is faster and more accurate than saying it. The details went back to the form, with a map to confirm each address:

    Typed details with the home and work addresses pinned on Google Maps

  2. Automatic hang-up after the goodbye, and when the tab is hidden for 30 seconds.

  3. Hard limits: 6-minute cap and hang-up after 25 seconds of silence.

  4. Shorter turns: one question at a time, no read-backs, at most one follow-up per topic.

  5. Fewer topics: from 7 to 5. I removed vacations, merged routines with hobbies, and stopped asking about utilities because the app finds them from the address.

  6. A smaller model: claude-haiku-5-5 instead of claude-sonnet-5-5 for the voice agent.

The results:

| Metric | Before | After | |---|---|---| | Call length | 5.5 min | 2.0 min | | Credits per call | 1,452 | 438 | | Cost per user | $0.53 | $0.16 (โˆ’70%) | | LLM charge per call | 146โ€“294 credits | 6 credits | | Topics missing from profile | โ€“ | 0 |

The cost went down 70%, and the profile stayed complete.

Bugs that real testing found

None of these appeared in my type checks. They appeared when I used the app like a real user.

  • The "๐Ÿ“ Here" button moved me to the wrong city. I clicked it, and while the browser waited for permission, I typed my San Francisco address. Then the GPS answer arrived and replaced my address with my current location in Florida, so all the suggestions were for Florida. Fix: a counter that makes the last user action win and ignores late async results.
  • The agent asked for things that were already on screen. It didn't know what I typed. Fix: a contextual update when the call starts, and another one each time the user edits the form.
  • "UDR" became "You do you are". Short brand names are hard for speech recognition. Fix: a keyword list for the recognizer, plus a rule to ask once for spelling and then move on.
  • A park appeared as a "merchant". Fix: filter Google place types like park and neighborhood.
  • Next.js 16 build error. With Cache Components on, reading the session outside <Suspense> breaks the build. Fix: a static shell plus the user part inside <Suspense>.
  • Vendor settings. My ElevenLabs key needed the Speech to Text permission, and its credit limit was set to 1. Also, the zero-retention flag only works on Enterprise plans. Fix: a pnpm check:elevenlabs health check that prints one clear line for each problem.

Lessons learned

  • Measure the bill first. My guess was "reduce tokens", but the data said "reduce minutes".
  • Use voice where it is better than typing. Open questions, yes. Phone numbers, no.
  • Keep the agent's world small. One tool, five topics, hard limits.
  • Use workflows when the steps are known. They are cheaper, easier to log and easier to test than an agent.
  • Mark what the model inferred. An unverified tag is better than a wrong fact that looks true.

Try it yourself

The repository has a full step-by-step setup guide, a testing guide, architecture diagrams and an experiment report.

git clone https://github.com/gusanchefullstack/voice-profile-onboarding.git
cd voice-profile-onboarding && pnpm install
cp .env.example .env.local   # add your keys
pnpm db:push && pnpm setup:agent && pnpm check:elevenlabs
pnpm dev

The next step is to run the A/B test with real users and compare the single voice note against the guided conversation. I'm curious which one wins. ๐Ÿค”

If you are building with voice agents, I would love to know: what is your cost per conversation, and what reduced it the most? Leave a comment! ๐Ÿ‘‡


I built this project with help from Claude Code, and I used AI to help me edit this post.


Sumber artikel open-source oleh Gustavo Sanchez di DEV Community โ€” Baca artikel asli. Topik: #ai #nextjs #tutorial #webdev

Sukai & bagikan artikel ini

Komentar