Skip to content

Structured Output

Structured output is a feature that allows you to generate structured data in JSON format with a JSON schema. This is more strict than JSON mode and is supported by gpt-4o-mini, gpt-4o-2024-08-06 and later models.

To enable this mode, set responseType to json_schema.

script({
responseType: "json_schema",
responseSchema: {
type: "object",
properties: {
name: { type: "string" },
age: { type: "number" },
},
required: ["name", "age"],
},
})

Note that there are several restrictions on the schema features supported by this mode.

  • additionalProperties: true is not supported.
  • all optional fields (e.g. not in required) will be returned and might be null