Skip to content

Commit 2e74329

Browse files
authored
feat(ai): implicit caching feature (#9462)
1 parent c4a3a56 commit 2e74329

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

.changeset/tender-items-pretend.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@firebase/ai': minor
3+
'firebase': minor
4+
---
5+
6+
Add params on `UsageMetadata` that provide cache-related usage data when the implicit caching feature is used.

common/api-review/ai.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,8 @@ export type URLRetrievalStatus = (typeof URLRetrievalStatus)[keyof typeof URLRet
14441444

14451445
// @public
14461446
export interface UsageMetadata {
1447+
cachedContentTokenCount?: number;
1448+
cacheTokensDetails?: ModalityTokenCount[];
14471449
// (undocumented)
14481450
candidatesTokenCount: number;
14491451
// (undocumented)

docs-devsite/ai.usagemetadata.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export interface UsageMetadata
2222

2323
| Property | Type | Description |
2424
| --- | --- | --- |
25+
| [cachedContentTokenCount](./ai.usagemetadata.md#usagemetadatacachedcontenttokencount) | number | The number of tokens in the prompt that were served from the cache. If implicit caching is not active or no content was cached, this will be 0. |
26+
| [cacheTokensDetails](./ai.usagemetadata.md#usagemetadatacachetokensdetails) | [ModalityTokenCount](./ai.modalitytokencount.md#modalitytokencount_interface)<!-- -->\[\] | Detailed breakdown of the cached tokens by modality (for example, text or image). This list provides granular insight into which parts of the content were cached. |
2527
| [candidatesTokenCount](./ai.usagemetadata.md#usagemetadatacandidatestokencount) | number | |
2628
| [candidatesTokensDetails](./ai.usagemetadata.md#usagemetadatacandidatestokensdetails) | [ModalityTokenCount](./ai.modalitytokencount.md#modalitytokencount_interface)<!-- -->\[\] | |
2729
| [promptTokenCount](./ai.usagemetadata.md#usagemetadataprompttokencount) | number | |
@@ -31,6 +33,26 @@ export interface UsageMetadata
3133
| [toolUsePromptTokensDetails](./ai.usagemetadata.md#usagemetadatatooluseprompttokensdetails) | [ModalityTokenCount](./ai.modalitytokencount.md#modalitytokencount_interface)<!-- -->\[\] | A list of tokens used by tools, broken down by modality. |
3234
| [totalTokenCount](./ai.usagemetadata.md#usagemetadatatotaltokencount) | number | |
3335

36+
## UsageMetadata.cachedContentTokenCount
37+
38+
The number of tokens in the prompt that were served from the cache. If implicit caching is not active or no content was cached, this will be 0.
39+
40+
<b>Signature:</b>
41+
42+
```typescript
43+
cachedContentTokenCount?: number;
44+
```
45+
46+
## UsageMetadata.cacheTokensDetails
47+
48+
Detailed breakdown of the cached tokens by modality (for example, text or image). This list provides granular insight into which parts of the content were cached.
49+
50+
<b>Signature:</b>
51+
52+
```typescript
53+
cacheTokensDetails?: ModalityTokenCount[];
54+
```
55+
3456
## UsageMetadata.candidatesTokenCount
3557

3658
<b>Signature:</b>

packages/ai/src/types/responses.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ export interface UsageMetadata {
133133
* A list of tokens used by tools, broken down by modality.
134134
*/
135135
toolUsePromptTokensDetails?: ModalityTokenCount[];
136+
/**
137+
* The number of tokens in the prompt that were served from the cache.
138+
* If implicit caching is not active or no content was cached,
139+
* this will be 0.
140+
*/
141+
cachedContentTokenCount?: number;
142+
/**
143+
* Detailed breakdown of the cached tokens by modality (for example, text or
144+
* image). This list provides granular insight into which parts of
145+
* the content were cached.
146+
*/
147+
cacheTokensDetails?: ModalityTokenCount[];
136148
}
137149

138150
/**

0 commit comments

Comments
 (0)