FG
๐Ÿค– AI & LLMsOpenAI

Support for zod 4

Freshabout 20 hours ago
Mar 14, 20260 views
Confidence Score95%
95%

Problem

Confirm this is a Node library issue and not an underlying OpenAI API issue - [x] 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: [code block] 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 1. pnpm add openai@5.8.3 zod@^4 1. Add a simple script: `import { zodResponseFormat } from 'openai/helpers/zod'` 1. pnpm tsx index.ts (or just bundle with esbuild) โ†’ error above. Code snippets [code block] OS macOS Node version Node v22 Library version Latest

Unverified for your environment

Select your OS to check compatibility.

2 Fixes

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Upgrade zod-to-json-schema for Zod v4 Compatibility

Medium Risk

The vendored `zod-to-json-schema` in the OpenAI Node library relies on the `ZodFirstPartyTypeKind` export, which was removed in Zod v4. This causes runtime errors when using Zod v4 with the current version of the OpenAI library.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Identify the vendored zod-to-json-schema

    Locate the vendored `zod-to-json-schema` within the OpenAI library. This is typically found in the `openai/helpers/zod` directory.

    javascript
    openai/helpers/zod/zod-to-json-schema.js
  2. 2

    Update zod-to-json-schema

    Replace the vendored `zod-to-json-schema` with a version that supports Zod v4. You can do this by installing `@asteasolutions/zod-to-openapi`, which is maintained and compatible with Zod v4.

    bash
    pnpm add @asteasolutions/zod-to-openapi
  3. 3

    Modify import statements

    Update your code to import from `@asteasolutions/zod-to-openapi` instead of the vendored version. Ensure that all references to the old import are replaced.

    typescript
    import { zodResponseFormat } from '@asteasolutions/zod-to-openapi';
  4. 4

    Test the integration

    Run your application to ensure that the integration with Zod v4 works without errors. This can be done by executing your main script again.

    bash
    pnpm tsx index.ts

Validation

Confirm that the application runs without the previous runtime error after making the changes. Additionally, ensure that all functionalities relying on Zod v4 operate as expected.

Sign in to verify this fix

1 low-confidence fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Upgrade zod-to-json-schema for Zod v4 Compatibility

Medium Risk

The error occurs because the vendored `zod-to-json-schema` in the OpenAI Node library relies on the `ZodFirstPartyTypeKind` export, which was removed in Zod v4. This incompatibility causes runtime errors when using the updated Zod version.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Identify the vendored dependency

    Locate the vendored `zod-to-json-schema` within the OpenAI Node library to understand its current version and compatibility with Zod v4.

    bash
    cd node_modules/openai/helpers/zod && ls
  2. 2

    Update zod-to-json-schema

    Replace the vendored `zod-to-json-schema` with the latest version that supports Zod v4. This can be done by modifying the OpenAI library to use `@asteasolutions/zod-to-openapi`, which is actively maintained and compatible with Zod v4.

    bash
    pnpm remove openai && pnpm add openai@5.8.3 @asteasolutions/zod-to-openapi
  3. 3

    Modify import statements

    Update your code to import from the new `@asteasolutions/zod-to-openapi` package instead of the vendored version to ensure compatibility with Zod v4.

    typescript
    import { zodResponseFormat } from '@asteasolutions/zod-to-openapi';
  4. 4

    Test the integration

    Run your application to verify that the integration with Zod v4 works correctly without any runtime errors. Ensure that all functionalities relying on Zod are functioning as expected.

    bash
    pnpm tsx index.ts

Validation

Confirm that the application runs without throwing the original runtime error related to `ZodFirstPartyTypeKind`. Additionally, ensure that all functionalities relying on Zod are functioning correctly.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

openaigptllmapienhancementsdk