Skip to main content

Use Cases

The Structured Outputs feature enables models to generate responses that conform to a JSON Schema you provide, making generated results more controllable and easy to parse. This feature facilitates downstream parsing and processing, and is beneficial for integrating results into business systems, suitable for various automation and data processing scenarios.

Supported Models

The following models support Structured Outputs:

Usage

Add the following to your request:
  • Set parameters: Specify your defined JSON Schema via the response_format parameter.
  • Prompt guidance: Guide the model to produce structured output in the prompt.

Examples

The following provides a complete Python code example demonstrating how to use the Structured Outputs feature to generate JSON responses conforming to your provided JSON Schema.

1. Initialize the Client

You need to initialize the client with your Myrouter API key.

2. Define the JSON Schema

You need to define a JSON Schema. The following example creates a JSON Schema for extracting expense information from user input.

3. Make the API Request

Create the API request. This request includes the response_format parameter, which specifies the JSON Schema defined in the previous step.
Output:

Complete Code