Skip to content

Support for JSON schema / structured output #150

@anudit

Description

@anudit

Thanks for the awesome work, the API works great 👏🏻

Is is possible to get structured outputs to work?

The following fails schema validation.

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

const provider = createOpenAICompatible({
  name: "geminiLocal",
  apiKey: "",
  baseURL: 'http://0.0.0.0:8787/v1/,
  includeUsage: true,
});

async function main() {

  const batchSchema = z.object({
    capital: z.string()
  });

  const { object, usage } = await generateObject({
    model: provider('gemini-2.5-pro'),
    schema: batchSchema,
    prompt:"what is the capital of france? return answer according to JSON schema.",
  });
  console.log('object', object);

}

main();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions