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

# Structured output

> Ask writer-0.1 for JSON with response_format on Chat Completions or text.format on the Responses API, with or without a JSON Schema, and parse it safely.

To get JSON back, set a format. `json_object` asks for any JSON object; `json_schema` asks for JSON that follows your schema. A `json_schema` format needs a `name` of 1 to 64 letters, digits, `_` or `-`, and a `schema` object; `strict` and `description` are optional.

## Chat Completions

```ts theme={"system"}
const completion = await client.chat.completions.create({
  model: "writer-0.1",
  messages: [
    {
      role: "user",
      content: "Write a title and a two-sentence summary for this release: search is 3x faster.",
    },
  ],
  response_format: {
    type: "json_schema",
    json_schema: {
      name: "release_summary",
      strict: true,
      schema: {
        type: "object",
        properties: { title: { type: "string" }, summary: { type: "string" } },
        required: ["title", "summary"],
        additionalProperties: false,
      },
    },
  },
});

const summary = JSON.parse(completion.choices[0].message.content ?? "");
```

## Responses API

The same format goes in `text.format`, without the `json_schema` wrapper:

```ts theme={"system"}
const response = await client.responses.create({
  model: "writer-0.1",
  input: "Write a title and a two-sentence summary for this release: search is 3x faster.",
  text: {
    format: {
      type: "json_schema",
      name: "release_summary",
      strict: true,
      schema: {
        type: "object",
        properties: { title: { type: "string" }, summary: { type: "string" } },
        required: ["title", "summary"],
        additionalProperties: false,
      },
    },
  },
});

const summary = JSON.parse(response.output_text);
```

## Parse safely

* Check `finish_reason` (Responses: `status`) first. An answer that ended because of the output limit (`length`, or `incomplete`) isn't complete JSON. Raise the limit or leave it unset.
* The plan still comes first and counts toward the output limit; only the answer is JSON.
* Validate the parsed object against your schema before you use it.


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