json_schema is not supported
I'm trying to use this provider with models that offer structured output through json_schema.
But with generateObject, it ALWAYS uses json_object, instead of json_schema.
{
"model": "(any model)",
"temperature": 0,
"response_format": {
"type": "json_object"
},
"messages": [
{
"role": "system",
"content": "JSON schema:\n{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"}},\"required\":[\"name\"],\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\nYou MUST answer with a JSON object that matches the JSON schema above."
},
{
"role": "user",
"content": "Hello, what's your name?"
}
]
}
i managed to use structed output with extrabody on the creaateOpenRouter function and passing the reponse_format as indicated on openrouter api. I have setupped mine in this way;
const openrouter = createOpenRouter({
apiKey: "your-api-key",
extraBody: {
"X-Title": "Translator", // This is only to recognise this application on openrouter activity view
response_format: {
type: 'json_schema',
json_schema: {
name: 'translated',
strict: true,
schema: {
type: 'array',
items: {
type: 'string',
description: 'Translated paragraph'
}
},
}
}
}
})```
did you use generateObject or generateText with this?
I had some issues with structured output as well, but at least for some models, like Mistral small 3.2, what worked for me was to add mode: json:
streamObject({
mode: "json",
...
});
Apparently, the default mode, always caused some issues for me. I think it should work for generateObject as well.
we added support for this in https://github.com/theopenco/llmgateway-ai-sdk-provider via https://github.com/theopenco/llmgateway-ai-sdk-provider/pull/7