Skip to content

feat(helpers): add zod realtime function helper#1996

Open
HAYDEN-OAI wants to merge 2 commits into
mainfrom
dev/hayden/issue-1809-zod-realtime-function
Open

feat(helpers): add zod realtime function helper#1996
HAYDEN-OAI wants to merge 2 commits into
mainfrom
dev/hayden/issue-1809-zod-realtime-function

Conversation

@HAYDEN-OAI

Copy link
Copy Markdown
Contributor

Summary

  • add zodRealtimeFunction() to openai/helpers/zod
  • generate Realtime function tool definitions from Zod v3, Zod v4, and Zod v4 mini schemas
  • omit strict, which is not part of the Realtime RealtimeFunctionTool shape
  • add focused coverage for the generated schema and wire format

Motivation

Fixes #1809.

zodResponsesFunction() is close to what Realtime callers need, but it always emits strict: true. Realtime function tools use the flat { type, name, description?, parameters } shape and do not support that field, so raw Realtime users currently have to convert Zod schemas by hand.

Behavior

The new helper returns a regular Realtime function tool definition with type, name, optional description, and JSON Schema parameters. It reuses the existing Zod conversion path so behavior stays consistent across the helper family, including current Zod v3, v4, and v4 mini support.

The helper is intentionally definition-only. It does not attach callback or parser metadata because the raw Realtime client does not have a runTools()-style consumer; callers still parse function-call arguments with their original Zod schema.

Validation

  • pnpm exec jest tests/helpers/zod.test.ts --runInBand
  • pnpm exec prettier --check src/helpers/zod.ts tests/helpers/zod.test.ts
  • git diff --check
  • pnpm run lint

@HAYDEN-OAI
HAYDEN-OAI marked this pull request as ready for review July 13, 2026 23:08
@HAYDEN-OAI
HAYDEN-OAI requested a review from a team as a code owner July 13, 2026 23:08
@openai-sdks

openai-sdks Bot commented Jul 13, 2026

Copy link
Copy Markdown

OkTest Summary

Failed for Node SDK PR #1996.

View OkTest run #29368639461

SDK merge (9f58df6ccd15) · head (c47069f89f26) · base (1cdc0196b434) · OkTest (cb7f0514ccd2)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 15c277ef73

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/helpers/zod.ts Outdated
Comment on lines +257 to +260
parameters:
isZodV4(zodSchema) ?
zodV4ToJsonSchema(zodSchema)
: zodV3ToJsonSchema(zodSchema, { name: options.name }),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor optional fields in Realtime schemas

When a Realtime tool has a normal optional parameter such as z.object({ limit: z.number().optional() }), this new helper still routes through the strict structured-output converters. Those converters reject .optional() without .nullable() and force nullable/defaulted fields into required, even though Realtime function tools only expose normal JSON Schema parameters and this helper intentionally omits the unsupported strict flag. As a result, valid non-strict Realtime function definitions cannot be produced, or are over-constrained, by the new helper.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zod helpder for RealtimeFunctionTool

1 participant