Skip to content

groq provider object generation needs review #7303

@shaper

Description

@shaper

Description

The below example fails with the noted error. Similarly, attempting to stream object generation e.g. with the tests in the examples/ai-core/src/e2e/groq.test.ts suite reports errors for all of them across several groq models.

I am not sure whether groq endpoints/models support structured outputs but it feels worth checking.

import { groq } from '@ai-sdk/groq';
import { generateObject } from 'ai';
import 'dotenv/config';
import { z } from 'zod/v4';

async function main() {
  const result = await generateObject({
    // model: groq('deepseek-r1-distill-llama-70b'), // "'messages' must contain the word 'json' in some form, to use 'response_format' of type 'json_object'."
    model: groq('moonshotai/kimi-k2-instruct'), // same as above
    schema: z.object({
      recipe: z.object({
        name: z.string(),
        ingredients: z.array(
          z.object({
            name: z.string(),
            amount: z.string(),
          }),
        ),
        steps: z.array(z.string()),
      }),
    }),
    prompt: 'Generate a lasagna recipe.',
  });

  console.log(JSON.stringify(result.object.recipe, null, 2));
  console.log();
  console.log('Token usage:', result.usage);
  console.log('Finish reason:', result.finishReason);
}

main().catch(console.error);

AI SDK Version

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy