#Getting Usage Accounting via Vercel AI SDK provider

1 messages · Page 1 of 1 (latest)

copper pasture
#

Hi — I am using Vercel AI SDK in my app, and the OpenRouter provider (https://github.com/OpenRouterTeam/ai-sdk-provider/) to actually access the models. I want to enable OR's usage accounting feature (https://openrouter.ai/docs/use-cases/usage-accounting) to get cost at the end of the stream, but I can't figure out how to do so. I've tried putting an extraBody in the createOpenRouter call:

  apiKey: process.env.OPENROUTER_API_KEY,
  extraBody: { usage: { include: true } },
})```

as well as passing providerOptions to openrouter in the streamText call:

``` const result = streamText({
    model: openrouter.chat('openai/gpt-4o'),
    messages: [{ role: 'user', content: 'hello' }],
    providerOptions: {
      openrouter: { usage: { include: true } },
    },
  })

but neither of these seem to work. I get back the basic accounting ( { promptTokens: 1786, completionTokens: 6, totalTokens: 1792 },) but not the fuller one with cost etc.

Would welcome any ideas! Thank you.

copper pasture