Speakeasy Logo
Skip to Content

Product Updates

TypeScript SDKs now with Zod v4 Mini

David Adler

David Adler

November 11, 2025 - 4 min read

Product Updates

Today we’re releasing support for Zod v4 mini in all Speakeasy-generated TypeScript SDKs. This update brings bundle size reductions of ~10% while maintaining the runtime type safety that makes our SDKs reliable.

Why Zod matters

When we rebuilt our TypeScript generator, Zod was a critical piece of the puzzle. It solved a fundamental problem: TypeScript has no runtime type safety. Types exist only at compile time, disappearing entirely when your code runs.

This creates real issues when working with APIs. Without runtime validation, there’s no guarantee that:

  • The data you send matches your API’s requirements
  • The responses you receive match your expectations
  • Type mismatches get caught before they cause bugs

Zod gives us runtime type safety by validating API responses before your code uses them:

import { SDK } from "@speakeasy/ecommerce-sdk"; async function run() { const sdk = new SDK(); const products = await sdk.products.list(); // Without Zod validation: // ❌ Runtime error: "Cannot read properties of undefined (reading 'amount')" console.log(product.price.amount); } // With Zod validation, fails fast with a clear error: // ZodError: Required at path: ["product", "price"]

This catches API contract mismatches immediately with clear errors, rather than letting your code crash when it tries to access properties that don’t exist.

Every improvement counts

We’re always asking ourselves: can we make our SDKs better? When Zod v4 was released, we saw an opportunity to improve bundle efficiency.

Zod v3 has served us well. In a typical SDK, it accounts for around 15% of the bundle size—about 20KB minified and gzipped. For many applications, this is a reasonable tradeoff for runtime type safety. But with Zod v4 mini offering better tree-shaking through its standalone function API, we could reduce that footprint even further without compromising on validation.

Enter Zod v4 mini

Zod v4 introduced a new variant called “mini” that fundamentally changes how validation works. Instead of method chaining, it uses standalone functions:

// Zod v3/v4 (method chaining) const schema = z.string().optional().nullable(); // Zod v4 mini (standalone functions) const schema = z.nullable(z.optional(z.string()));

This might look like a cosmetic change, but it enables better tree-shaking. Standalone functions are module-level exports that bundlers can analyze and eliminate when unused. A class-based API, by contrast, pulls in the entire class structure regardless of which methods you actually call.

Zod v4 mini clocks in at around 10KB minified and gzipped—about half the size of Zod v3’s 20KB.

Beyond bundle size, Zod v4 delivers significant performance improvements:

  • String parsing is 14.7x faster
  • Array parsing is 7.4x faster
  • Object parsing is 6.5x faster

How this impacts Speakeasy SDKs

These library changes are entirely internal to our generated SDKs. Your SDK users don’t need to change anything—they continue using the same class-based interface they’re familiar with:

import { Dub } from "dub"; const dub = new Dub({ token: process.env.DUB_API_KEY }); const result = await dub.links.create({ url: "https://example.com", domain: "dub.sh", });

Under the hood, we’ve migrated all validation logic to use Zod v4 mini’s standalone functions. Here’s what we’re seeing in real-world SDKs:

SDK
Minimal with 1 method Zod v4-mini
Bundled
79.44 KB
Bundled & Minified
31.26 KB
Bundled & Minified & GZIP
9.95 KB
Minimal with 1 method Zod v4
Bundled
156.90 KB
Bundled & Minified
63.76 KB
Bundled & Minified & GZIP
17.69 KB
Minimal with 1 method Zod v3
Bundled
181.74 KB
Bundled & Minified
72.01 KB
Bundled & Minified & GZIP
18.17 KB
@polar-sh/sdk Zod v4-mini
Bundled
1.25 MB
Bundled & Minified
542.09 KB
Bundled & Minified & GZIP
55.22 KB
@polar-sh/sdk Zod v3
Bundled
1.37 MB
Bundled & Minified
598.28 KB
Bundled & Minified & GZIP
61.51 KB
@mistralai/mistralai Zod v3
Bundled
582.72 KB
Bundled & Minified
234.36 KB
Bundled & Minified & GZIP
34.60 KB
@mistralai/mistralai Zod v4-mini
Bundled
488.50 KB
Bundled & Minified
191.61 KB
Bundled & Minified & GZIP
28.66 KB

Your SDK users automatically benefit from:

  • Smaller bundle sizes when building frontend applications (typically ~10% reduction)
  • Better tree-shaking that only includes validation for the SDK methods they actually use
  • Faster validation at runtime

We’ve also maintained backward compatibility. Thanks to the forward thinking zod team  our SDKs work regardless of whether v3 or v4 is installed in your project.

Getting started

Zod v4 mini support is opt-in via your gen.yaml configuration file. Add the zodVersion flag to your TypeScript generation settings:

typescript: version: 1.0.0 zodVersion: v4-mini

Then regenerate your SDK:

speakeasy run

Looking forward

Zod v4 mini is part of our broader commitment to building TypeScript SDKs that work everywhere: from Node.js servers, to browser frontends to edge functions. Every improvement matters, especially in bundle-sensitive environments like edge functions and mobile applications.

If you’re generating TypeScript SDKs with Speakeasy, we encourage you to try Zod v4 mini. The migration is straightforward, and you’ll benefit from smaller bundles and faster validation.

Last updated on

Organize your
dev universe,

faster and easier.

Try Speakeasy Now