AI Development

Building with the Vercel AI SDK: A Production Playbook

Streaming a chat demo is easy. Streaming one that survives a flaky provider, a rate limit and a user closing the tab mid-response is a different problem. Here's the pattern we ship in every AI SDK integration now.

KAKabir AnandLead Developer
11 min read
3D rendered AI lettering over a blue wireframe network pattern

The Vercel AI SDK made streaming a chat response a five-line demo. What it doesn't show you on the landing page is everything a production integration actually needs: provider fallback, tool-call error handling, and a UI that doesn't break when a user closes the tab mid-stream.

Start with the unified provider interface

The SDK's biggest production win isn't streaming — it's the provider abstraction. Swapping between OpenAI, Anthropic and a local model becomes a config change, not a rewrite, which matters the first time your primary provider has an outage during a demo.

lib/ai/model.ts
1import { anthropic } from "@ai-sdk/anthropic";
2import { openai } from "@ai-sdk/openai";
3 
4export function getModel(fallback = false) {
5  return fallback
6    ? openai("gpt-4.1")
7    : anthropic("claude-sonnet-5");
8}

Design the failure states before the happy path

The request path we actually build

User sends messagestreamText() call
Primary providerFirst attempt, streamed
On error / timeoutRetry once, then fall back
Fallback providerDifferent vendor, same interface
Stream to clientPartial output preserved either way
  • A dropped connection mid-stream shouldn't lose what already rendered — persist partial output as it arrives, not only on completion.
  • A tool call that throws shouldn't crash the whole response — catch it, return a structured error the model can react to, and keep streaming.
  • A rate limit from your primary provider should trigger an automatic, logged fallback — not a raw 429 surfaced to the user.
The mistake we see most

Teams wire up streamText() and ship the happy path, then discover in production that a single provider timeout takes down every conversation in flight. Build the retry/fallback path in the first PR, not the incident postmortem.

Tool calls need the same review as an API endpoint

Every tool you expose to the model is effectively a new API endpoint the model can call unsupervised. We review tool definitions with the same rigor as a public route — input validation, scoped permissions, and a hard cap on anything that costs money or sends an irreversible action.

lib/ai/tools/refundOrder.ts
1export const refundOrder = tool({
2  description: "Refund an order — requires human approval",
3  parameters: orderRefundSchema,
4  // never executes automatically — queues for a human to confirm
5  execute: async (input) => queueForApproval("refund", input),
6});

2

providers wired behind every production AI feature we ship

0

irreversible tool calls we let execute without human approval

~4s

acceptable stream latency budget before we investigate the provider

A chatbot demo has one provider and no error states. A chatbot product has a fallback, a retry budget, and a plan for the tool call that fails at 2am.

Kabir Anand, Lead Developer

Key Takeaways

  • Treat the provider abstraction as the SDK's main production value, not just the streaming API — build the fallback path from day one.
  • Persist streamed output as it arrives so a dropped connection doesn't lose a response that already rendered most of the way.
  • Review every tool definition like a public API endpoint — validated input, scoped permissions, and no irreversible actions without human approval.
  • Log and alert on provider fallback triggers — a silent fallback hides a real outage you'll want to know about.

Bringing it together

The AI SDK genuinely removes a lot of boilerplate. What it doesn't remove is the responsibility to design for the request that doesn't go well — that part is still on the team shipping it, same as any other production system.

Keep Reading

More from the blog

The Engineering Partner You Can Build On

Reliable software takes an experienced team that owns delivery end to end. Here’s the track record behind ours.

11+

Years Building Custom Software

320+

Projects Delivered Across Web, Mobile & AI

85%

Repeat Client Rate

12+

Countries Served Worldwide

Trusted by startups and enterprises worldwide

Work With Us

Let’s create
with purpose

Share your goals, timeline, and challenges — we’ll respond with clarity and next steps.

Ambitious ideas deserve thoughtful execution. Start the conversation and let’s define what success looks like.

Team

Acetrum

Est. 2015

4.9/5

Trusted by
top brands

Services interested in:

By submitting, I confirm I’ve read and agree with Privacy and Cookie Policies.

Newsletter

Signals worth
paying attention

No recycled headlines — just the patterns we’re seeing across real client work, distilled into one read a month.

A curated digest of practical thinking and real-world brand perspectives monthly.

No spam. Unsubscribe anytime.