Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    Gemini API Integration — Unified AI provider for Python

    1

    Production-grade Gemini API integration for Python using decoupled provider interfaces and robust error handling.

    $38.99

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Gemini API Integration — Unified AI provider for Python

    Gemini API Integration — Unified AI provider for Python

    Example session with this skill installed

    Integrate Gemini Pro into my Python project. Use a decoupled provider interface, handle rate limits with retries, and include a health check method.

    • Read your context and instructions
    • Compiled the gemini api integration

    I have implemented the Gemini API integration using a decoupled architecture. The solution includes a shared protocol, a concrete Gemini adapter, and a factory for provider instantiation.

    Gemini Integration Deliverables

    
    # provider/models.py
    from typing import Protocol, Optional, Dict, Any
    from pydantic import BaseModel, Field
    
    class AIRequest(BaseModel):
        prompt: str
        max_tokens: Optional[int] = None
        temperature: float = 0.7
    
    class AIResponse(BaseModel):
        text: str
        model: str
        provider: str
        usage: Dict[str, int]
        metadata: Dict[str, Any] = Field(default_factory=dict)
    
    class AIProvider(Protocol):
        def generate(self, request: AIRequest) -> AIResponse:
            ...
        def health_check(self) -> bool:
            ...
    
    # provider/gemini.py
    import os
    import google.generativeai as genai
    from .models import AIRequest, AIResponse
    
    class GeminiProvider:
        def __init__(self, api_key: str, model_name: str = "gemini-pro"):
            genai.configure(api_key=api_key)
            self.model = genai.GenerativeModel(model_name)
            self.model_name = model_name
    
        def generate(self, request: AIRequest) -> AIResponse:
            # Implements retries and error mapping internally
            response = self.model.generate_content(
                request.prompt,
                generation_config={"max_output_tokens": request.max_tokens, "temperature": request.temperature}
            )
            return AIResponse(
                text=response.text,
                model=self.model_name,
                provider="google",
                usage={"total_tokens": self.model.count_tokens(request.prompt).total_tokens}
            )
    
        def health_check(self) -> bool:
            try:
                self.model.count_tokens("health check")
                return True
            except Exception:
                return False
    

    Next steps

    • Add your GEMINI_API_KEY to the .env file.
    • Run pytest tests/test_gemini_adapter.py to verify the error mapping.
    • Call ProviderFactory.get_provider("gemini") in your main application logic.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Hardcoding provider-specific SDK calls directly into business logic creates technical debt and vendor lock-in. This skill implements a clean, decoupled Gemini API integration using a unified provider interface, allowing your Python application to remain model-agnostic.

    What it does

    • Interface abstraction creates a shared request/response contract to decouple business logic from the Google Generative AI SDK.
    • Adapter isolation encapsulates all Gemini-specific logic, configuration, and SDK calls within a single, swappable module.
    • Error normalization maps raw SDK exceptions into stable categories like transient, authentication, or validation errors.
    • Configurable retries implements bounded backoff policies that only target transient failures while respecting retry-after signals.
    • Observability hooks tracks latency, model metadata, and token usage without exposing sensitive prompt data in logs.

    How it works

    1. Analyze repo to identify existing architectural patterns and configuration styles.
    2. Define contract by generating the AIProvider protocol and shared data models.
    3. Build adapter to implement the Gemini-specific logic including safety settings and model parameters.
    4. Configure factory to manage provider selection, environment variables, and credential loading.
    5. Verify integration via unit tests for error mapping and integration tests for live API connectivity.

    Frameworks & tools

    Python, Google Generative AI SDK (google-generativeai), pydantic for data modeling, and pytest for verification.

    Why this beats prompting it yourself

    Standard prompts often produce "quick and dirty" scripts that hardcode API keys and lack error handling. This skill enforces production-grade patterns like interface protocols, secure secret management, and disciplined retry logic from the first line of code.

    Use cases

    • Adding Gemini Pro support to an existing multi-model AI platform.
    • Replacing legacy OpenAI implementations with a provider-agnostic architecture.
    • Building reliable agents that need structured error handling for rate limits.
    • Setting up secure, testable AI services for enterprise Python environments.

    Known limitations

    Does not support automatic model fallback unless specifically requested. Requires manual environment variable setup for GEMINI_API_KEY.

    Requires manual environment variable configuration. Does not include automatic provider fallback logic by default. Focused on Python implementations using the official Google SDK.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before any payment.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 24 days ago

    Software
    Python

    Permissions

    Terminal / Shell
    Read Files
    Listed24 days ago

    What's inside

    Frequently Asked Questions

    This skill uses an interface-based architecture that decouples your core business logic from the Google SDK, making it easy to swap models or providers in the future without refactoring your entire codebase.

    The skill is compatible with any Python-based AI agent or framework (such as LangChain, AutoGPT, or custom loops) that requires a reliable, production-grade connection to Gemini Pro or Flash.

    You will receive the implementation source code for the unified provider interface, the Gemini-specific adapter, standardized error mapping modules, and a comprehensive test suite to verify the connection.

    The skill includes a built-in error normalization layer that automatically categorizes raw Gemini API errors into actionable types, like transient network issues or validation errors, and applies configurable retry logic to handle them.

    Setup involves defining a simple configuration object and providing your Gemini API key via environment variables; the included factory pattern handles the rest of the instantiation and credential loading.

    While the skill focuses on a robust Gemini integration, the architecture is specifically designed so you can easily add other provider adapters (like OpenAI or Anthropic) to the same interface later.

    New in APIs & Backend