Cameleer

Gemini component

The gemini component calls Google's Gemini models through the Gemini API (Google AI Studio, API keys), with tool calling: with tags it runs your ai-tool routes for the model, and it is a model for the agent step.

Scheme: gemini: · Crate: cameleer-saas · Cargo feature: saas · Consumer: no · Producer: yes · Apache Camel: no direct equivalent (Camel reaches Gemini through LangChain4j or google-vertexai)

When to use it

  • Call Gemini with an API key, without a Google Cloud project or service account.
  • Give Gemini your routes as tools, with argument checks, approvals and an audit log (ai-tool).
  • Use Gemini as the model of an agent step.

For Vertex AI (service accounts, regions, VPC) use google-vertexai. For Gemini's OpenAI-compatible API use openai:chat-completion?provider=gemini; this component keeps what that API drops, such as thought signatures.

URI format

text
gemini:generate[?options]

Example

yaml example: gemini-tools
- route:
    from:
      uri: direct:ask
      steps:
        - to: "gemini:generate?model=gemini-2.5-flash&apiKey={{env:GEMINI_API_KEY}}&systemMessage=You are a support agent.&tags=support"

A text body is the user's message and becomes the answer. With tags, the model can call the ai-tool routes with those tags; each functionCall runs through the ai-tool envelope and its thoughtSignature is sent back with it, as Gemini requires.

Options

optiondefaultdescription
modelrequiredThe model, such as gemini-2.5-flash (the CamelGeminiModel header overrides it)
apiKeyGEMINI_API_KEY, then GOOGLE_API_KEY envSent as x-goog-api-key
baseUrlhttps://generativelanguage.googleapis.comThe API base URL (a gateway or proxy)
systemMessageThe system instruction (the CamelGeminiSystemMessage header overrides it)
maxTokensgenerationConfig.maxOutputTokens
temperaturegenerationConfig.temperature
timeout120sHTTP timeout
tags, autoToolExecution, maxToolIterations, maxAgenticTokens, parallelToolExecution, hallucinatedToolNameStrategy, record, replayTool calling, as on every model component (the options)
maxRetries, retryDelay, fallbackModels, responseCache, responseCacheTtl, responseCacheSize, coalesceRetries, fallbacks, response cache and coalescing (model providers)

Message headers

headerdirectiondescription
CamelGeminiSystemMessageinThe system instruction
CamelGeminiModelinThe model for this call
CamelGeminiFinishReasonoutMap bodies: the first candidate's finishReason
CamelGeminiPromptTokenCount, CamelGeminiCandidatesTokenCountoutToken usage (all turns of a tool loop)
CamelAiAgentTurns, CamelAiAgentToolCalls, CamelAiAgentStopReason, CamelAiAgentTotalTokensoutThe tool loop
CamelAiCacheReadTokensoutInput tokens served from Gemini's implicit cache (when there were any)
CamelAiRequestedToolCallsoutWith autoToolExecution=false: the calls Gemini asked for

Bodies: a text body is one user message; a list body is the message list ({"role", "content"}); a map body is sent as the whole generateContent request and the whole response becomes the body.

Common questions

What happens on an API error?

The exchange fails with HttpOperationFailedException and the API's error message (for example API key not valid). 429 and 5xx answers are retried first (maxRetries).

Can I test routes that use it without calling Gemini?

Yes. Record the responses once (record=file:gemini.jsonl) and replay them (replay=...); cameleer test runs the route against them (testing without a model). cameleer_saas::testing::GeminiMock is a mock of the API for Rust tests: it scripts tool calls and rejects a functionCall sent back without its thought signature.

Found a problem?

If something on this page doesn't match what Cameleer does, please open an issue, or fork the repository, fix it, add a test, run cargo test --workspace and open a pull request.

Edit this page on GitHub