-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Labels
Description
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