Functions
batch-embed-contents
fn (model: Str, request: ModelsBatchEmbedContentsRequest): ModelsBatchEmbedContentsResponse
fn (model: Str, request: ModelsBatchEmbedContentsRequest, opts: Map): ModelsBatchEmbedContentsResponse
Generate embeddings for multiple content items in a single request. More efficient than calling embed-content multiple times.
Example
::models ::gemini::models
response ::models/batch-embed-contents("text-embedding-004", ::models/ModelsBatchEmbedContentsRequest({
requests: [
::models/EmbedContentRequest({
content: ::models/Content({role: "user", parts: [::models/Part({text: "Hello world"})]}),
model: "models/text-embedding-004"
}),
::models/EmbedContentRequest({
content: ::models/Content({role: "user", parts: [::models/Part({text: "Goodbye world"})]}),
model: "models/text-embedding-004"
})
]
}))
length(response.embeddings) // => 2
count-tokens
fn (model: Str, request: ModelsCountTokensRequest): ModelsCountTokensResponse
fn (model: Str, request: ModelsCountTokensRequest, opts: Map): ModelsCountTokensResponse
Count the number of tokens in the provided content. Useful for estimating API usage before making a generation request.
Example
::models ::gemini::models
response ::models/count-tokens("gemini-2.0-flash", ::models/ModelsCountTokensRequest({
contents: [::models/Content({
role: "user",
parts: [::models/Part({text: "Hello, world!"})]
})]
}))
response.totalTokens // => 3
embed-content
fn (model: Str, request: ModelsEmbedContentRequest): ModelsEmbedContentResponse
fn (model: Str, request: ModelsEmbedContentRequest, opts: Map): ModelsEmbedContentResponse
Generate an embedding vector for the given content. Supports optional task type for optimized embeddings.
Example
::models ::gemini::models
response ::models/embed-content("text-embedding-004", ::models/ModelsEmbedContentRequest({
content: ::models/Content({
role: "user",
parts: [::models/Part({text: "The quick brown fox jumps over the lazy dog"})]
})
}))
response.embedding.values // => [0.0123, -0.0456, ...]
With task type
::models ::gemini::models
response ::models/embed-content("text-embedding-004", ::models/ModelsEmbedContentRequest({
content: ::models/Content({
role: "user",
parts: [::models/Part({text: "What is the meaning of life?"})]
}),
taskType: "RETRIEVAL_QUERY"
}))
generate-content
fn (model: Str, request: ModelsGenerateContentRequest): ModelsGenerateContentResponse
fn (model: Str, request: ModelsGenerateContentRequest, opts: Map): ModelsGenerateContentResponse
Generate content using a Gemini model (non-streaming). This is the low-level API; for a simpler interface, see ::gemini::chat/generate or ::gemini::chat/chat.
Example
::models ::gemini::models
response ::models/generate-content("gemini-2.0-flash", ::models/ModelsGenerateContentRequest({
contents: [::models/Content({
role: "user",
parts: [::models/Part({text: "What is the capital of France?"})]
})],
generationConfig: ::models/GenerationConfig({maxOutputTokens: 100})
}))
text first(response.candidates).content.parts[0].text
get
fn (request: ModelsGetRequest): ModelsGetResponse
fn (request: ModelsGetRequest, opts: Map): ModelsGetResponse
Get details about a specific Gemini model, including its capabilities and token limits.
Example
model ::gemini::models/get(::gemini::models/ModelsGetRequest({
model: "gemini-2.0-flash"
}))
model.name // => "models/gemini-2.0-flash"
model.displayName // => "Gemini 2.0 Flash"
model.inputTokenLimit // => 1048576
model.outputTokenLimit // => 8192
list
fn (request: ModelsListRequest): ModelsListResponse
fn (request: ModelsListRequest, opts: Map): ModelsListResponse
List available Gemini models. Returns a paginated list of models with their capabilities.
Example
models ::gemini::models/list(::gemini::models/ModelsListRequest({
page-size: "10",
page-token: ""
}))
first-model first(models.models)
first-model.name // => "models/gemini-2.0-flash"
stream-generate-content
fn (model: Str, alt: Str, request: ModelsStreamGenerateContentRequest): ModelsStreamGenerateContentResponse
fn (model: Str, alt: Str, request: ModelsStreamGenerateContentRequest, opts: Map): ModelsStreamGenerateContentResponse
Generate content with streaming. Requires an alt parameter (e.g. "sse") to specify the streaming format.
Example
::models ::gemini::models
response ::models/stream-generate-content("gemini-2.0-flash", "sse", ::models/ModelsStreamGenerateContentRequest({
contents: [::models/Content({
role: "user",
parts: [::models/Part({text: "Count from 1 to 5."})]
})],
generationConfig: ::models/GenerationConfig({maxOutputTokens: 100})
}))
Types
BatchEmbedContentsRequest
BatchEmbedContentsRequest type {
requests: Vec<EmbedContentRequest>
}
BatchEmbedContentsResponse
BatchEmbedContentsResponse type {
embeddings: Vec<ContentEmbedding>?
}
Blob
Blob type {
mimeType: Str?,
data: Str?
}
BlockReason
BlockReason type "BLOCK_REASON_UNSPECIFIED" | "SAFETY" | "OTHER" | "BLOCKLIST" | "PROHIBITED_CONTENT"
Candidate
Candidate type {
content: Content?,
finishReason: FinishReason?,
safetyRatings: Vec<SafetyRating>?,
citationMetadata: CitationMetadata?,
tokenCount: Int?,
groundingMetadata: GroundingMetadata?,
avgLogprobs: Dec?,
logprobsResult: LogprobsResult?,
index: Int?
}
CitationMetadata
CitationMetadata type {
citationSources: Vec<CitationSource>?
}
CitationSource
CitationSource type {
startIndex: Int?,
endIndex: Int?,
uri: Str?,
license: Str?
}
CodeExecutionOutcome
CodeExecutionOutcome type "OUTCOME_UNSPECIFIED" | "OUTCOME_OK" | "OUTCOME_FAILED" | "OUTCOME_DEADLINE_EXCEEDED"
CodeExecutionResult
CodeExecutionResult type {
outcome: CodeExecutionOutcome?,
output: Str?
}
Content
Content type {
parts: Vec<Part>?,
role: ContentRole?
}
ContentEmbedding
ContentEmbedding type {
values: Vec<Dec>?
}
ContentRole
ContentRole type "user" | "model"
CountTokensRequest
CountTokensRequest type {
contents: Vec<Content>?,
generateContentRequest: GenerateContentRequest?
}
CountTokensResponse
CountTokensResponse type {
totalTokens: Int?,
cachedContentTokenCount: Int?
}
DynamicRetrievalConfig
DynamicRetrievalConfig type {
mode: "MODE_UNSPECIFIED" | "MODE_DYNAMIC"?,
dynamicThreshold: Dec?
}
EmbedContentRequest
EmbedContentRequest type {
content: Content,
taskType: "TASK_TYPE_UNSPECIFIED" | "RETRIEVAL_QUERY" | "RETRIEVAL_DOCUMENT" | "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "QUESTION_ANSWERING" | "FACT_VERIFICATION"?,
title: Str?,
outputDimensionality: Int?
}
EmbedContentResponse
EmbedContentResponse type {
embedding: ContentEmbedding?
}
ErrorResponse
ErrorResponse type {
error: Status?
}
ExecutableCode
ExecutableCode type {
language: ExecutableCodeLanguage?,
code: Str?
}
ExecutableCodeLanguage
ExecutableCodeLanguage type "LANGUAGE_UNSPECIFIED" | "PYTHON"
FileData
FileData type {
mimeType: Str?,
fileUri: Str?
}
FinishReason
FinishReason type "FINISH_REASON_UNSPECIFIED" | "STOP" | "MAX_TOKENS" | "SAFETY" | "RECITATION" | "LANGUAGE" | "OTHER" | "BLOCKLIST" | "PROHIBITED_CONTENT" | "SPII" | "MALFORMED_FUNCTION_CALL"
FunctionCall
FunctionCall type {
name: Str?,
args: Map?
}
FunctionCallingConfig
FunctionCallingConfig type {
mode: "MODE_UNSPECIFIED" | "AUTO" | "ANY" | "NONE"?,
allowedFunctionNames: Vec<Str>?
}
FunctionDeclaration
FunctionDeclaration type {
name: Str?,
description: Str?,
parameters: Schema?
}
FunctionResponse
FunctionResponse type {
name: Str?,
response: Map?
}
GenerateContentRequest
GenerateContentRequest type {
contents: Vec<Content>,
systemInstruction: Content?,
tools: Vec<Tool>?,
toolConfig: ToolConfig?,
safetySettings: Vec<SafetySetting>?,
generationConfig: GenerationConfig?,
cachedContent: Str?
}
GenerateContentResponse
GenerateContentResponse type {
candidates: Vec<Candidate>?,
promptFeedback: PromptFeedback?,
usageMetadata: UsageMetadata?,
modelVersion: Str?
}
GenerationConfig
GenerationConfig type {
stopSequences: Vec<Str>?,
responseMimeType: Str?,
responseSchema: Schema?,
candidateCount: Int?,
maxOutputTokens: Int?,
temperature: Dec?,
topP: Dec?,
topK: Int?,
presencePenalty: Dec?,
frequencyPenalty: Dec?,
responseLogprobs: Bool?,
logprobs: Int?
}
GoogleSearchRetrieval
GoogleSearchRetrieval type {
dynamicRetrievalConfig: DynamicRetrievalConfig?
}
GroundingChunk
GroundingChunk type {
web: Web?,
retrievedContext: RetrievedContext?
}
GroundingMetadata
GroundingMetadata type {
webSearchQueries: Vec<Str>?,
searchEntryPoint: SearchEntryPoint?,
groundingChunks: Vec<GroundingChunk>?,
groundingSupports: Vec<GroundingSupport>?,
retrievalMetadata: RetrievalMetadata?
}
GroundingSupport
GroundingSupport type {
segment: Segment?,
groundingChunkIndices: Vec<Int>?,
confidenceScores: Vec<Dec>?
}
HarmProbability
HarmProbability type "HARM_PROBABILITY_UNSPECIFIED" | "NEGLIGIBLE" | "LOW" | "MEDIUM" | "HIGH"
ListModelsResponse
ListModelsResponse type {
models: Vec<Model>?,
nextPageToken: Str?
}
LogprobsCandidate
LogprobsCandidate type {
token: Str?,
tokenId: Int?,
logProbability: Dec?
}
LogprobsResult
LogprobsResult type {
topCandidates: Vec<TopCandidates>?,
chosenCandidates: Vec<LogprobsCandidate>?
}
Model
Model type {
name: Str?,
baseModelId: Str?,
version: Str?,
displayName: Str?,
description: Str?,
inputTokenLimit: Int?,
outputTokenLimit: Int?,
supportedGenerationMethods: Vec<Str>?,
temperature: Dec?,
maxTemperature: Dec?,
topP: Dec?,
topK: Int?
}
ModelsBatchEmbedContentsRequest
ModelsBatchEmbedContentsRequest type {
requests: Vec<EmbedContentRequest>
}
ModelsBatchEmbedContentsResponse
ModelsBatchEmbedContentsResponse type {
embeddings: Vec<ContentEmbedding>?
}
ModelsCountTokensRequest
ModelsCountTokensRequest type {
contents: Vec<Content>?,
generateContentRequest: GenerateContentRequest?
}
ModelsCountTokensResponse
ModelsCountTokensResponse type {
totalTokens: Int?,
cachedContentTokenCount: Int?
}
ModelsEmbedContentRequest
ModelsEmbedContentRequest type {
content: Content,
taskType: "TASK_TYPE_UNSPECIFIED" | "RETRIEVAL_QUERY" | "RETRIEVAL_DOCUMENT" | "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "QUESTION_ANSWERING" | "FACT_VERIFICATION"?,
title: Str?,
outputDimensionality: Int?
}
ModelsEmbedContentResponse
ModelsEmbedContentResponse type {
embedding: ContentEmbedding?
}
ModelsGenerateContentRequest
ModelsGenerateContentRequest type {
contents: Vec<Content>,
systemInstruction: Content?,
tools: Vec<Tool>?,
toolConfig: ToolConfig?,
safetySettings: Vec<SafetySetting>?,
generationConfig: GenerationConfig?,
cachedContent: Str?
}
ModelsGenerateContentResponse
ModelsGenerateContentResponse type {
candidates: Vec<Candidate>?,
promptFeedback: PromptFeedback?,
usageMetadata: UsageMetadata?,
modelVersion: Str?
}
ModelsGetRequest
ModelsGetRequest type {
model: Str
}
ModelsGetResponse
ModelsGetResponse type {
name: Str?,
baseModelId: Str?,
version: Str?,
displayName: Str?,
description: Str?,
inputTokenLimit: Int?,
outputTokenLimit: Int?,
supportedGenerationMethods: Vec<Str>?,
temperature: Dec?,
maxTemperature: Dec?,
topP: Dec?,
topK: Int?
}
ModelsListRequest
ModelsListRequest type {
page-size: Str,
page-token: Str
}
ModelsListResponse
ModelsListResponse type {
models: Vec<Model>?,
nextPageToken: Str?
}
ModelsStreamGenerateContentRequest
ModelsStreamGenerateContentRequest type {
contents: Vec<Content>,
systemInstruction: Content?,
tools: Vec<Tool>?,
toolConfig: ToolConfig?,
safetySettings: Vec<SafetySetting>?,
generationConfig: GenerationConfig?,
cachedContent: Str?
}
ModelsStreamGenerateContentResponse
ModelsStreamGenerateContentResponse type {
candidates: Vec<Candidate>?,
promptFeedback: PromptFeedback?,
usageMetadata: UsageMetadata?,
modelVersion: Str?
}
Part
Part type {
text: Str?,
inlineData: Blob?,
fileData: FileData?,
functionCall: FunctionCall?,
functionResponse: FunctionResponse?,
executableCode: ExecutableCode?,
codeExecutionResult: CodeExecutionResult?
}
PromptFeedback
PromptFeedback type {
blockReason: BlockReason?,
safetyRatings: Vec<SafetyRating>?
}
RetrievalMetadata
RetrievalMetadata type {
googleSearchDynamicRetrievalScore: Dec?
}
RetrievedContext
RetrievedContext type {
uri: Str?,
title: Str?
}
SafetyRating
SafetyRating type {
category: Str?,
probability: HarmProbability?,
blocked: Bool?
}
SafetySetting
SafetySetting type {
category: "HARM_CATEGORY_UNSPECIFIED" | "HARM_CATEGORY_DEROGATORY" | "HARM_CATEGORY_TOXICITY" | "HARM_CATEGORY_VIOLENCE" | "HARM_CATEGORY_SEXUAL" | "HARM_CATEGORY_MEDICAL" | "HARM_CATEGORY_DANGEROUS" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_CIVIC_INTEGRITY"?,
threshold: "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_ONLY_HIGH" | "BLOCK_NONE" | "OFF"?
}
Schema
Schema type {
type: "TYPE_UNSPECIFIED" | "STRING" | "NUMBER" | "INTEGER" | "BOOLEAN" | "ARRAY" | "OBJECT"?,
format: Str?,
description: Str?,
nullable: Bool?,
enum: Vec<Str>?,
items: Schema?,
properties: Map?,
required: Vec<Str>?
}
SearchEntryPoint
SearchEntryPoint type {
renderedContent: Str?,
sdkBlob: Str?
}
Segment
Segment type {
partIndex: Int?,
startIndex: Int?,
endIndex: Int?,
text: Str?
}
Status
Status type {
code: Int?,
message: Str?,
details: Vec<Map>?
}
Tool
Tool type {
functionDeclarations: Vec<FunctionDeclaration>?,
codeExecution: Map?,
googleSearch: Map?,
googleSearchRetrieval: GoogleSearchRetrieval?
}
ToolConfig
ToolConfig type {
functionCallingConfig: FunctionCallingConfig?
}
TopCandidates
TopCandidates type {
candidates: Vec<LogprobsCandidate>?
}
UsageMetadata
UsageMetadata type {
promptTokenCount: Int?,
cachedContentTokenCount: Int?,
candidatesTokenCount: Int?,
totalTokenCount: Int?
}
Web
Web type {
uri: Str?,
title: Str?
}