Functions
create
fn (request: CachedContentsCreateRequest): CachedContentsCreateResponse
fn (request: CachedContentsCreateRequest, opts: Map): CachedContentsCreateResponse
Create a new cached content entry. Cached content allows reusing large contexts across multiple requests, reducing latency and cost.
Example
::cached ::gemini::cachedcontents
result ::cached/create(::cached/CachedContentsCreateRequest({
model: "models/gemini-2.0-flash",
displayName: "My cached context",
contents: [::cached/Content({
role: "user",
parts: [::cached/Part({text: "This is a large document to cache..."})]
})],
ttl: "3600s"
}))
result.name // => "cachedContents/abc123"
delete
fn (request: CachedContentsDeleteRequest): CachedContentsDeleteResponse
fn (request: CachedContentsDeleteRequest, opts: Map): CachedContentsDeleteResponse
Delete a cached content entry by name.
Example
::gemini::cachedcontents/delete(::gemini::cachedcontents/CachedContentsDeleteRequest({
name: "cachedContents/abc123"
}))
get
fn (request: CachedContentsGetRequest): CachedContentsGetResponse
fn (request: CachedContentsGetRequest, opts: Map): CachedContentsGetResponse
Get a specific cached content entry by name.
Example
result ::gemini::cachedcontents/get(::gemini::cachedcontents/CachedContentsGetRequest({
name: "cachedContents/abc123"
}))
result.displayName // => "My cached context"
result.model // => "models/gemini-2.0-flash"
result.expireTime // => "2025-01-01T00:00:00Z"
list
fn (request: CachedContentsListRequest): CachedContentsListResponse
fn (request: CachedContentsListRequest, opts: Map): CachedContentsListResponse
List cached contents. Returns a paginated list of previously cached content entries.
Example
result ::gemini::cachedcontents/list(::gemini::cachedcontents/CachedContentsListRequest({
page-size: "10",
page-token: ""
}))
cached or(result.cachedContents, [])
update
fn (name: Str, update-mask: Str, request: CachedContentsUpdateRequest): CachedContentsUpdateResponse
fn (name: Str, update-mask: Str, request: CachedContentsUpdateRequest, opts: Map): CachedContentsUpdateResponse
Update a cached content entry. Currently supports updating the TTL or expire time. The update-mask parameter specifies which fields to update.
Example
result ::gemini::cachedcontents/update("cachedContents/abc123", "ttl", ::gemini::cachedcontents/CachedContentsUpdateRequest({
ttl: "7200s"
}))
result.expireTime // updated expiration time
Types
Blob
Blob type {
mimeType: Str?,
data: Str?
}
CachedContent
CachedContent type {
name: Str?,
displayName: Str?,
model: Str?,
systemInstruction: Content?,
contents: Vec<Content>?,
tools: Vec<Tool>?,
toolConfig: ToolConfig?,
createTime: Str?,
updateTime: Str?,
usageMetadata: CachedContentUsageMetadata?,
expireTime: Str?,
ttl: Str?
}
CachedContentUsageMetadata
CachedContentUsageMetadata type {
totalTokenCount: Int?
}
CachedContentsCreateRequest
CachedContentsCreateRequest type {
model: Str,
displayName: Str?,
systemInstruction: Content?,
contents: Vec<Content>?,
tools: Vec<Tool>?,
toolConfig: ToolConfig?,
ttl: Str?,
expireTime: Str?
}
CachedContentsCreateResponse
CachedContentsCreateResponse type {
name: Str?,
displayName: Str?,
model: Str?,
systemInstruction: Content?,
contents: Vec<Content>?,
tools: Vec<Tool>?,
toolConfig: ToolConfig?,
createTime: Str?,
updateTime: Str?,
usageMetadata: CachedContentUsageMetadata?,
expireTime: Str?,
ttl: Str?
}
CachedContentsDeleteRequest
CachedContentsDeleteRequest type {
name: Str
}
CachedContentsDeleteResponse
CachedContentsDeleteResponse type {
value: Map
}
CachedContentsGetRequest
CachedContentsGetRequest type {
name: Str
}
CachedContentsGetResponse
CachedContentsGetResponse type {
name: Str?,
displayName: Str?,
model: Str?,
systemInstruction: Content?,
contents: Vec<Content>?,
tools: Vec<Tool>?,
toolConfig: ToolConfig?,
createTime: Str?,
updateTime: Str?,
usageMetadata: CachedContentUsageMetadata?,
expireTime: Str?,
ttl: Str?
}
CachedContentsListRequest
CachedContentsListRequest type {
page-size: Str,
page-token: Str
}
CachedContentsListResponse
CachedContentsListResponse type {
cachedContents: Vec<CachedContent>?,
nextPageToken: Str?
}
CachedContentsUpdateRequest
CachedContentsUpdateRequest type {
ttl: Str?,
expireTime: Str?
}
CachedContentsUpdateResponse
CachedContentsUpdateResponse type {
name: Str?,
displayName: Str?,
model: Str?,
systemInstruction: Content?,
contents: Vec<Content>?,
tools: Vec<Tool>?,
toolConfig: ToolConfig?,
createTime: Str?,
updateTime: Str?,
usageMetadata: CachedContentUsageMetadata?,
expireTime: Str?,
ttl: 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?
}
ContentRole
ContentRole type "user" | "model"
CreateCachedContentRequest
CreateCachedContentRequest type {
model: Str,
displayName: Str?,
systemInstruction: Content?,
contents: Vec<Content>?,
tools: Vec<Tool>?,
toolConfig: ToolConfig?,
ttl: Str?,
expireTime: Str?
}
DynamicRetrievalConfig
DynamicRetrievalConfig type {
mode: DynamicRetrievalMode?,
dynamicThreshold: Dec?
}
DynamicRetrievalMode
DynamicRetrievalMode type "MODE_UNSPECIFIED" | "MODE_DYNAMIC"
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?
}
FunctionCall
FunctionCall type {
name: Str?,
args: Map?
}
FunctionCallingConfig
FunctionCallingConfig type {
mode: FunctionCallingMode?,
allowedFunctionNames: Vec<Str>?
}
FunctionCallingMode
FunctionCallingMode type "MODE_UNSPECIFIED" | "AUTO" | "ANY" | "NONE"
FunctionDeclaration
FunctionDeclaration type {
name: Str?,
description: Str?,
parameters: Schema?
}
FunctionResponse
FunctionResponse type {
name: Str?,
response: Map?
}
GoogleSearchRetrieval
GoogleSearchRetrieval type {
dynamicRetrievalConfig: DynamicRetrievalConfig?
}
ListCachedContentsResponse
ListCachedContentsResponse type {
cachedContents: Vec<CachedContent>?,
nextPageToken: Str?
}
Part
Part type {
text: Str?,
inlineData: Blob?,
fileData: FileData?,
functionCall: FunctionCall?,
functionResponse: FunctionResponse?,
executableCode: ExecutableCode?,
codeExecutionResult: CodeExecutionResult?
}
Schema
Schema type {
type: SchemaType?,
format: Str?,
description: Str?,
nullable: Bool?,
enum: Vec<Str>?,
items: Schema?,
properties: Map?,
required: Vec<Str>?
}
SchemaType
SchemaType type "TYPE_UNSPECIFIED" | "STRING" | "NUMBER" | "INTEGER" | "BOOLEAN" | "ARRAY" | "OBJECT"
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?
}
UpdateCachedContentRequest
UpdateCachedContentRequest type {
ttl: Str?,
expireTime: Str?
}