Support for zod 4
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
Upgrade zod-to-json-schema for Zod v4 Compatibility
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
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.
javascriptopenai/helpers/zod/zod-to-json-schema.js - 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.
bashpnpm add @asteasolutions/zod-to-openapi - 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.
typescriptimport { zodResponseFormat } from '@asteasolutions/zod-to-openapi'; - 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.
bashpnpm 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
Upgrade zod-to-json-schema for Zod v4 Compatibility
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
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.
bashcd node_modules/openai/helpers/zod && ls - 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.
bashpnpm remove openai && pnpm add openai@5.8.3 @asteasolutions/zod-to-openapi - 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.
typescriptimport { zodResponseFormat } from '@asteasolutions/zod-to-openapi'; - 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.
bashpnpm 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
Alex Chen
2450 rep