Skip to content

Commit 657799a

Browse files
authoredMay 3, 2024··
Add UsageMetadata to GenerateContentResponse (#127)
Added the UsageMetadata payload to GenerateContentResponse, and updated docs accordingly.
1 parent 16acde7 commit 657799a

11 files changed

+104
-2
lines changed
 

‎.changeset/beige-lamps-sip.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@google/generative-ai": minor
3+
---
4+
5+
Added UsageMetadata to GenerateContentResponses.

‎docs/reference/main/generative-ai.generatecontentresponse.candidates.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## GenerateContentResponse.candidates property
66

7+
Candidate responses from the model.
8+
79
**Signature:**
810

911
```typescript

‎docs/reference/main/generative-ai.generatecontentresponse.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface GenerateContentResponse
1616

1717
| Property | Modifiers | Type | Description |
1818
| --- | --- | --- | --- |
19-
| [candidates?](./generative-ai.generatecontentresponse.candidates.md) | | [GenerateContentCandidate](./generative-ai.generatecontentcandidate.md)<!-- -->\[\] | _(Optional)_ |
20-
| [promptFeedback?](./generative-ai.generatecontentresponse.promptfeedback.md) | | [PromptFeedback](./generative-ai.promptfeedback.md) | _(Optional)_ |
19+
| [candidates?](./generative-ai.generatecontentresponse.candidates.md) | | [GenerateContentCandidate](./generative-ai.generatecontentcandidate.md)<!-- -->\[\] | _(Optional)_ Candidate responses from the model. |
20+
| [promptFeedback?](./generative-ai.generatecontentresponse.promptfeedback.md) | | [PromptFeedback](./generative-ai.promptfeedback.md) | _(Optional)_ The prompt's feedback related to the content filters. |
21+
| [usageMetadata?](./generative-ai.generatecontentresponse.usagemetadata.md) | | [UsageMetadata](./generative-ai.usagemetadata.md) | _(Optional)_ Metadata on the generation request's token usage. |
2122

‎docs/reference/main/generative-ai.generatecontentresponse.promptfeedback.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## GenerateContentResponse.promptFeedback property
66

7+
The prompt's feedback related to the content filters.
8+
79
**Signature:**
810

911
```typescript
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [GenerateContentResponse](./generative-ai.generatecontentresponse.md) &gt; [usageMetadata](./generative-ai.generatecontentresponse.usagemetadata.md)
4+
5+
## GenerateContentResponse.usageMetadata property
6+
7+
Metadata on the generation request's token usage.
8+
9+
**Signature:**
10+
11+
```typescript
12+
usageMetadata?: UsageMetadata;
13+
```

‎docs/reference/main/generative-ai.md

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
| [StartChatParams](./generative-ai.startchatparams.md) | Params for [GenerativeModel.startChat()](./generative-ai.generativemodel.startchat.md)<!-- -->. |
7373
| [TextPart](./generative-ai.textpart.md) | Content part interface if the part represents a text string. |
7474
| [ToolConfig](./generative-ai.toolconfig.md) | Tool config. This config is shared for all tools provided in the request. |
75+
| [UsageMetadata](./generative-ai.usagemetadata.md) | Metadata on the generation request's token usage. |
7576

7677
## Variables
7778

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [UsageMetadata](./generative-ai.usagemetadata.md) &gt; [candidatesTokenCount](./generative-ai.usagemetadata.candidatestokencount.md)
4+
5+
## UsageMetadata.candidatesTokenCount property
6+
7+
Total number of tokens across the generated candidates.
8+
9+
**Signature:**
10+
11+
```typescript
12+
candidatesTokenCount: number;
13+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [UsageMetadata](./generative-ai.usagemetadata.md)
4+
5+
## UsageMetadata interface
6+
7+
Metadata on the generation request's token usage.
8+
9+
**Signature:**
10+
11+
```typescript
12+
export interface UsageMetadata
13+
```
14+
15+
## Properties
16+
17+
| Property | Modifiers | Type | Description |
18+
| --- | --- | --- | --- |
19+
| [candidatesTokenCount](./generative-ai.usagemetadata.candidatestokencount.md) | | number | Total number of tokens across the generated candidates. |
20+
| [promptTokenCount](./generative-ai.usagemetadata.prompttokencount.md) | | number | Number of tokens in the prompt. |
21+
| [totalTokenCount](./generative-ai.usagemetadata.totaltokencount.md) | | number | Total token count for the generation request (prompt + candidates). |
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [UsageMetadata](./generative-ai.usagemetadata.md) &gt; [promptTokenCount](./generative-ai.usagemetadata.prompttokencount.md)
4+
5+
## UsageMetadata.promptTokenCount property
6+
7+
Number of tokens in the prompt.
8+
9+
**Signature:**
10+
11+
```typescript
12+
promptTokenCount: number;
13+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [UsageMetadata](./generative-ai.usagemetadata.md) &gt; [totalTokenCount](./generative-ai.usagemetadata.totaltokencount.md)
4+
5+
## UsageMetadata.totalTokenCount property
6+
7+
Total token count for the generation request (prompt + candidates).
8+
9+
**Signature:**
10+
11+
```typescript
12+
totalTokenCount: number;
13+
```

‎packages/main/types/responses.ts

+17
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,25 @@ export interface EnhancedGenerateContentResponse
7979
* @public
8080
*/
8181
export interface GenerateContentResponse {
82+
/** Candidate responses from the model. */
8283
candidates?: GenerateContentCandidate[];
84+
/** The prompt's feedback related to the content filters. */
8385
promptFeedback?: PromptFeedback;
86+
/** Metadata on the generation request's token usage. */
87+
usageMetadata?: UsageMetadata;
88+
}
89+
90+
/**
91+
* Metadata on the generation request's token usage.
92+
* @public
93+
*/
94+
export interface UsageMetadata {
95+
/** Number of tokens in the prompt. */
96+
promptTokenCount: number;
97+
/** Total number of tokens across the generated candidates. */
98+
candidatesTokenCount: number;
99+
/** Total token count for the generation request (prompt + candidates). */
100+
totalTokenCount: number;
84101
}
85102

86103
/**

0 commit comments

Comments
 (0)