GeminiProvider wraps the google-genai SDK to connect Logicore to Google’s Gemini family of models. Gemini is natively multimodal — text, images, and function calls are first-class inputs — and supports some of the largest context windows available (up to 2M tokens on Gemini 1.5 Pro).
Installation
Set your API key
- GEMINI_API_KEY
- GOOGLE_API_KEY (alias)
- Pass directly
Constructor parameters
The Gemini model ID to use. Examples:
"gemini-1.5-flash", "gemini-1.5-pro", "gemini-2.5-pro", "gemini-2.0-flash". Check the Google AI model catalog for the current list.Your Gemini API key. If omitted, the provider reads
GEMINI_API_KEY then GOOGLE_API_KEY from the environment. Raises ValueError if neither is found.Basic usage
system_message are automatically mapped to Gemini’s system_instruction field.
Streaming
GeminiProvider runs the Gemini streaming API in a thread executor to keep the asyncio event loop unblocked:
chat_stream returns a dict with role, content, and optionally tool_calls once all tokens have been received.
Tool calling
Logicore converts standard tool definitions to GeminiFunctionDeclaration objects automatically:
call_<function_name> and tool results are returned to Gemini as FunctionResponse parts in the conversation history.
Vision / multimodal
All Gemini models support images natively. Pass image parts alongside text:image_url values:
- Local file path
https://image URLdata:image/...;base64,...inline data
How Gemini-specific formatting works
TheGeminiGateway handles several format differences transparently:
| Concern | How it is handled |
|---|---|
| System messages | Extracted and passed as system_instruction in GenerateContentConfig |
| Tool definitions | Converted to FunctionDeclaration objects in a Tool config |
| Tool results | Returned as Content(role="tool", parts=[FunctionResponse(...)]) |
| Assistant role | Mapped to Gemini’s "model" role in Content objects |
Troubleshooting
ValueError: Gemini/Google API key is required
ValueError: Gemini/Google API key is required
Neither
api_key nor GEMINI_API_KEY/GOOGLE_API_KEY is set. Get a free key at aistudio.google.com and export it.ValueError: Gemini returned an empty response
ValueError: Gemini returned an empty response
The model may have triggered a safety filter or the prompt produced no output. Try rephrasing the request or check the Gemini safety settings for your API key.
ValueError: Gemini model does not support this image/data type
ValueError: Gemini model does not support this image/data type
You are passing an image to a model or API version that does not support vision. Ensure you are using
gemini-1.5-flash, gemini-1.5-pro, gemini-2.0-flash, or gemini-2.5-pro.Tool calls not working / missing function responses
Tool calls not working / missing function responses
Gemini requires tool responses to be returned as
FunctionResponse parts, not plain text. Logicore handles this automatically when tools are registered on Agent. If you are calling provider.chat() directly, ensure your conversation history follows the Gemini format (role "tool" with the correct name field).ResourceExhausted: 429 quota exceeded
ResourceExhausted: 429 quota exceeded
The free tier has per-minute and per-day limits. Upgrade to a pay-as-you-go plan in the Google Cloud Console or add exponential back-off in your application code.