Response_format set to JSON not accepted by openai.beta.threads.createAndRun

I set it to response_format: { type: “json_object” } yet I get the error: “Invalid value: ‘json_object’. Supported values are: ‘auto’.”. I also tried response_format: { “type”: “json_object” }, same error. I’m not using any tools. I’m also specifying to generate JSON in the message/ additional instructions.
Per the documentation, ‘auto’ is the default value, otherwise an object has to be specified:

POSSIBLE TYPES FROM DOC at https://platform.openai.com/docs/api-reference/runs/createThreadAndRun:
Setting to { "type": "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON.
auto is the default value

object: An object describing the expected output of the model. If json_object only function type tools are allowed to be passed to the Run. If text the model can return text or any value needed.

type: Must be one of text or json_object.

Share complete code or no one will be able to help you.

OK, found the issue. My fault. The issue was this line:
… runOptions

While as a catch-all I expected not to override runOptions.response_format , it did, and placed json_object directly in response_format overriding the previous line. Posting since I’ve taken this code from the other code samples, and to show how to call.

const createOAIAThreadRunAndStream = async (threadId, assistantId, runOptions = {}, userId) => {

const model = runOptions.model || 'gpt-3.5-turbo';

return new Promise((resolve, reject) => {
    try {

        const streamOptions = {
            assistant_id: assistantId,
            model: model || 'gpt-3.5-turbo', 
            instructions: runOptions.instructions || null, 
            additional_instructions: runOptions.additional_instructions || null, 
            tools: runOptions.tools || null,
            metadata: runOptions.metadata || null, 
            // response_format: "auto",
            response_format: runOptions.response_format ? { type: runOptions.response_format } : undefined, 
            // ...runOptions, // Ensures any additional, unspecified options provided by runOptions are included  -- Removed to fix issue
        };
1 Like