GenerativeModel class Stay organized with collections Save and categorize content based on your preferences.
Class for generative model APIs.
Signature:
exportdeclareclassGenerativeModelextendsAIModelExtends:AIModel
Constructors
| Constructor | Modifiers | Description |
|---|---|---|
| (constructor)(ai, modelParams, requestOptions, chromeAdapter) | Constructs a new instance of theGenerativeModel class |
Properties
| Property | Modifiers | Type | Description |
|---|---|---|---|
| generationConfig | GenerationConfig | ||
| requestOptions | RequestOptions | ||
| safetySettings | SafetySetting[] | ||
| systemInstruction | Content | ||
| toolConfig | ToolConfig | ||
| tools | Tool[] |
Methods
| Method | Modifiers | Description |
|---|---|---|
| countTokens(request, singleRequestOptions) | Counts the tokens in the provided request. | |
| generateContent(request, singleRequestOptions) | Makes a single non-streaming call to the model and returns an object containing a singleGenerateContentResponse. | |
| generateContentStream(request, singleRequestOptions) | Makes a single streaming call to the model and returns an object containing an iterable stream that iterates over all chunks in the streaming response as well as a promise that returns the final aggregated response. | |
| startChat(startChatParams) | Gets a newChatSession instance which can be used for multi-turn chats. |
GenerativeModel.(constructor)
Constructs a new instance of theGenerativeModel class
Signature:
constructor(ai:AI,modelParams:ModelParams,requestOptions?:RequestOptions,chromeAdapter?:ChromeAdapter|undefined);Parameters
| Parameter | Type | Description |
|---|---|---|
| ai | AI | |
| modelParams | ModelParams | |
| requestOptions | RequestOptions | |
| chromeAdapter | ChromeAdapter | undefined |
GenerativeModel.generationConfig
Signature:
generationConfig:GenerationConfig;GenerativeModel.requestOptions
Signature:
requestOptions?:RequestOptions;GenerativeModel.safetySettings
Signature:
safetySettings:SafetySetting[];GenerativeModel.systemInstruction
Signature:
systemInstruction?:Content;GenerativeModel.toolConfig
Signature:
toolConfig?:ToolConfig;GenerativeModel.tools
Signature:
tools?:Tool[];GenerativeModel.countTokens()
Counts the tokens in the provided request.
Signature:
countTokens(request:CountTokensRequest|string|Array<string|Part>,singleRequestOptions?:SingleRequestOptions):Promise<CountTokensResponse>;Parameters
| Parameter | Type | Description |
|---|---|---|
| request | CountTokensRequest | string | Array<string |Part> | |
| singleRequestOptions | SingleRequestOptions |
Returns:
Promise<CountTokensResponse>
GenerativeModel.generateContent()
Makes a single non-streaming call to the model and returns an object containing a singleGenerateContentResponse.
Signature:
generateContent(request:GenerateContentRequest|string|Array<string|Part>,singleRequestOptions?:SingleRequestOptions):Promise<GenerateContentResult>;Parameters
| Parameter | Type | Description |
|---|---|---|
| request | GenerateContentRequest | string | Array<string |Part> | |
| singleRequestOptions | SingleRequestOptions |
Returns:
Promise<GenerateContentResult>
GenerativeModel.generateContentStream()
Makes a single streaming call to the model and returns an object containing an iterable stream that iterates over all chunks in the streaming response as well as a promise that returns the final aggregated response.
Signature:
generateContentStream(request:GenerateContentRequest|string|Array<string|Part>,singleRequestOptions?:SingleRequestOptions):Promise<GenerateContentStreamResult>;Parameters
| Parameter | Type | Description |
|---|---|---|
| request | GenerateContentRequest | string | Array<string |Part> | |
| singleRequestOptions | SingleRequestOptions |
Returns:
Promise<GenerateContentStreamResult>
GenerativeModel.startChat()
Gets a newChatSession instance which can be used for multi-turn chats.
Signature:
startChat(startChatParams?:StartChatParams):ChatSession;Parameters
| Parameter | Type | Description |
|---|---|---|
| startChatParams | StartChatParams |
Returns:
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-01-15 UTC.