v2026.5.3
All Bundles
Bundle Google Gemini API client. Supports text generation, multimodal inputs (image, audio, video), chat sessions, function calling, and caching. Set GOOGLE_API_KEY before use. Compile with -lib gemini.

Model

Gemini model interactions

Inherits: EndPoint
content := Content->New("user")->AddPart(TextPart->New("What number is this image showing?"))
  ->AddPart(BinaryPart->New(FileReader->ReadBinaryFile("thirdteen.png"), "image/png"));
candidates := Model->GenerateContent("models/gemini-1.5-flash", content, EndPoint->GetApiKey());
each(candidate in candidates) {
  candidate->ToString()->PrintLine();
};

Operations

BatchEmbedContent # function

Generates embeddings for multiple text strings in a single request

function : BatchEmbedContent(model_name:String, texts:Vector<String>, key:String) ~ Vector<EmbeddingValues>

Parameters

NameTypeDescription
model_nameStringmodel name (e.g. "models/text-embedding-004")
textsVector<String>list of text strings to embed
keyStringAPI key

Return

TypeDescription
Vector<EmbeddingValues>list of embedding vectors, one per input text

CountTokens # function

Runs a model's tokenizer on input content and returns the token count

function : CountTokens(model_name:String, content:Content, key:String) ~ Int

Parameters

NameTypeDescription
model_nameStringmodel name
contentContentcontent for the model
keyStringAPI key

Example

content := Content->New("user")->AddPart(TextPart->New("Hello, world!"));
count := Model->CountTokens(Model->GEMINI_2_0_FLASH(), content, EndPoint->GetApiKey());
"Token count: {$count}"->PrintLine();

CountTokens # function

Runs a model's tokenizer on input content and returns the token count

function : CountTokens(model_name:String, contents:Vector<Content>, key:String) ~ Int

Parameters

NameTypeDescription
model_nameStringmodel name
contentsVector<Content>list of content for the model
keyStringAPI key

EmbedContent # function

Generates an embedding from the model given an input Content

function : EmbedContent(content:Content, key:String) ~ Float[]

Parameters

NameTypeDescription
contentContentmodel content=
keyStringAPI key

Example

content := Content->New("user")->AddPart(TextPart->New("machine learning"));
embedding := Model->EmbedContent(content, EndPoint->GetApiKey());
"Embedding dimensions: {$embedding->Size()}"->PrintLine();

EmbedContent # function

Generates an embedding from the model given an input Content

function : EmbedContent(content:Content, title:String, type:Model->TaskType, key:String) ~ Float[]

Parameters

NameTypeDescription
contentContentmodel content=
titleStringtitle for the text. Only applicable when TaskType is RETRIEVAL_DOCUMENT
typeModel->TaskTypetask type for which the embeddings will be used
keyStringAPI key

GEMINI_1_5_FLASH # native

Model name constants for Gemini 1.5 models

function : native : GEMINI_1_5_FLASH() ~ String

GEMINI_2_0_FLASH # native

Model name constants for Gemini 2.0 models

function : native : GEMINI_2_0_FLASH() ~ String

GEMINI_2_5_PRO # native

Model name constants for Gemini 2.5 models

function : native : GEMINI_2_5_PRO() ~ String

GEMINI_PRO # native

Model name constants for legacy models

function : native : GEMINI_PRO() ~ String

GenerateContent # function

Generates a response from the model given an input

function : GenerateContent(model_name:String, content:Content, key:String) ~ Vector<Candidate>

Parameters

NameTypeDescription
model_nameStringmodel name
contentContentcontent for the model
keyStringAPI key

Example

content := Content->New("user")->AddPart(TextPart->New("What is the Eiffel Tower?"));
candidates := Model->GenerateContent(Model->GEMINI_2_0_FLASH(), content, EndPoint->GetApiKey());
each(candidate in candidates) {
  candidate->GetAllText()->PrintLine();
};

GenerateContent # function

Generates a response from the model given an input with system instruction

function : GenerateContent(model_name:String, content:Content, system_instruction:Content, key:String) ~ Vector<Candidate>

Parameters

NameTypeDescription
model_nameStringmodel name
contentContentcontent for the model
system_instructionContentsystem instruction content
keyStringAPI key

GenerateContent # function

Generates a response from the model given an input

function : GenerateContent(model_name:String, content:Content, resp_schema:Pair<String,ParameterType>, key:String) ~ Vector<Candidate>

Parameters

NameTypeDescription
model_nameStringmodel name
contentContentcontent for the model
resp_schemaPair<String,ParameterType>response format
keyStringAPI key

GenerateContent # function

Generates a response from the model given an input

function : GenerateContent(model_name:String, content:Content, funcs:Map<String,Pair<FunctionType,Func2Ref<JsonElement,JsonElement>>>) ~ Vector<Candidate>

Parameters

NameTypeDescription
model_nameStringmodel name
contentContentcontent for the model
funcsMap<String,Pair<FunctionType,Func2Ref<JsonElement,JsonElement>>>map of function callbacks, name must to map to function callback name

GenerateContent # function

Generates a response from the model given an input

function : GenerateContent(model_name:String, content:Content, funcs:Map<String,Pair<FunctionType,Func2Ref<JsonElement,JsonElement>>>) ~ Vector<Candidate>

Parameters

NameTypeDescription
model_nameStringmodel name
contentContentmodel content
funcsMap<String,Pair<FunctionType,Func2Ref<JsonElement,JsonElement>>>map of function callbacks, name must to map to function callback name

GenerateContent # function

Generates a response from the model given an input

function : GenerateContent(model_name:String, contents:Vector<Content>, funcs:Map<String,Pair<FunctionType,Func2Ref<JsonElement,JsonElement>>>) ~ Vector<Candidate>

Parameters

NameTypeDescription
model_nameStringmodel name
contentsVector<Content>list of content for the model
funcsMap<String,Pair<FunctionType,Func2Ref<JsonElement,JsonElement>>>map of function callbacks, name must to map to function callback name

GenerateContentWithGrounding # function

Generate content using Google Search grounding for up-to-date information

function : GenerateContentWithGrounding(model_name:String, content:Content, key:String) ~ Vector<Candidate>

Parameters

NameTypeDescription
model_nameStringmodel name (e.g. "models/gemini-2.0-flash")
contentContentuser content
keyStringAPI key

Return

TypeDescription
Vector<Candidate>list of candidates with grounding metadata

Get # function

Gets a model by name

function : Get(model_name:String, key:String) ~ Model

Parameters

NameTypeDescription
model_nameStringmodel name
keyStringAPI key

Return

TypeDescription
Modelavailable models

Example

model := Model->Get(Model->GEMINI_2_0_FLASH(), EndPoint->GetApiKey());
"Version: {$model->GetVersion()}"->PrintLine();
"Max output tokens: {$model->GetOutputTokenLimit()}"->PrintLine();

GetDescription #

Get the model's description

method : public : GetDescription() ~ String

Return

TypeDescription
Stringmodel's description

GetDisplayName #

Get the model's display name

method : public : GetDisplayName() ~ String

Return

TypeDescription
Stringmodel's display name

GetGenerationMethods #

The model's supported generation methods.

method : public : GetGenerationMethods() ~ Vector<String>

Return

TypeDescription
Vector<String>generation methods

GetInputTokenLimit #

Get the model's input token limit

method : public : GetInputTokenLimit() ~ Int

Return

TypeDescription
Intmodel's input token limit

GetName #

Get the model's name

method : public : GetName() ~ String

Return

TypeDescription
Stringmodel's name

GetOutputTokenLimit #

Maximum number of output tokens available for this model

method : public : GetOutputTokenLimit() ~ Int

Return

TypeDescription
Intmaximum number of output tokens

GetTemperature #

Controls the randomness of the output. Values can range over [0.0,1.0], inclusive. A value closer to 1.0 will produce responses that are more varied, while a value closer to 0.0 will typically result in less surprising responses from the model.

method : public : GetTemperature() ~ Float

Return

TypeDescription
Floatmodel temperature

GetTopK #

Get the top-k sampling of the most probable tokens.

method : public : GetTopK() ~ Int

Return

TypeDescription
Inttop-k sampling

GetTopP #

Nucleus sampling considers the smallest set of tokens whose probability sum is at least topP.

method : public : GetTopP() ~ Float

GetVersion #

Get the model version

method : public : GetVersion() ~ String

Return

TypeDescription
Stringmodel version

List # function

Lists available models

function : List(key:String) ~ Vector<Model>

Parameters

NameTypeDescription
keyStringAPI key

Return

TypeDescription
Vector<Model>available models

Example

models := Model->List(EndPoint->GetApiKey());
each(model in models) {
  model->GetName()->PrintLine();
};

ToString #

String representation of the object

method : public : ToString() ~ String

Return

TypeDescription
Stringstring representation