Skip to content

feat: native Google provider (Gemini API and Vertex AI) - #139

Merged
anhnh2002 merged 13 commits into
FSoft-AI4Code:mainfrom
albertsikkema-elix:feat/native-google-gemini-api-vertex-ai
Oct 22, 2026
Merged

anhnh2002 merged 13 commits into
FSoft-AI4Code:mainfrom
albertsikkema-elix:feat/native-google-gemini-api-vertex-ai

Conversation

@albertsikkema-elix

Copy link
Copy Markdown
Contributor

Closes #138.

  • Adds google (Gemini API / AI Studio) and google-vertex
    (Vertex AI) as native providers, using the google-genai SDK
    directly instead of routing through the OpenAI-compatible shim
  • Fixes Gemini 3.x compatibility: thought signatures are
    round-tripped correctly via pydantic-ai's GoogleModel
  • Vertex AI is ~50x cheaper than Opus for doc generation ($0.05 vs
    $0.32-$22.75 per repo in a four-repo trial)

Changes

New module: codewiki/src/be/google_provider.py

  • create_client(): builds a genai.Client for either provider
    (API key for google, ADC for google-vertex)
  • create_google_model(): wraps the client in pydantic-ai's
    GoogleModel via GoogleProvider(client=...) (works on both
    pydantic-ai 1.x and 2.x)
  • call_google(): sync one-shot completions (callers run inside an
    active event loop, so async model_request_sync would deadlock)
  • check_access(): credential validation against the model metadata
    endpoint
  • Cost tracking via genai-prices through pydantic-ai's
    ModelResponse.cost()

Config changes:

  • codewiki/src/config.py: google_project, google_location
    fields
  • codewiki/cli/models/config.py: serialization, validation,
    is_complete() updates
  • codewiki/cli/config_manager.py: Google-aware validation gating
    (no API key required for Vertex, no base URL for either)
  • codewiki/cli/commands/config.py: --provider google|google-vertex,
    --google-project, --google-location options; config show and
    config validate branches for Google providers

Integration:

  • codewiki/src/be/backend.py: GOOGLE_PROVIDERS set,
    is_google_provider(), needs_api_key(), needs_base_url()
  • codewiki/src/be/llm_services.py: Google branch in
    create_main_model / create_fallback_model / call_llm
  • codewiki/src/be/pydantic_ai_backend.py: _run_usage_with_cost()
    for Google agent-loop cost tracking
  • pyproject.toml: google-genai dependency

Docs: guides/providers.md, guides/cli-reference.md,
guides/development.md, README.md, CHANGELOG.md

Test results

17 new tests across two files:

  • tests/test_google_config.py (11 tests): provider config,
    validation, serialization, is_complete(), needs_api_key(),
    needs_base_url()
  • tests/test_google_provider.py (6 tests): model normalisation,
    client creation, call_google usage extraction, cost tracking

All 332 tests pass (existing + new). No changes to existing test
files.

Live tested on Vertex AI (google-vertex, gemini-3.8-flash,
eu and global locations) against real repositories.

Breaking changes

None. Existing providers (openai, anthropic, bedrock) are unaffected.
The google-genai dependency is new but optional at runtime for
non-Google providers.

Notes for reviewers

  • GoogleProvider(client=genai.Client(...)) is used instead of
    GoogleProvider(vertexai=True) because the latter only exists in
    pydantic-ai 1.x; the client form works on both 1.x and 2.x.
  • Vertex AI never receives an API key in create_client() to
    prevent the SDK from switching to Express Mode.
  • The genai client must be assigned to a variable before use (not
    created inline) to prevent Python GC from closing the underlying
    httpx client mid-request.
  • trial.sh is included for testing convenience but can be excluded
    from the merge if preferred.

albertsikkema-elix and others added 13 commits October 20, 2026 15:45
Add google and google-vertex providers to config set, with Vertex AI
project/location fields. Vertex needs neither an API key nor a base
URL; the Gemini API key is read from GEMINI_API_KEY/GOOGLE_API_KEY.
Agent loops run on pydantic-ai's GoogleModel so Gemini 3 thought
signatures survive tool-call turns; one-shot calls use the sync
google-genai client. Gemini runs record a priced cost_usd.
config validate probes Google access without sending a Gemini key to an
OpenAI endpoint; config show lists the Vertex project and location.
The inline create_client(...).models.get() let Python garbage-collect
the Client before the request completed, closing the httpx transport.
Same GC issue as check_access: the client created by
_client_for() was used inline, so Python could collect
it before the HTTP request completed.
- Switching from google/google-vertex to another provider resets the
  auto-set Gemini fallback model to glm-4p5 unless --fallback-model is given.
- call_google reuses one sync genai client per credential set instead of
  building a client per call; agent-loop models still get a fresh client.
- The non-top-tier cluster model hint now names current model families.
@anhnh2002
anhnh2002 merged commit d079769 into FSoft-AI4Code:main Oct 22, 2026
2 checks passed
@anhnh2002

Copy link
Copy Markdown
Collaborator

Thanks @albertsikkema-elix, nice work! I pushed two small commits to your branch to fix minor points.

@albertsikkema-elix

Copy link
Copy Markdown
Contributor Author

Thanks, glad to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: native Google provider (Gemini API and Vertex AI)

2 participants