Skip to content

feat(core): Support OpenAI-compatible API endpoints for multi-provider workflows #23385

Closed

Description

@netbrah

Problem

Gemini CLI currently only works with Google's Gemini API. Users who want to use the excellent tooling, agent loop, and MCP integration with other models (OpenAI GPT, Anthropic Claude, local models via Ollama/vLLM) cannot do so.

This is the most requested capability for extending gemini-cli's reach. Projects like Qwen Code (a fork) have already proven demand by shipping multi-provider support.

Proposed Solution

Add an OpenAIContentGenerator that implements the existing ContentGenerator interface, translating between Gemini's native Content/Part format and OpenAI's Chat Completions API.

Activation: Set two environment variables:

export OPENAI_COMPATIBLE_ENDPOINT="https://api.openai.com"
export OPENAI_COMPATIBLE_API_KEY="sk-..."
export OPENAI_COMPATIBLE_MODEL="gpt-4o"  # optional

What it enables:

  • OpenAI (GPT-4o, o1, o3, GPT-5)
  • Anthropic Claude (via OpenAI-compatible proxies like LiteLLM)
  • Local models (Ollama, vLLM, llama.cpp)
  • Corporate LLM gateways
  • Any OpenAI-compatible API

Architecture (zero disruption to existing Gemini flow):

  • New OpenAIContentGenerator class implementing ContentGenerator
  • Factory detection in createContentGenerator() — env vars present → OpenAI path, otherwise → existing Gemini path unchanged
  • Full streaming via SSE parsing with tool call accumulation
  • Model-aware max_tokens defaults to prevent output truncation
  • Pre-send context budget enforcement for smaller context windows
  • Token limits expanded for Claude (200K), GPT-4o (128K), o1/o3 (200K)

What stays unchanged:

  • All Gemini-native functionality
  • Auth flows (OAuth, API key, Vertex AI, ADC)
  • The agent loop, MCP integration, tools — all work identically

I have a PR ready with full test coverage (17 tests).

Activity

  1. added
    status/need-triageIssues that need to be triaged by the triage automation.
    area/agentIssues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality
    on Mar 21, 2026
  2. gemini-cli commented on Mar 21, 2026

    @gemini-cli
    Contributor

    Found possible duplicate issues:

    If you believe this is not a duplicate, please remove the status/possible-duplicate label.

  3. added
    area/coreIssues related to User Interface, OS Support, Core Functionality
    effort/medium2-3 days: UI state, async flow, cross-component refactors
    priority/p2Important but can be addressed in a future release.
    and removed
    status/need-triageIssues that need to be triaged by the triage automation.
    on May 9, 2026
  4. gemini-cli commented on May 9, 2026

    @gemini-cli
    Contributor

    A highly requested feature to allow the CLI to use OpenAI-compatible API endpoints.

    Effort Analysis:
    Adding support for an OpenAI-compatible endpoint involves implementing the ContentGenerator interface and handling streaming via SSE parsing. This requires resolving asynchronous flows and tool execution integration within the core architecture, mapping to effort/medium.

  5. Adib234 commented on May 9, 2026

    @Adib234
    Contributor

    Thank you for bringing this to our attention. Right now, our engineering team is focusing all resources on critical system maintenance and core stability. Because of this, we don't have immediate plans to address this specific issue, but we truly appreciate you flagging it for us.

  6. WuJunkai2004 commented on May 31, 2026

    @WuJunkai2004

    I write a https://github.com/WuJunkai2004/api-for-gemini for routing gemini cli's request to custom model provider, it may help you.

  7. jaroslawjanas commented on Jun 11, 2026

    @jaroslawjanas

    Thank you for bringing this to our attention. Right now, our engineering team is focusing all resources on critical system maintenance and core stability. Because of this, we don't have immediate plans to address this specific issue, but we truly appreciate you flagging it for us.

    Yeah you have been saying this for almost a year now. I checked the issues.
    Clearly this is just corporate speak for no.
    You don't even have the guts to say it outright and I find it borderline offensive.
    Don't Be Evil

  8. smallcaseclassicking commented on Aug 24, 2026

    @smallcaseclassicking

    Thank you for bringing this to our attention. Right now, our engineering team is focusing all resources on critical system maintenance and core stability. Because of this, we don't have immediate plans to address this specific issue, but we truly appreciate you flagging it for us.

    Yeah you have been saying this for almost a year now. I checked the issues. Clearly this is just corporate speak for no. You don't even have the guts to say it outright and I find it borderline offensive. Don't Be Evil

    I checked past issues and saw they were just repeating the same phrase, so I created my own fork.

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/agentIssues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Qualityarea/coreIssues related to User Interface, OS Support, Core Functionalityeffort/medium2-3 days: UI state, async flow, cross-component refactorskind/featurepriority/p2Important but can be addressed in a future release.status/bot-triagedstatus/possible-duplicate

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions