11/**
22 * Idiomatic Vercel AI SDK example with OpenRouter provider
3- *
3+ *
44 * This example demonstrates key AI SDK concepts:
55 * - Creating and configuring the OpenRouter provider
66 * - Using generateText for non-streaming chat completions
@@ -146,7 +146,12 @@ async function usageAccounting() {
146146
147147 // OpenRouter-specific metadata with cost information
148148 if ( result . providerMetadata ?. openrouter ?. usage ) {
149- const usage = result . providerMetadata . openrouter . usage as any ;
149+ const usage = result . providerMetadata . openrouter . usage as {
150+ totalTokens ?: number ;
151+ promptTokens ?: number ;
152+ completionTokens ?: number ;
153+ cost ?: number ;
154+ } ;
150155 console . log ( '\nOpenRouter Usage Details:' ) ;
151156 console . log ( '- Total Tokens:' , usage . totalTokens ) ;
152157 console . log ( '- Prompt Tokens:' , usage . promptTokens ) ;
@@ -167,15 +172,17 @@ async function conversationExample() {
167172 // System messages set the behavior and context for the model
168173 const { text } = await generateText ( {
169174 model,
170- system : 'You are a helpful coding assistant specializing in TypeScript and modern web development.' ,
175+ system :
176+ 'You are a helpful coding assistant specializing in TypeScript and modern web development.' ,
171177 messages : [
172178 {
173179 role : 'user' ,
174180 content : 'How do I define a generic function in TypeScript?' ,
175181 } ,
176182 {
177183 role : 'assistant' ,
178- content : 'You define a generic function using angle brackets with a type parameter, like this: `function identity<T>(arg: T): T { return arg; }`' ,
184+ content :
185+ 'You define a generic function using angle brackets with a type parameter, like this: `function identity<T>(arg: T): T { return arg; }`' ,
179186 } ,
180187 {
181188 role : 'user' ,
0 commit comments