> ## Documentation Index
> Fetch the complete documentation index at: https://docs.radium.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Structured outputs

> Receive responses that conform to a JSON schema

# Structured outputs

Structured outputs guarantee that the model response conforms to a JSON schema you define. Use this for typed API responses, database records, configuration objects or any case where free text is not acceptable.

## JSON mode

Set `response_format: {type: "json_object"}` to receive valid JSON.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.radium.cloud/v1/chat/completions \\
    -H "Authorization: Bearer $RADIUM_API_KEY" \\
    -H "Content-Type: application/json" \\
    -d '{
      "model": "clarke-1.0",
      "messages": [{"role": "user", "content": "List two planets"}],
      "response_format": {"type": "json_object"}
    }'
  ```

  ```python Python theme={null}
  from openai import OpenAI
  client = OpenAI(api_key="YOUR_RADIUM_API_KEY", base_url="https://api.radium.cloud/v1")
  response = client.chat.completions.create(
      model="clarke-1.0",
      messages=[{"role": "user", "content": "List two planets"}],
      response_format={"type": "json_object"},
  )
  print(response.choices[0].message.content)
  ```

  ```typescript TypeScript theme={null}
  import OpenAI from "openai";
  const client = new OpenAI({ apiKey: process.env.RADIUM_API_KEY, baseURL: "https://api.radium.cloud/v1" });
  const response = await client.chat.completions.create({
    model: "clarke-1.0",
    messages: [{ role: "user", content: "List two planets" }],
    response_format: { type: "json_object" },
  });
  console.log(response.choices[0].message.content);
  ```
</CodeGroup>

## JSON schema

For stricter validation, supply a JSON schema using `json_schema` mode:

```python theme={null}
from openai import OpenAI
client = OpenAI(api_key="YOUR_RADIUM_API_KEY", base_url="https://api.radium.cloud/v1")

response = client.chat.completions.create(
    model="clarke-1.0",
    messages=[{"role": "user", "content": "List two planets with their diameters"}],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "planets",
            "schema": {
                "type": "object",
                "properties": {
                    "planets": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "name": {"type": "string"},
                                "diameter_km": {"type": "number"}
                            },
                            "required": ["name", "diameter_km"]
                        }
                    }
                },
                "required": ["planets"]
            }
        }
    },
)
print(response.choices[0].message.content)
```

## Anthropic format

Structured outputs work in the Messages API using the same `response_format` parameter.

## Limitations

Complex nested schemas with recursive references or union types may not be fully supported. Test your schema on a representative sample before deploying to production.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.