Request structured JSON responses when you analyze video content. This feature returns predictable, machine-readable data that integrates directly into your applications.
Key features:
Use cases:
Use prompts and schemas together to control your responses:
The schema takes precedence over the prompt. If your prompt requests a summary but your schema defines chapters, the platform returns chapters. Always ensure your prompt and schema align to request the same type of information.
A schema defines:
string, number, or object).For complete specifications, see the JSON schema requirements section.
The examples in this section show different types of structured responses you can request.
This example generates a comprehensive video summary using a simple schema.
You can receive structured JSON responses in real-time as they are generated:
required property to specify fields that must be present. This ensures critical data is always included in responses.finish_reason field in your code. When it equals length, inspect the error field. Increase the maximum response length if your response needs more room, or reduce your input if the context window was reached.This section provides solutions to common issues you might encounter when working with structured JSON responses.
Problem: The response contains information different from what you requested in the prompt (for example, you asked for a summary but received chapters).
Cause: The schema takes precedence over the prompt. The platform generates content that matches the schema structure, regardless of what the prompt requests.
Solution: Ensure your prompt and schema align to request the same type of information.
Problem: The response contains truncated JSON or fails to parse.
Cause: The response reached the maximum response length or the context window before completing the JSON structure.
Solution: Check the finish_reason field. When it equals length, the platform returns a warning in the error field, and the truncated response is in data (sync) or result.data (async). Increase the maximum response length if your response needs more room, or reduce your input if the context window was reached.
Problem: You receive a BadRequestError with code response_format_invalid when making a request.
Cause: The schema contains unsupported constraints (such as minLength or maxLength) or invalid references (such as $ref pointing to non-existent definitions).
Solution: Review the json_schema field in the API Reference section for a list of the supported constraints. Ensure all $ref values point to definitions in $defs. Remove unsupported validation keywords and use only the supported data types and constraints.
Your schema must adhere to the JSON Schema Draft 2020-12 specification and must meet the requirements below:
array, boolean, integer, null, number, object, and string.pattern for strings, minimum and maximum for integers, required for objects, and minItems for arrays (accepts only 0 or 1).anyOf for combining schemas.$defs and reference them with valid $ref URIs pointing to internal subschemas.For complete schema specifications, see the json_schema field in the API Reference section.