Skip to content

Unable to view openai cachedPromptTokens in providerMetadata #8426

@bobbyzhong

Description

@bobbyzhong

Description

I'm using streamText and trying to see prompt caching results from the request. According to the docs here I should be able to see information about prompt caching through providerMetadata. However, when I log out providerMetadata like this

const providerMetadata = await streamResult.providerMetadata; console.log("PROVIDER METADATA", providerMetadata);

This is what I get
PROVIDER METADATA { openai: { responseId: 'resp_68b8a9962d6881959b8ef32423e42dad098f808d181f89bf', logprobs: [ [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [] ] } }

When I just log out streamResult.usage I see this

USAGE { inputTokens: 6003, outputTokens: 92, totalTokens: 6095, reasoningTokens: 0, cachedInputTokens: 5760 }

Why does the provider metadata not show any information about prompt caching?

Thanks!

AI SDK Version

"ai": "^5.0.22",
"@ai-sdk/anthropic": "^2.0.6",
"@ai-sdk/google": "^2.0.8",
"@ai-sdk/openai": "^2.0.19",
"@ai-sdk/provider-utils": "^3.0.5",

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions