Skip to content

feat: add native Gemini support to openai_compat provider#3049

Open
Ajinkya-Kardile wants to merge 3 commits into
ultraworkers:mainfrom
Ajinkya-Kardile:main
Open

feat: add native Gemini support to openai_compat provider#3049
Ajinkya-Kardile wants to merge 3 commits into
ultraworkers:mainfrom
Ajinkya-Kardile:main

Conversation

@Ajinkya-Kardile
Copy link
Copy Markdown

Description

This PR enables native integration with Google Gemini by updating the wire_model_for_base_url logic in the openai_compat provider.

Previously, when using a custom OPENAI_BASE_URL (such as the Google Generative Language API endpoint), claw-code would preserve the openai/ prefix in the outgoing JSON payload. This caused API requests to fail because the Google API does not recognize model identifiers like:

models/openai/gemini-....

This change adds gemini to the stripping logic, ensuring that model slugs are correctly normalized to the format expected by the Google Gemini API while maintaining compatibility for other OpenAI-compatible gateways.


Commands Run

To verify this change, the following commands were executed inside the rust/ workspace:

cargo fmt --all --check

✅ Passed

cargo clippy --workspace

✅ Passed

cargo test --workspace

✅ Passed


Manual Verification

Environment

export OPENAI_BASE_URL="https://generativelanguage.googleapis.com/v1beta/openai/"

Command Executed

./target/release/claw --model openai/gemini-2.5-flash prompt "reply with ready"

Result

✅ Successfully received a response from Gemini.


Compatibility Risks

CLI / Provider Behavior

This changes how openai/ model slugs are sanitized when a non-default OPENAI_BASE_URL is detected.

The logic specifically targets models containing "gemini" to avoid prefix corruption while preserving compatibility with existing OpenAI-compatible providers.

Windows / PowerShell

No changes were made to build scripts, shell integrations, or documentation.

The modification is isolated entirely within the Rust api crate.


Known Gaps

None.

This implementation follows the existing normalization pattern already used for providers such as:

  • xai
  • qwen
  • kimi

and adheres to the current crate boundaries and provider architecture.

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