If trying to use zodResponseFormat
to setup structured outputs (as you did with other OpenAI interfaces) you may get an error that says No overload matches this call.
How can you use zod with structured outputs and the new openai.responses.create
interface?
OpenAI added a new helper function zodTextFormat
but hasn't updated their docs yet on how to use it with responses.
import the new helper -
import { zodTextFormat } from "openai/helpers/zod";
Use it in this new format -
const response = await openai.responses.create({
model: "gpt-4o",
input: [
{
role: "system",
content: systemPrompt,
},
{
role: "user",
content: [
{
type: "input_text",
text: userPrompt,
},
],
},
],
text: {
format: zodTextFormat(YourZodSchema, "zod_schema"),
},
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With