Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zodResponseFormat not working with OpenAI Responses interface

Tags:

openai-api

zod

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?

like image 500
Major Major Avatar asked Oct 16 '25 16:10

Major Major


1 Answers

OpenAI added a new helper function zodTextFormat but hasn't updated their docs yet on how to use it with responses.

  1. import the new helper -

    import { zodTextFormat } from "openai/helpers/zod";
    
  2. 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"),
          },
        });
    
like image 130
Major Major Avatar answered Oct 18 '25 17:10

Major Major



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!