Docs menuinvideo Platform docsQuickstartFor AI agentsAPI referenceAuthenticationRequestsFilesErrorsLimitsBilling and balanceCatalogueProvider keys (BYOK)Formats and model IDsChat completionsOpenAI ResponsesAnthropic MessagesGeminiStreaming chat answersTools (function calling)Structured output (JSON)VideoAudioUse your own SDKOpenAI mediaElevenLabsReplicatefalGemini mediaxAIRunwayLumaDeepgram and CartesiaMakers' own APIsVideo provider formatsImage provider formatsAudio provider formatsLLM provider formatsGenerate and edit imagesTest your integrationWorkspaces and membersSecurityService accountsModels
View as markdown

Structured output (JSON)

Get a chat model's answer as JSON that matches your JSON Schema, with response_format json_schema or json_object.

Ask for JSON with response_format.

json_schema

The answer is one JSON object that matches your schema. It works on every model with tools (chat.capabilities.structured_output: true).

bash
curl https://platform-api.invideo.io/v1/chat/completions \
  -H "Authorization: Bearer $INVIDEO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-4-carbon",
    "messages": [{"role": "user", "content": "Three scene ideas for a 30 second ad for running shoes."}],
    "response_format": {
      "type": "json_schema",
      "json_schema": {
        "name": "scenes",
        "schema": {
          "type": "object",
          "properties": {
            "scenes": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {"title": {"type": "string"}, "seconds": {"type": "integer"}},
                "required": ["title", "seconds"]
              }
            }
          },
          "required": ["scenes"]
        }
      }
    }
  }'

choices[0].message.content is the JSON as a string:

json
{"scenes": [{"title": "Dawn run on the bridge", "seconds": 10}, {"title": "Close-up of the sole", "seconds": 8}, {"title": "Finish line", "seconds": 12}]}
python
from openai import OpenAI
import json, os

client = OpenAI(base_url="https://platform-api.invideo.io/v1", api_key=os.environ["INVIDEO_API_KEY"])

messages = [{"role": "user", "content": "Three scene ideas for a 30 second ad for running shoes."}]
response_format = {
    "type": "json_schema",
    "json_schema": {
        "name": "scenes",
        "schema": {
            "type": "object",
            "properties": {
                "scenes": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {"title": {"type": "string"}, "seconds": {"type": "integer"}},
                        "required": ["title", "seconds"],
                    },
                }
            },
            "required": ["scenes"],
        },
    },
}

answer = client.chat.completions.create(model="gemini-4-carbon", messages=messages, response_format=response_format)
scenes = json.loads(answer.choices[0].message.content)["scenes"]
print(json.dumps(scenes, indent=2))

With stream: true the JSON arrives in delta.content pieces; parse it once the stream ends.

json_schema cannot be sent with tools in the same request: use one of them.

json_object

{"type": "json_object"} asks the model for one JSON object with no schema. Say in your messages what the object holds. Parse it, and check it, in your code.