Skip to content

Add support for OpenAI models as a backend #1605

Closed

Description

@infocusmodereal

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:

  1. Configuration Update:

    • Extend the configuration in packages/core/src/config/config.ts and packages/cli/src/config/config.ts to 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.ts to support reading the OpenAI key from an environment variable (OPENAI_API_KEY) and storing it securely.
  2. Provider Abstraction Layer:

    • In packages/core/src/core/, create a new LanguageModelProvider.ts file defining a generic LanguageModelProvider interface.
    • This interface will standardize the methods for generating content, handling streaming, and managing tool calls, creating a common contract for all providers.
  3. Refactor Existing Gemini Integration:

    • Create a GeminiProvider.ts class that implements the LanguageModelProvider interface.
    • Migrate the existing Gemini-specific logic from geminiRequest.ts and client.ts into this new class.
    • Refactor geminiChat.ts to depend on the LanguageModelProvider interface rather than the concrete Gemini implementation.
  4. Implement OpenAI Provider:

    • Add the official openai npm package as a dependency to packages/core.
    • Create a new OpenAIProvider.ts class that also implements the LanguageModelProvider interface.
    • 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.
  5. Provider Factory:

    • Create a factory function that reads the user's configuration and instantiates the appropriate provider (GeminiProvider or OpenAIProvider).
    • The core chat logic in geminiChat.ts will use this factory to get the active model provider.

Rollout

  • PR 1: Core Abstraction & Refactoring: Introduce the LanguageModelProvider interface 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 /docs directory 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!

Activity

  1. cperry-goog commented on Jun 25, 2025

    @cperry-goog
    Contributor

    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.

  2. gerrywastaken commented on Jun 25, 2025

    @gerrywastaken

    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?

  3. added
    status/need-triageIssues that need to be triaged by the triage automation.
    on Jun 26, 2025
  4. arpanpreneur commented on Jun 26, 2025

    @arpanpreneur

    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.

  5. added
    priority/p3Backlog - a good idea but not currently a priority.
    area/coreIssues related to User Interface, OS Support, Core Functionality
    and removed
    status/need-triageIssues that need to be triaged by the triage automation.
    on Jun 26, 2025
  6. tarruda commented on Jun 27, 2025

    @tarruda

    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 ContentGenerator specific concern
    • We could have separate ContentGenerator specific 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).

  7. ksecurity45 commented on Jun 29, 2025

    @ksecurity45

    Much needed future. Else we cant use it in our workflow.

  8. acoliver commented on Jul 2, 2025

    @acoliver

    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 :-)

  9. six-ddc commented on Jul 6, 2025

    @six-ddc

    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.

  10. acoliver commented on Jul 6, 2025

    @acoliver

    I submitted as a PR #3405 - it does this and more.

  11. tarruda commented on Jul 6, 2025

    @tarruda

    I submitted as a PR #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 #1975? That seems to work pretty well and the added line count is an order of magnitude lower than in your PR.

  12. acoliver commented on Jul 6, 2025

    @acoliver

    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:

    1. 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 support openai like api #1975 is a necessary patch on this unofficial component.

    2. PR Multi provider #3405 Makes This Vision Official and Robust: Pull Request Multi provider #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, Multi provider #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 Multi provider #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: Multi provider #3405 delivers the full user experience—from configuration to execution—for a multi-provider world. In contrast, PR support openai like api #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."

  13. acoliver commented on Jul 19, 2025

    @acoliver

    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

  14. TommrraraSnow commented on Jul 23, 2025

    @TommrraraSnow

    Qwen has made a OpenAI compatible version called qwen-code: qwen-code

  15. mattKorwel commented on Aug 1, 2025

    @mattKorwel
    Collaborator

    Hi all. Thanks for taking time to share thoughts and discussions around this topic. At this time we're focused on just Gemini, per #1974 (comment). Closing this out for now. I'll follow up here if anything changes.

  16. acoliver commented on Aug 1, 2025

    @acoliver

    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.

  17. added 2 commits that reference this issue on May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreIssues related to User Interface, OS Support, Core Functionalitypriority/p3Backlog - a good idea but not currently a priority.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions