You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{createOpenAI}from'@ai-sdk/openai';import{streamText}from'ai';importdotenvfrom'dotenv';dotenv.config();constgroq=createOpenAI({apiKey: process.env.GROQ_API_KEY??'',baseURL: 'https://api.groq.com/openai/v1',});asyncfunctionmain(){constresult=awaitstreamText({model: groq.chat('llama3-70b-8192'),prompt: 'Invent a new holiday and describe its traditions.',});forawait(consttextPartofresult.textStream){process.stdout.write(textPart);}console.log();console.log('Token usage:',awaitresult.usage);// This results in NaNconsole.log('Finish reason:',awaitresult.finishReason);}main().catch(console.error);
Additional context
No response
The text was updated successfully, but these errors were encountered:
Description
Seems like Groq models do not follow the OpenAI spec for usage. They return the
usage
object under ax-groq
key in the last chunk:Code example
Additional context
No response
The text was updated successfully, but these errors were encountered: