gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

Add support for local/offline language models (Ollola, LM Studio, etc.)

Open shivas1432 opened this issue 1 year ago • 14 comments

What would you like to be added?

Support for local language models like Ollama, LM Studio, and other offline AI models that can run on-premises without cloud connectivity.

Why is this needed?

Enterprise organizations with strict data privacy requirements cannot use cloud-based AI services due to regulatory compliance (HIPAA, SOX, PCI-DSS, GDPR). Financial institutions, healthcare companies, government agencies, and defense contractors are prohibited from sending code or sensitive data to external cloud services. Recent security incidents have made enterprises even more cautious about cloud AI:

The Samsung incident where employees accidentally leaked source code to ChatGPT JPMorgan Chase restricting ChatGPT usage after code exposure concerns Multiple healthcare organizations blocking AI tools due to HIPAA violations

Meanwhile, local models like CodeLlama, StarCoder, and DeepSeek-Coder have reached production quality and can run effectively on modern hardware. Tools like Ollama make local model deployment trivial, but there's no way to integrate them with Gemini CLI. This creates a massive adoption barrier - entire enterprise development teams (thousands of potential users) cannot adopt Gemini CLI despite wanting to use it. Local model support would unlock this market while maintaining the superior UX that Gemini CLI provides.

Additional context

No response

shivas1432 avatar Aug 10 '25 15:08 shivas1432

This is doable I made a patch script to make it work with LM Studio OpenAI compatible API.

High-Level Approach

1. Core Concept

The Gemini CLI uses an authentication system to determine which AI service to connect to. We can add "local-model" as a new authentication type alongside the existing Google services.

2. Key Components to Modify

A. Create a Local Model Content Generator

  • Create a new TypeScript class that implements the ContentGenerator interface
  • This class translates between Gemini's message format and OpenAI's chat completion format
  • Handles streaming responses from the local server

B. Add Local Model to Auth Types

In packages/core/src/core/contentGenerator.ts:

  • Add LOCAL_MODEL = 'local-model' to the AuthType enum
  • Add logic to instantiate your LocalModelContentGenerator when this auth type is selected

C. Update Authentication Validation

In packages/cli/src/config/auth.ts:

  • Add validation that checks for LOCAL_MODEL_ENDPOINT environment variable
  • Return appropriate error messages if configuration is missing

D. Update the Auth Dialog UI

In packages/cli/src/ui/components/AuthDialog.tsx:

  • Add "Local Model" as an option in the authentication selection dialog
  • Add detection logic for when LOCAL_MODEL_ENDPOINT is set

3. Environment Configuration

Users configure their local model via environment variables:

AUTH_METHOD=local-model
LOCAL_MODEL_ENDPOINT=http://[YOUR_LM_STUDIO_IP]:1234/v1/chat/completions
GEMINI_MODEL=[model_name_from_lm_studio]

I am not sure this is the forum for dropping the patch or if my patch works with the current version as I did this for version 0.1.17 and we are at 0.4.1 now, but if this hasn't been updated and there is interest I can make a gist.

tibrownace avatar Sep 13 '25 00:09 tibrownace

@tibrownace I was wondering if you be interest in helping with my fork https://github.com/dloring1988/agent-cli as I am gearing this towards using all local providers along with gemini

dloring1988 avatar Sep 20 '25 14:09 dloring1988

@tibrownace I was wondering if you be interest in helping with my fork https://github.com/dloring1988/agent-cli as I am gearing this towards using all local providers along with gemini

broken link

jodinathan avatar Oct 16 '25 13:10 jodinathan

@jodinathan get this one instead https://github.com/acoliver/llxprt-code

TomLucidor avatar Oct 25 '25 07:10 TomLucidor

This issue has been automatically marked as stale due to 60 days of inactivity. It will be closed in 14 days if no further activity occurs.

github-actions[bot] avatar Jan 30 '26 02:01 github-actions[bot]

Please drop the patch)

DunaSpice avatar Feb 01 '26 07:02 DunaSpice

Google will always be preferential to their own, so LLXPRT is the best bet

TomLucidor avatar Feb 01 '26 11:02 TomLucidor

This is doable I made a patch script to make it work with LM Studio OpenAI compatible API.

High-Level Approach

1. Core Concept

The Gemini CLI uses an authentication system to determine which AI service to connect to. We can add "local-model" as a new authentication type alongside the existing Google services.

2. Key Components to Modify

A. Create a Local Model Content Generator

* Create a new TypeScript class that implements the `ContentGenerator` interface

* This class translates between Gemini's message format and OpenAI's chat completion format

* Handles streaming responses from the local server

B. Add Local Model to Auth Types

In packages/core/src/core/contentGenerator.ts:

* Add `LOCAL_MODEL = 'local-model'` to the AuthType enum

* Add logic to instantiate your LocalModelContentGenerator when this auth type is selected

C. Update Authentication Validation

In packages/cli/src/config/auth.ts:

* Add validation that checks for `LOCAL_MODEL_ENDPOINT` environment variable

* Return appropriate error messages if configuration is missing

D. Update the Auth Dialog UI

In packages/cli/src/ui/components/AuthDialog.tsx:

* Add "Local Model" as an option in the authentication selection dialog

* Add detection logic for when LOCAL_MODEL_ENDPOINT is set

3. Environment Configuration

Users configure their local model via environment variables:

AUTH_METHOD=local-model LOCAL_MODEL_ENDPOINT=http://[YOUR_LM_STUDIO_IP]:1234/v1/chat/completions GEMINI_MODEL=[model_name_from_lm_studio]

I am not sure this is the forum for dropping the patch or if my patch works with the current version as I did this for version 0.1.17 and we are at 0.4.1 now, but if this hasn't been updated and there is interest I can make a gist.

drop the patch

Petomai avatar Feb 09 '26 13:02 Petomai

The local model support everyone is looking for is actually already available in the @google/gemini-cli-core SDK. The SDK was architected as a modular orchestrator, and you can bypass the cloud router natively using the OverrideStrategy.

I've implemented a bridge for this in Tars (github.com/agustinsacco/tars) using a custom LlamaCppGenerator.

How it works (Technical TL;DR):

  1. Bypass Cloud Pings: During initialization, passing a concrete model name (e.g., qwen-3b) instead of auto trips the OverrideStrategy, which 'amputates' the ClassifierStrategy (no cloud router, no API key required).
  2. Tool-Calling Bridge: To make the core recognize local tool calls, you must map the model output to the response.functionCalls prototype getter. This allows local models like Qwen 3.5 to participate in the exact same multi-turn tool-loops as Gemini Pro.
  3. Future-Proof: Since this uses the standard ContentGenerator interface, it doesn't require forking the core and remains compatible with upstream SDK updates.

If you want to test this today, you can run tars setup and select the Llama.cpp backend.

agustinsacco avatar Mar 22 '26 22:03 agustinsacco

This is a feature request to add support for local/offline language models. It relates to the core agent's capabilities to interface with different models.

gemini-cli[bot] avatar May 09 '26 09:05 gemini-cli[bot]

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

because the gemini will stop the service for non-enterprise user, I write it for continue using gemini cli.

I try antigravity cli but found it is actually a b*** ***t.

WuJunkai2004 avatar May 30 '26 03:05 WuJunkai2004

I have created Gemini-CLI fork and added local models support check it out OpenAgent

haseeb-heaven avatar Jul 22 '26 00:07 haseeb-heaven

This item has been automatically marked as stale due to 60 days of inactivity. It will be closed in 14 days if no further activity occurs. Thank you!

gemini-cli[bot] avatar Sep 20 '26 01:09 gemini-cli[bot]

This item has been closed due to 14 additional days of inactivity after being marked as stale. If you believe this is still relevant, feel free to comment or reopen. Thank you!

gemini-cli[bot] avatar Oct 04 '26 02:10 gemini-cli[bot]