Skip to content

OpenRouter structured handler should use json_schema and preserve structured_outputs #1019

Description

@mistermantas

Hi, I think the OpenRouter structured-output handler may be sending the wrong request shape.

OpenRouter’s structured output docs show strict schema output using:

{
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "...",
      "strict": true,
      "schema": {}
    }
  },
  "structured_outputs": true
}

But Prism’s OpenRouter structured handler appears to send the schema under response_format while using type: "json_object".

That means OpenRouter treats it as normal JSON mode, not strict schema-constrained output. Some models still behave okay, but others return empty content, unstructured content, or schema-shaped but unreliable output.

Suggested fix:

'response_format' => [
    'type' => 'json_schema',
    'json_schema' => [
        'name' => $request->schema()->name(),
        'strict' => true,
        'schema' => $request->schema()->toArray(),
    ],
],
'structured_outputs' => $request->providerOptions('structured_outputs') ?? true,

It may also be worth documenting that callers can pass:

'provider' => [
    'require_parameters' => true,
],

for OpenRouter so it does not route the request to an endpoint that ignores unsupported structured-output parameters.

Relevant OpenRouter docs:

This seems separate from plain JSON mode. response_format carries the schema, while structured_outputs is a separate supported parameter/capability flag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions