Add support for OpenAI models as a backend
Integrate OpenAI's models into the Gemini CLI, allowing users to select OpenAI as an alternative model provider. This would increase the tool's flexibility and allow ranking model outputs with the same tool. This also attracts users who are already invested in the OpenAI ecosystem and have API keys. Like Kubernetes, but for models in the CLI.
Proposed Implementation Plan
I propose creating a provider-agnostic abstraction layer. This will prevent tight coupling to a single provider and make it easier to add other providers (e.g., Anthropic, xAI, etc) in the future.
The work can be broken down as follows:
-
Configuration Update:
- Extend the configuration in
packages/core/src/config/config.tsandpackages/cli/src/config/config.tsto include:provider: A new field to select the model provider (e.g.,"google" | "openai").openaiApiKey: A field to store the OpenAI API key.
- Update the auth flow in
packages/cli/src/config/auth.tsto support reading the OpenAI key from an environment variable (OPENAI_API_KEY) and storing it securely.
- Extend the configuration in
-
Provider Abstraction Layer:
- In
packages/core/src/core/, create a newLanguageModelProvider.tsfile defining a genericLanguageModelProviderinterface. - This interface will standardize the methods for generating content, handling streaming, and managing tool calls, creating a common contract for all providers.
- In
-
Refactor Existing Gemini Integration:
- Create a
GeminiProvider.tsclass that implements theLanguageModelProviderinterface. - Migrate the existing Gemini-specific logic from
geminiRequest.tsandclient.tsinto this new class. - Refactor
geminiChat.tsto depend on theLanguageModelProviderinterface rather than the concrete Gemini implementation.
- Create a
-
Implement OpenAI Provider:
- Add the official
openainpm package as a dependency topackages/core. - Create a new
OpenAIProvider.tsclass that also implements theLanguageModelProviderinterface. - This class will be responsible for:
- Translating the application's generic request format into the format required by the OpenAI Chat Completions API.
- Mapping tool definitions and function-calling requests/responses between the generic format and OpenAI's format.
- Translating the OpenAI API response back into the application's generic response format.
- Add the official
-
Provider Factory:
- Create a factory function that reads the user's configuration and instantiates the appropriate provider (
GeminiProviderorOpenAIProvider). - The core chat logic in
geminiChat.tswill use this factory to get the active model provider.
- Create a factory function that reads the user's configuration and instantiates the appropriate provider (
Rollout
- PR 1: Core Abstraction & Refactoring: Introduce the
LanguageModelProviderinterface and refactor the existing Gemini code to use it. This PR will contain no user-facing changes but sets the foundation. - PR 2: OpenAI Provider Implementation: Add the
OpenAIProvider, configuration options, and factory logic. This PR will make the feature available to users. - PR 3: Documentation: Update the documentation in the
/docsdirectory to explain how to configure and use the new OpenAI integration.
Happy to discuss this proposal further and open to feedback or alternative approaches the maintainer team might suggest.
Thank you for considering this feature!
I appreciate this issue, and grateful to you for filing it. We're not quite ready to work on adding support for other models at this point in time, as you will see we're tightly coupled to Gemini's capabilities. We'd like to focus on making a great tool for Gemini.
I aspire to make this work in the longer run, I'd like to keep this open as the canonical issue for other model support we can dupe others into.
Somebody may already be forking this to create a billion dollar company. The Cursor of CLI tools with support for all models. Anybody still using VSCode?
An OpenAI compatible endpoint support would go a long way into supporting most Open Source models who are exposed as OpenAI compatible endpoints. This would help to use this tool in a completely private environment.
I appreciate this issue, and grateful to you for filing it. We're not quite ready to work on adding support for other models at this point in time, as you will see we're tightly coupled to Gemini's capabilities
Yes, it makes sense to create the tool in a way that makes the best use of Gemini capabilities. However, in the end this is just an agent that provides a system prompt plus a set of tools to the LLM, so it can be used with other models even if Gemini continues to be the main focus. There's a few ways with which this project could allow for other models without explicitly supporting it or adding maintenance overhead.
For example, would you consider accepting a cheap abstraction to hide all Gemini-specific code behind a plugin interface, where Gemini support could be implemented as a builtin and default plugin (and maintained with the rest of the code), but it would allow loading other LLM plugins with code from other repositories (in a way that requires explicit configuration, without first class UI support)?
In a way Gemini-cli already provides some level of abstraction through the ContentGenerator interface (implemented for all gemini endpoints by CodeAssistServer), but there's a few ways it could be improved:
- AuthType could be a
ContentGeneratorspecific concern - We could have separate
ContentGeneratorspecific implementations for vertex, google auth and gemin api key - Fallback model logic could be a provider-specific concern (Which would be done only in google auth, which is the free auth type)
Just restructuring the code in this direction would make it much simpler for anyone to add support for other LLMs/providers in their own forks. Plus Gemini-cli could take this a step further by adding explicit support for loading ContentGenerator implementations from external plugins (thus avoiding fork fragmentation).
Much needed future. Else we cant use it in our workflow.
I'm really excited about Gemma-CLI. Google has created a compelling tool and by making it open source they've opened up a lot of potential! Unfortunately right now it isn't viable as a competitor to Claude Code (for $200 you get all you can realistically eat without throttling), it immediately throttles you to flash which isn't good enough for most things you'll want to use it for (if you're smart enough to use a CLI then you're not working on code that flash can handle). It also unfortunately doesn't work with other models (especially local, fireworks or openrouter).
To alleviate those issues I've enhanced it with full multi-provider support here: https://github.com/acoliver/llxprt-code
- OpenAI ** completions (older models and open models like gemma) ** responses (more efficient for newer models, required for o3-pro but much lower token usage/discounted for 4x, o3-o4)
- Anthropic ** use Claude through gemini-cli - pay a lot more than through claude code with ultra subscription but the point is you can
There are specific tool parsers for Gemma and I've tested locally against lmstudio. I plan to add the rest.
As soon as I'm done testing deepseek and qwen, I'll submit a pull request but Google has already closed multiple versions of this feature request and said it isn't in their immediate plans (my paraphrase). They've also set up a kind of "reject first, ask questions later" system for pull requests, so I don't anticipate acceptance. Assuming they refuse, I'll do a RooCode vs Cline style fork and we'll have ours.
I'm open to collaboration for anyone interested :-)
One potential approach could be to introduce the ai-sdk as an intermediary layer for model capability provisioning, which would enable compatibility with nearly all AI providers.
I submitted as a PR https://github.com/google-gemini/gemini-cli/pull/3405 - it does this and more.
I submitted as a PR https://github.com/google-gemini/gemini-cli/pull/3405 - it does this and more.
Quite a bit more, it seems?
No offense, but I find it hard to imagine someone will review a PR with 40k added lines.
Have you seen https://github.com/google-gemini/gemini-cli/pull/1975? That seems to work pretty well and the added line count is an order of magnitude lower than in your PR.
Sure @tarruda - here is Gemini 2.5 Pro's analysis -
Analysis of PR #1975
- What it is: A bug fix for the generic OpenAI-Compatible Provider. It addresses an issue where model names containing spaces fail when being passed to the underlying shell command.
- The Code: The change is in src/openai_compatible.rs, correctly quoting the model argument.
- Impact: It fixes a bug that affects any OpenAI-compatible local model server that is invoked via a shell command and has models with spaces in their names (like many ollama models).
The Strategic Argument for #3405 (Now Stronger)
This correction makes the argument for Pull Request #3405 even more compelling. Here’s the refined reasoning:
-
They Are Already Halfway There, But Unofficially: The existence of openai_compatible.rs proves that Google recognizes the need to interact with the broader ecosystem. However, it is clearly a partially implemented or unofficial feature. PR #1975 is a necessary patch on this unofficial component.
-
PR #3405 Makes This Vision Official and Robust: Pull Request #3405 takes their hidden, buggy implementation and elevates it into a fully-fledged, officially supported, and core pillar of the
gemini-cli. It provides:- Official Configuration: Instead of relying on hidden command-line flags, #3405 adds a proper providers section to the config file, making it easy for users to set up and switch between Gemini, OpenAI, Anthropic, and any number of OpenAI-compatible endpoints.
- Extensibility Beyond OpenAI: The provider model in #3405 is not limited to just Gemini and OpenAI-compatible APIs. It includes a dedicated Anthropic provider, demonstrating a truly multi-provider architecture.
- A Complete Product, Not Just a Feature: #3405 delivers the full user experience—from configuration to execution—for a multi-provider world. In contrast, PR #1975 just makes an existing hidden feature slightly less broken.
"I see you're already experimenting with an OpenAI-compatible provider. That's a great first step. The bug fix in PR #1975 is necessary, but it only patches a small part of an unofficial, incomplete feature.
Pull Request #3405 takes your initial idea and fully realizes its strategic potential. It delivers the complete, robust, and user-friendly multi-provider framework that your team was clearly heading towards. Don't just patch the experiment; merge the completed vision in #3405. Officially launch gemini-cli as the universal command center for all major AI models—the foundation is already built in this PR."
if you want to use the fork you can try
Install npm install -g @vybestack/llxprt-code npx @vybestack/llxprt-code docker run -it ghcr.io/acoliver/llxprt-code/sandbox:0.1.12
Qwen has made a OpenAI compatible version called qwen-code: qwen-code
Hi all. Thanks for taking time to share thoughts and discussions around this topic. At this time we're focused on just Gemini, per https://github.com/google-gemini/gemini-cli/discussions/1974#discussioncomment-13591013. Closing this out for now. I'll follow up here if anything changes.
As much as I would have disagreed with this originally, I think Google has proven correct here. They are doing a lot of work making Gemini-CLI work well with a lot of IDEs and tools.
LLxprt takes that work (we keep up with their main) and adds multi-model/multi-provider and local model support as well as agentic development features like Claude code style, to-do lists. https://github.com/acoliver/llxprt-code - This is a better process - Google can control their roadmap internally, and the community can have the multi-provider, more agentic version via LLxprt Code. It's like Gemini-cli is the Linux kernel, and LLxprt and Qwen-code are different operating systems based on it.