> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gengen.farm/llms.txt
> Use this file to discover all available pages before exploring further.

# Gemini tools

> Use Gemini function calling, Code execution, and Computer use, with conversation replay and streaming requirements.

Gemini `gemini-3.8-flash`, `gemini-3.7-flash`, and `gemini-3.5-flash-lite` support
function calling, Google Code execution, and Computer use. Tools are enabled per
request through [Chat Completions](/api-reference/google/chat-completions) or
[Responses](/api-reference/google/responses).

Start with the [Function calling guide](/tool-calling) for tool declarations and
the application-side execution loop. This page covers Gemini-specific options,
conversation metadata, built-in tools, and streaming behavior.

## Function calling options

For Gemini, `tool_choice` accepts `auto`, `none`, `required`, or
`{"type":"function","function":{"name":"get_weather"}}`.
Return a result for every call, matched by ID, including parallel calls with the same
function name. Gemini rejects `parallel_tool_calls: false`; handle all returned calls.
Supported tool options and reasoning settings vary by model; check the selected model reference.

## Gemini conversation metadata

Gemini assistant messages include `providerMetadata.google.parts` when needed. These
are the original ordered Gemini parts, including thought signatures, native call IDs,
code, execution results, and inline output bytes. Preserve them unchanged when
replaying the assistant message. They take precedence over reconstructed content.

Each Chat Completions tool call also carries `extra_content.google.thought_signature`
and `extra_content.google.function_call_id` when supplied by Google. Preserve these
if your client reconstructs messages from `tool_calls` instead of retaining the full
assistant message. Do not fabricate signatures or discard provider reasoning fields.

## Streaming

Use `stream: true` on Chat Completions. Tool calls appear in
`choices[0].delta.tool_calls` with stable call IDs and zero-based indexes.
Gemini emits complete arguments for each call. Collect text and tool calls, and
concatenate `delta.providerMetadata.google.parts` arrays in stream order into the
assistant message's `providerMetadata.google.parts` before replaying it.

Execution code, results, and graph bytes also arrive in these parts, even when the
chunk has no text. The stream ends with usage and `data: [DONE]` after successful
settlement. An error event without `[DONE]` is an incomplete stream.
Gemini's native `streamFunctionCallArguments: true` option is rejected; the API does
not expose Google's JSONPath argument fragments.

## Gemini Code execution

Enable Google's built-in Python execution tool:

```json theme={"dark"}
{
  "model": "gemini-3.8-flash",
  "messages": [{ "role": "user", "content": "Use Python to calculate the first 20 Fibonacci numbers." }],
  "providerOptions": {
    "google": { "tools": [{ "codeExecution": {} }] }
  }
}
```

Google runs the code. Read `executableCode`, `codeExecutionResult`, and any
`inlineData` graph output from the returned `providerMetadata.google.parts`.
Check the execution `outcome`; failed or timed-out code can still return a model
explanation. Code generation and execution results are preserved without requiring
text output.

For CSV or other supported inline files, use a content part such as
`{"type":"input_file","file_data":"data:text/csv;base64,eCx5CjEsMg=="}`.
Google Code execution requires inline file bytes rather than file URIs.

## Gemini Computer use

Provide a screenshot and enable the built-in tool:

```json theme={"dark"}
{
  "model": "gemini-3.8-flash",
  "messages": [{
    "role": "user",
    "content": [
      { "type": "text", "text": "Find the search field on this page." },
      { "type": "image_url", "image_url": { "url": "data:image/png;base64,REPLACE_WITH_SCREENSHOT" } }
    ]
  }],
  "providerOptions": {
    "google": {
      "tools": [{ "computerUse": { "environment": "ENVIRONMENT_BROWSER" } }]
    }
  }
}
```

Computer actions return as `tool_calls` with the action name and arguments.
Your application supplies the browser or device, executes permitted actions, and
captures the new screenshot. GENGEN does not provision or control a computer.

Keep safety decisions in the call arguments. When Google requests confirmation,
ask the end user before executing the action. After actual confirmation, send the
provider's `safety_acknowledgement` in the result JSON. GENGEN never supplies this
acknowledgement automatically.

Append the complete assistant message, then a tool result with the matching ID:

```json theme={"dark"}
{
  "role": "tool",
  "tool_call_id": "RETURNED_CALL_ID",
  "content": [
    { "type": "text", "text": "{\"url\":\"https://example.com\"}" },
    { "type": "image_url", "image_url": { "url": "data:image/png;base64,REPLACE_WITH_NEW_SCREENSHOT" } }
  ]
}
```

Gemini receives the JSON as `functionResponse.response` and the screenshot as
`functionResponse.parts`. `computerUse` also accepts Google's
`excludedPredefinedFunctions` and `enablePromptInjectionDetection` options.
`ENVIRONMENT_MOBILE` can be requested where supported by the selected Google model.

## Responses API

Gemini also supports all three tool types through synchronous or streaming
`POST /api/gengen/v1/responses`. Use flat function declarations:

```json theme={"dark"}
{
  "model": "gemini-3.8-flash",
  "input": "What is the weather in Paris?",
  "tools": [{
    "type": "function",
    "name": "get_weather",
    "parameters": {
      "type": "object",
      "properties": { "city": { "type": "string" } },
      "required": ["city"]
    }
  }]
}
```

Calls appear as `output` items with `type: "function_call"`, `call_id`, `name`, and
JSON-string `arguments`. Append **all** returned output items to your prior input,
then append one `{"type":"function_call_output","call_id":"...","output":"..."}`
for each call. Keep each item's `providerMetadata` unchanged. `output` can also be
an array of text and screenshot content parts for Computer use.

Code and execution-result parts are carried in the corresponding assistant output
item's `providerMetadata.google.parts`. `output_text` contains only the final visible
text. Set `stream: true` for typed Responses SSE events, including text and function
argument deltas. Read [Streaming Responses](/api-reference/google/responses#streaming-responses)
for the event lifecycle. `background: true` remains rejected. Send the full
conversation history; Gemini does not resolve
`previous_response_id` server-side.

## Usage and billing

Every model request is metered, including turns that return only a tool call and
streamed completions. Gemini usage includes Code execution's intermediate tool input
tokens in `prompt_tokens` (Chat Completions) or `input_tokens` (Responses).
Cached prompt tokens retain their cache pricing; intermediate tool inputs use the
model's ordinary input price. Code execution has no separate execution fee.
User-defined functions and browser execution happen in your application.

See Google's [Function calling](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/tools/function-calling),
[Code execution](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/tools/code-execution), and
[Computer use](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/computer-use)
documentation for provider-specific tool limitations.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.