Skip to content

Structured Outputs don't work when using the @ai-sdk/openai-compatible package #8427

@michaelchiche

Description

@michaelchiche

Description

import "dotenv/config";
import { generateObject } from "ai";
import z from "zod";
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";

export const openrouteAiCompatible = createOpenAICompatible({
  baseURL: process.env.OPENROUTER_BASE_URL!,
  apiKey: process.env.OPENROUTER_API_KEY!,
  name: "openrouter",
});

(async () => {
  const result = await generateObject({
    model: openrouteAiCompatible("qwen/qwen3-4b:free"),
    schema: z.object({
      firstName: z.string(),
      lastName: z.string(),
    }),
    prompt: `My name is Murray Rothbard`,
  });

  console.log("result.", result.object);
})();

And this will always fail, the "structure output" parameter is never sent correctly

AI SDK Version

Packages:

  • "@ai-sdk/openai-compatible": "^1.0.14"
  • "@openrouter/ai-sdk-provider": "^1.1.2"
  • "@types/node": "^24.3.0"
  • "ai": "^5.0.30"
  • "dotenv": "^17.2.2"
  • "zod": "^4.1.5"

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions