I’m trying to set up structured outputs using Zod schemas with the OpenAI API, but I keep running into issues with the openai.responses.create
method. When I attempt to use zodResponseFormat
like I would with other OpenAI endpoints, I get a TypeScript error saying there’s no matching overload for my function call.
Has anyone successfully integrated Zod validation with the newer OpenAI responses interface? I’m looking for the correct way to configure structured outputs using Zod schemas with this specific API endpoint.
Any examples or guidance on the proper syntax would be really helpful since the standard approach doesn’t seem to work here.
I hit this same issue recently. The OpenAI SDK changed a lot - responses.create
doesn’t exist anymore. You’re probably looking at old docs or examples. For structured outputs with Zod, use chat.completions.create
and pass your Zod schema through response_format
with zodResponseFormat(yourSchema, 'response_name')
. Make sure you’ve got the latest SDK version and your schema follows the JSON Schema constraints they support. Structured outputs is pretty new so there’s tons of outdated info out there.
That TypeScript error is happening because you’re using the wrong method. openai.responses.create
doesn’t exist for structured outputs with Zod schemas. You want openai.chat.completions.create
with the response_format
parameter instead. I ran into this same issue last month when I was migrating to structured outputs. You need to wrap your Zod schema with zodResponseFormat(yourSchema, 'schemaName')
and pass that to the response_format field. Also check your OpenAI SDK version - if it’s below 4.28.0, structured outputs won’t work. The docs are pretty confusing on this since it’s a newer feature and most examples online still use the old methods.
you might be confused with the methods. responses.create
isn’t for zodResponseFormat - that’s for chat completions only. try chat.completions.create
with the response_format option to get structured outputs with zod schemas. hope this helps!