Skip to content

Support for zod 4Β #1576

@kenn

Description

@kenn

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

Describe the bug

Hey OpenAI team πŸ‘‹

After updating to Zod v4 I’m hitting this runtime error:

✘ [ERROR] No matching export in "node_modules/.pnpm/[email protected]/node_modules/zod/index.js" for import "ZodFirstPartyTypeKind"

    node_modules/.pnpm/openai@5.8.3_ws@8.18.3_zod@4.0.2/node_modules/openai/_vendor/zod-to-json-schema/parsers/array.mjs:1:9:
      1 β”‚ import { ZodFirstPartyTypeKind } from 'zod';
        β•΅          ~~~~~~~~~~~~~~~~~~~~~

Looks like the vendored zod-to-json-schema in openai/helpers/zod still expects the ZodFirstPartyTypeKind export, which was removed in Zod v4.

Notes / ideas

  • Pinning zod@3 is a temporary workaround, but it blocks upgrading the whole stack.
  • A quick fix might be bumping the vendored zod-to-json-schema to a version that supports Zod v4 or swapping it out for the maintained @asteasolutions/zod-to-openapi which already handles the new internals.

Thanks for taking a look! Let me know if I can help with more info or a PR.

To Reproduce

  1. Fresh project with pnpm
  2. pnpm add [email protected] zod@^4
  3. Add a simple script: import { zodResponseFormat } from 'openai/helpers/zod'
  4. pnpm tsx index.ts (or just bundle with esbuild) β†’ error above.

Code snippets

OS

macOS

Node version

Node v22

Library version

Latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions