Skip to content

Commit fe93589

Browse files
Fix type errors in prompt-caching examples with @ts-expect-error
Add FIXME comments noting that providerMetadata.openrouter.usage should be properly typed as OpenRouterUsage instead of JSONValue.
1 parent fdeb252 commit fe93589

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

typescript/ai-sdk-v5/src/prompt-caching/anthropic-multi-message-cache.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ async function main() {
6969
],
7070
});
7171

72+
// FIXME: providerMetadata.openrouter.usage should have proper type with promptTokensDetails
7273
const cached1 =
74+
// @ts-expect-error - usage is typed as JSONValue but should be OpenRouterUsage
7375
result1.providerMetadata?.openrouter?.usage?.promptTokensDetails?.cachedTokens ?? 0;
7476
console.log(` Response: ${result1.text.substring(0, 80)}...`);
7577
console.log(` cached_tokens=${cached1}`);
@@ -110,7 +112,9 @@ async function main() {
110112
],
111113
});
112114

115+
// FIXME: providerMetadata.openrouter.usage should have proper type with promptTokensDetails
113116
const cached2 =
117+
// @ts-expect-error - usage is typed as JSONValue but should be OpenRouterUsage
114118
result2.providerMetadata?.openrouter?.usage?.promptTokensDetails?.cachedTokens ?? 0;
115119
console.log(` Response: ${result2.text.substring(0, 80)}...`);
116120
console.log(` cached_tokens=${cached2}`);

typescript/ai-sdk-v5/src/prompt-caching/anthropic-no-cache-control.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ async function main() {
5959
],
6060
});
6161

62+
// FIXME: providerMetadata.openrouter.usage should have proper type with promptTokensDetails
6263
const cached1 =
64+
// @ts-expect-error - usage is typed as JSONValue but should be OpenRouterUsage
6365
result1.providerMetadata?.openrouter?.usage?.promptTokensDetails?.cachedTokens ?? 0;
6466
console.log(` cached_tokens=${cached1}`);
6567

@@ -87,7 +89,9 @@ async function main() {
8789
],
8890
});
8991

92+
// FIXME: providerMetadata.openrouter.usage should have proper type with promptTokensDetails
9093
const cached2 =
94+
// @ts-expect-error - usage is typed as JSONValue but should be OpenRouterUsage
9195
result2.providerMetadata?.openrouter?.usage?.promptTokensDetails?.cachedTokens ?? 0;
9296
console.log(` cached_tokens=${cached2}`);
9397

typescript/ai-sdk-v5/src/prompt-caching/anthropic-user-message-cache.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ async function main() {
8181

8282
console.log(' Response:', result1.text.substring(0, 100) + '...');
8383
const usage1 = result1.providerMetadata?.openrouter?.usage;
84+
// FIXME: providerMetadata.openrouter.usage should have proper type with promptTokensDetails, promptTokens, completionTokens
85+
// @ts-expect-error - usage is typed as JSONValue but should be OpenRouterUsage
8486
const cached1 = usage1?.promptTokensDetails?.cachedTokens ?? 0;
8587
console.log(
88+
// @ts-expect-error - usage is typed as JSONValue but should be OpenRouterUsage
8689
` Tokens: prompt=${usage1?.promptTokens}, completion=${usage1?.completionTokens}, cached=${cached1}`,
8790
);
8891

@@ -117,8 +120,11 @@ async function main() {
117120

118121
console.log(' Response:', result2.text.substring(0, 100) + '...');
119122
const usage2 = result2.providerMetadata?.openrouter?.usage;
123+
// FIXME: providerMetadata.openrouter.usage should have proper type with promptTokensDetails, promptTokens, completionTokens
124+
// @ts-expect-error - usage is typed as JSONValue but should be OpenRouterUsage
120125
const cached2 = usage2?.promptTokensDetails?.cachedTokens ?? 0;
121126
console.log(
127+
// @ts-expect-error - usage is typed as JSONValue but should be OpenRouterUsage
122128
` Tokens: prompt=${usage2?.promptTokens}, completion=${usage2?.completionTokens}, cached=${cached2}`,
123129
);
124130

0 commit comments

Comments
 (0)