feat(helpers/zod): add zodRealtimeFunction for Realtime API tool definitions#1864
Open
xodn348 wants to merge 1 commit intoopenai:masterfrom
Open
feat(helpers/zod): add zodRealtimeFunction for Realtime API tool definitions#1864xodn348 wants to merge 1 commit intoopenai:masterfrom
xodn348 wants to merge 1 commit intoopenai:masterfrom
Conversation
…nitions zodResponsesFunction sets strict: true, which the Realtime API's RealtimeFunctionTool interface does not support. zodRealtimeFunction is a parallel helper that converts a Zod schema to a RealtimeFunctionTool without the strict field, letting callers define Realtime API function tools with the same convenience as zodResponsesFunction. Closes openai#1809
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Realtime API's
RealtimeFunctionToolinterface does not include astrictfield, unlike the Responses API's function tool type. As a result,zodResponsesFunctioncannot be used to build Realtime API tool definitions — it emitsstrict: true, which is an unrecognized field for that API endpoint and silently breaks schema validation.This PR adds
zodRealtimeFunction, a new exported helper insrc/helpers/zod.tsthat mirrorszodResponsesFunctionbut targetsRealtimeFunctionTool. It converts a Zod v3 or v4 schema into the correct tool shape (withtype,name,parameters, and an optionaldescription) and omitsstrict. Callers pass the Zod object for type safety during tool definition; they parse the arguments themselves when the model calls the tool (e.g.,MyParams.parse(JSON.parse(event.arguments))).Issue
Fixes #1809
Local verification
Installed deps with
yarn install --frozen-lockfile --ignore-scripts(skipping the git-swap postinstall), ran typecheck and the targeted test suite:Risk
The change is additive — no existing function is modified.
zodRealtimeFunctionis a new export insrc/helpers/zod.ts, which the generator is documented to never overwrite. Tests for existing helpers pass unchanged.