Tools & JSON

Function calling and structured outputs follow the OpenAI format. Requests with tools to a model that cannot call tools fail fast with 400 unsupported_parameter.

response = client.chat.completions.create(
    model="grok-4.7",
    messages=[{"role": "user", "content": "Extract: Ada Lovelace, born 1815"}],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "person",
            "strict": True,
            "schema": {
                "type": "object",
                "properties": {"name": {"type": "string"}, "born": {"type": "integer"}},
                "required": ["name", "born"],
                "additionalProperties": False,
            },
        },
    },
)