Ensure responses adhere to a JSON schema.
https://api.inference.net/v1
.
In this example, we are reading the API key from the environment variable INFERENCE_API_KEY
.
response_format
Structured Outputs | JSON Mode | |
---|---|---|
Outputs valid JSON | Yes | Yes |
Adheres to schema | Yes (see supported schemas) | No |
Enabling | response_format: { type: "json_schema", json_schema: {"strict": true, "schema": ... } } | response_format: { type: "json_object" } |
parse
method to automatically parse the JSON response into the object you defined.
Under the hood, the SDK takes care of supplying the JSON schema corresponding to your data structure, and then parsing the response as an object.
stream
helper:
required
.
Also, additionalProperties
must be set to false
.
In the following example, note how both location
and unit
are listed as required properties.
response_format
to { "type": "json_object" }
.
Important notes: