Skip to content

feat(llm): native Google Gemini provider via OpenAI-compatible endpoint#57

Merged
elder-plinius merged 1 commit into
elder-plinius:mainfrom
jmagly:fix/gemini-native-provider
Jul 9, 2026
Merged

feat(llm): native Google Gemini provider via OpenAI-compatible endpoint#57
elder-plinius merged 1 commit into
elder-plinius:mainfrom
jmagly:fix/gemini-native-provider

Conversation

@jmagly

@jmagly jmagly commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #52.

What's broken

src/config/index.ts advertises provider: 'Google' Gemini models, but there is no way to actually run Gemini with a direct key: 'google'/'gemini' isn't a member of the LLMProvider union and createAdapter() has no matching case, so it falls through to default → throw "Unknown LLM provider". Setting a Gemini key just leaves LLM features disabled. (The google/gemini-* ids under openrouter do work — but only through an OpenRouter key, not a direct Gemini key.)

The fix

Add a first-class gemini provider, wired exactly like the existing xAI provider: dispatched through OpenAIAdapter against Google's OpenAI-compatible surface. No new adapter class needed.

The one detail that matters: the base URL is https://generativelanguage.googleapis.com/v1beta/openai. OpenAIAdapter posts to `${baseUrl}/chat/completions`, so the /openai path segment is required — with a bare /v1beta base, requests resolve to /v1beta/chat/completions, which Google does not serve (that root is the native generateContent REST API, not the OpenAI shim). A regression test pins this exact path.

Selection: LLM_PROVIDER=gemini + GEMINI_API_KEY.

Changes

  • src/types/index.ts — add 'gemini' to LLMProvider
  • src/llm/index.tscase 'gemini' → OpenAIAdapter
  • src/config/index.ts — interface, defaults (correct /v1beta/openai base URL, gemini-2.5-flash default), native model catalog (bare ids), GEMINI_API_KEY env map, getLLMConfig, fallback chain, redaction, .env template
  • src/__tests__/gemini-provider.test.ts — regression tests, including the /openai base-URL guard

Verification

  • npm run typecheck — clean
  • npm test — 371 passing (34 files), incl. 4 new Gemini tests
  • npm run lint — 0 errors

Relation to existing PRs

This overlaps #55 and #45, which also add Gemini. It differs deliberately: #55 sets the base URL to .../v1beta (missing /openai), so OpenAI-shaped calls would hit an endpoint Google doesn't serve; #45 introduces a LiteLLM gateway (a larger architectural dependency). This PR is the minimal native fix that matches the repo's existing xAI OpenAI-compat pattern. Happy to close in favor of either if a maintainer prefers that direction — flagging the base-URL detail regardless, since it's easy to miss.

Add a first-class `gemini` provider so operators can drive missions with a
direct GEMINI_API_KEY, instead of only reaching Gemini through OpenRouter.

Gemini is wired exactly like xAI: dispatched through OpenAIAdapter against
Google's OpenAI-compatible surface. The base URL is
https://generativelanguage.googleapis.com/v1beta/openai — the `/openai`
segment is required because OpenAIAdapter posts to `${baseUrl}/chat/completions`;
without it requests hit `/v1beta/chat/completions`, which Google does not serve.

Wires the provider through the type union, adapter factory, config
(interface, defaults, model catalog, key env map, getLLMConfig, fallback
chain, redaction, .env template), and adds regression tests pinning the
`/openai` base-URL segment.
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.

[Feature Request/Bug] Complete Native Google Gemini Integration (Dead Metadata in src/config/index.ts)

2 participants