Structured output

Every Phoenix Grove model supports JSON mode and function calling: the standard OpenAI mechanisms for getting machine-readable output.


JSON mode

Ask the model to return a single JSON object with response_format:

resp = client.chat.completions.create(
    model="glm-5.2",
    messages=[
        {"role": "system", "content": "Extract the fields as JSON."},
        {"role": "user", "content": "Ada Lovelace, born 1815 in London."},
    ],
    response_format={"type": "json_object"},
)

import json
data = json.loads(resp.choices[0].message.content)

When you use JSON mode, instruct the model (in the system or user message) to produce JSON and describe the shape you want. The response content will be a single valid JSON document.


Function calling / tools

Pass a tools array and let the model choose when to call one:

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get the current weather for a city.",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]

resp = client.chat.completions.create(
    model="kimi-k2.7",
    messages=[{"role": "user", "content": "What's the weather in Kyoto?"}],
    tools=tools,
)

call = resp.choices[0].message.tool_calls[0]
print(call.function.name, call.function.arguments)

Feed the tool result back as a role: "tool" message referencing the tool_call_id, exactly as you would with any OpenAI-compatible endpoint.

Parallel and streaming tool calls work the standard way: a model may return several tool_calls in one turn (run them and return each result), and tool calls stream as delta.tool_calls chunks when stream: true. Note that a model can't call another tool from inside a tool call — resolve each call and send the results back for the next turn. Tool and function definitions count as input tokens and are billed as part of your prompt.


A note on strict schemas

The models advertise JSON mode + function calling. Strict json_schema enforcement (guaranteed conformance to a supplied JSON Schema) varies by model and is not yet advertised as a guarantee. For now, validate the returned JSON on your side and retry on parse failure. We'll publish a per-model strict-schema badge once each model is verified.