openai / openai-node

Official JavaScript / TypeScript library for the OpenAI API
https://www.npmjs.com/package/openai
Apache License 2.0
7.97k stars 869 forks source link

`zodResponseFormat` should require a zod object, and not any zod type #1092

Closed uriva closed 1 month ago

uriva commented 1 month ago

Confirm this is a feature request for the Node library and not the underlying OpenAI API.

Describe the feature or improvement you're requesting

it is easy to get it wrong by inputting z.boolean() which will later fail in ta cryptic http error

400 Invalid schema for response_format 'query': schema must be a JSON Schema of 'type: "object"', got 'type: "None"'.
RobertCraigie commented 1 month ago

Unfortunately we can't just accept a zod object because of recursive schemas, so I don't think it's feasible to change the type.

I agree this error message is not very helpful though, I've reported this back to the OpenAI API team.