Skip to content

feat: add cost field to providerMetadata usage - #40

Merged
requesty-JohnCosta27 merged 1 commit into
requestyai:backport/2.2.0-usagefrom
wladimiiir:feat/add-cost-to-usage-metadata
May 15, 2026
Merged

feat: add cost field to providerMetadata usage#40
requesty-JohnCosta27 merged 1 commit into
requestyai:backport/2.2.0-usagefrom
wladimiiir:feat/add-cost-to-usage-metadata

Conversation

@wladimiiir

Copy link
Copy Markdown
Contributor

Summary

Adds the cost field from response.usage.cost into providerMetadata.requesty.usage, alongside existing cachingTokens and cachedTokens.

Changes

  • src/types.ts — Added cost?: number to RequestyUsage type
  • src/requesty-chat-language-model.ts — Include cost from response.usage.cost in doGenerate providerMetadata; added cost to RequestyStreamChatCompletionChunkSchema usage Zod schema
  • src/stream/index.ts — Extract cost in handleUsageChunk; forward cost in createFlush providerMetadata

Usage

The cost is now available in providerMetadata.requesty.usage.cost for both doGenerate and streaming responses:

const result = await generateText({
  model: requesty('...'),
  prompt: '...',
})

const cost = result.providerMetadata?.requesty?.usage?.cost

@changeset-bot

changeset-bot Bot commented May 14, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 1f7b446

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

- Add cost to RequestyUsage type
- Include response.usage.cost in doGenerate providerMetadata
- Add cost to stream chunk usage schema
- Extract and forward cost in stream handleUsageChunk/flush
@wladimiiir
wladimiiir force-pushed the feat/add-cost-to-usage-metadata branch from ea2a11d to 1f7b446 Compare May 14, 2026 20:48
@requesty-JohnCosta27
requesty-JohnCosta27 merged commit fc89e55 into requestyai:backport/2.2.0-usage May 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants