Skip to content

Comments

feat: add Gemini API support to OpenAI provider#20

Merged
douglaz merged 1 commit intomasterfrom
feat/gemini-support
Aug 30, 2025
Merged

feat: add Gemini API support to OpenAI provider#20
douglaz merged 1 commit intomasterfrom
feat/gemini-support

Conversation

@douglaz
Copy link
Owner

@douglaz douglaz commented Aug 30, 2025

Summary

Adds support for Google Gemini models through the OpenAI-compatible API endpoint, enabling the use of advanced models like Gemini 2.5 Flash and 2.5 Pro.

Changes

  • Added support for GEMINI_API_KEY environment variable as a fallback option
  • Automatically fixes Gemini API URLs to include the required /chat/completions endpoint
  • Updated error messages to reflect support for both OpenAI and Gemini APIs

Technical Details

The Gemini API provides an OpenAI-compatible endpoint at https://generativelanguage.googleapis.com/v1beta/openai/. This change detects when this URL is used and automatically appends /chat/completions if needed, ensuring compatibility with the existing OpenAI provider implementation.

Testing

  • All existing tests pass
  • Manually tested with Gemini 2.5 Flash model in the Fedimint challenge
  • Agent successfully connects and uses Gemini for reasoning

Benefits

  • Access to Gemini's latest models including 2.5 Flash (fast, efficient) and 2.5 Pro (advanced reasoning)
  • No need for a separate Gemini provider - reuses existing OpenAI infrastructure
  • Seamless switching between OpenAI and Gemini models via configuration

Configuration Example

[llm]
provider = "openai"
model = "gemini-2.5-flash"
api_url = "https://generativelanguage.googleapis.com/v1beta/openai"
api_key = "YOUR_GEMINI_API_KEY"
temperature = 0.3
max_tokens = 8000

- Support GEMINI_API_KEY environment variable as fallback
- Automatically fix Gemini endpoint URLs to include /chat/completions
- Enables using Gemini models (2.5 Flash, 2.5 Pro) via OpenAI-compatible API
- Tested with Gemini 2.5 Flash successfully
@douglaz douglaz merged commit a30b139 into master Aug 30, 2025
4 checks passed
@douglaz douglaz deleted the feat/gemini-support branch August 30, 2025 21:52
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.

1 participant