The interface and design decisions behind the Gemini AI client.
The SDK wraps the Google Gemini SDK (google-genai) with a clean Python interface. It handles API key management, caching, error recovery, and model selection.
It was extracted from the Alma project. The original code lived inside a Flask application with hardcoded model names, framework coupling, and a Go service dependency. The extraction removed all of that.
ModelConfig dataclass, not hardcoded as module constants. Different products can use different models._is_recoverable_api_error catches all exceptions except programming errors (TypeError, NameError, etc.). The SDK returns synthetic text for API failures instead of raising. Real bugs still propagate.response.text. The Gemini SDK returns empty strings without raising. The SDK returns a placeholder instead of failing silently.generate_text(prompt) # Simple text
generate_chat(messages) # Chat with history
generate_text_with_thinking(p) # Text + reasoning
generate_chat_with_thinking(m) # Chat + reasoning
generate_text_with_url_context(p) # Text + URL context
generate_chat_with_url_context(m) # Chat + URL context
text_to_speech(text) # Text to MP3
generate_image(prompt) # Image generation
research_topic(topic) # Deep research
Three providers via ImageProviderRegistry:
gemini-2.5-flash-image.google-cloud-aiplatform.Found something unexpected? Report an issue.