Invalid schema in structured outputs when using built in tool batch api

I’m using a class of

class Food(BaseModel):
    food: Optional[str] = None
    amount: Optional[str] = None
    list_of_stores: Optional[List[int]] = None

class Recipe(BaseModel):
        list_of_foods: Optional[List[Food]] = None

and i pass it to the function
type_to_response_format_param

to format the json for my batch api jsonl request. which ends up being

{'type': 'json_schema', 'json_schema': {'schema': {'$defs': {'Food': {'properties': {'food': {'anyOf': [{'type': 'string'}, {'type': 'null'}], 'title': 'Food'}, 'amount': {'anyOf': [{'type': 'string'}, {'type': 'null'}], 'title': 'Amount'}, 'list_of_stores': {'anyOf': [{'items': {'type': 'integer'}, 'type': 'array'}, {'type': 'null'}], 'title': 'List Of Stores'}}, 'title': 'Food', 'type': 'object', 'additionalProperties': False, 'required': ['food', 'amount', 'list_of_stores']}}, 'properties': {'list_of_foods': {'anyOf': [{'items': {'$ref': '#/$defs/Food'}, 'type': 'array'}, {'type': 'null'}], 'title': 'List Of Foods'}}, 'title': 'Recipe', 'type': 'object', 'additionalProperties': False, 'required': ['list_of_foods']}, 'name': 'Recipe', 'strict': True}}

yet i continually run into this response error.

{"response": {"status_code": 400, "request_id": "9ab29cc692da4f48ce8a487235631664", "body": {"error": {"message": "Invalid schema for response_format 'Recipe': None is not of type 'object', 'boolean'.", "type": "invalid_request_error", "param": "response_format", "code": null}}}, "error": null}

Have you tried pasting this in the playground for json_schema format → generate? (that tool basically uses your input to generate a valid schema). Here is what I gave me back for your schema:

{
  "name": "Recipe",
  "schema": {
    "type": "object",
    "properties": {
      "list_of_foods": {
        "anyOf": [
          {
            "type": "array",
            "items": {
              "$ref": "#/$defs/Food"
            }
          },
          {
            "type": "null"
          }
        ],
        "description": "List of food items for the recipe."
      }
    },
    "required": [
      "list_of_foods"
    ],
    "additionalProperties": false,
    "$defs": {
      "Food": {
        "type": "object",
        "properties": {
          "food": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "description": "The name of the food item."
          },
          "amount": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "description": "The amount of the food item."
          },
          "list_of_stores": {
            "anyOf": [
              {
                "type": "array",
                "items": {
                  "type": "integer"
                }
              },
              {
                "type": "null"
              }
            ],
            "description": "List of stores where the food item can be found."
          }
        },
        "required": [
          "food",
          "amount",
          "list_of_stores"
        ],
        "additionalProperties": false
      }
    }
  },
  "strict": true
}

you can also check the code to see the full request details to use in your app. That tool saves me a lot of pain with schemas: https://platform.openai.com/playground/prompts?models=gpt-4o

just tested the schema in playground to make an old fashioned bread with olives:

{
  "list_of_foods": [
    {
      "food": "all-purpose flour",
      "amount": "3 1/2 cups",
      "list_of_stores": null
    },
    {
      "food": "active dry yeast",
      "amount": "2 teaspoons",
      "list_of_stores": null
    },
    {
      "food": "warm water",
      "amount": "1 1/2 cups",
      "list_of_stores": null
    },
    {
      "food": "salt",
      "amount": "1 1/2 teaspoons",
      "list_of_stores": null
    },
    {
      "food": "olive oil",
      "amount": "1 tablespoon",
      "list_of_stores": null
    },
    {
      "food": "black or green olives",
      "amount": "1 cup",
      "list_of_stores": null
    },
    {
      "food": "sugar",
      "amount": "1 teaspoon",
      "list_of_stores": null
    }
  ]
}

So when i utilize this with a batch endpoint after making a jsonl i get this error now

{"message": "Missing required parameter: 'response_format.json_schema.schema'.", "type": "invalid_request_error", "param": "response_format.json_schema.schema", "code": "missing_required_parameter"}}}, "error": null}

it seems the batch api doesnt accept the same style inputs. like properties is denied.

Please read the documentation, and error messages trying to understand what those say. If never used JSON before, please try to learn at least basics to be able to understand the structures.

Here it says that the structure is wrong (you copy-pasted my snippet as is without realizing it should go into the missing field the API is complaining about).

Ask GPT for code formatting assistance (give it docs as well).