Skip to content
All posts

Ask for JSON that matches a schema

Chat completions accept response_format. The answer is a JSON string on message.content. Parse it. The root of the schema stays an object.

One field on the chat call

Send response_format.type json_schema on /v1/chat/completions. AnyRouter forwards that object. choices[0].message.content comes back as a JSON string. Parse it.

Keep the root an object. A non-object root is wrapped under a result key. strict is false, which is the body Interfaze publishes. strict: true on that hop came back as ordinary prose.

A model offers this when its page lists Structured output under Details. That row links to the guide. The row is there when a hop advertises response_format or structured_outputs. It is not on every model.

Related posts