---
title: Gemini CLI | RunAPI
description: Configure Gemini CLI with RunAPI's Gemini native API, verify requests,
  and restore your previous setup.
url: https://runapi.ai/docs/resources/tool-integrations/gemini-cli.md
canonical: https://runapi.ai/docs/resources/tool-integrations/gemini-cli
locale: en
---

> HTML version: https://runapi.ai/docs/resources/tool-integrations/gemini-cli
> Site index for agents: https://runapi.ai/llms.txt

# Gemini CLI

## Overview

Gemini CLI is a terminal agent. This guide changes its model provider to
RunAPI's Gemini native API; adding RunAPI tools through MCP is a
separate step.

## Before you begin

Follow the [official installation guide][1]. Create a dedicated standard
API key using the [Authentication Guide](https://runapi.ai/docs/guides/authentication.md),
then copy a Gemini-native model ID from the [Model Catalog](https://runapi.ai/models).
Never commit your key.



[1]: https://geminicli.com/docs/get-started/installation/

```shell
npm install -g @google/gemini-cli
```

## Configure RunAPI

Start with these variables in your current shell. The base URL is the
HTTPS API root, without `/v1beta`; the SDK adds `POST
/v1beta/models/{model}:streamGenerateContent?alt=sse`. HTTP is only
allowed for localhost.

```shell
export GOOGLE_GEMINI_BASE_URL=https://runapi.ai
export GEMINI_API_KEY=YOUR_RUNAPI_API_KEY
export GEMINI_MODEL=YOUR_RUNAPI_MODEL_ID
```

For persistent use, put the same three variables in `~/.gemini/.env`,
outside your repositories. Restrict access with `chmod 600
~/.gemini/.env`. Gemini CLI searches for `.env` from the current
directory toward its parents, then checks `~/.gemini/.env` and `~/.env`;
check for competing files.

Merge these two settings into `~/.gemini/settings.json`, preserving
unrelated settings. Use `gemini-api-key` for API-key authentication; do
not reuse a cached Google login. The key is sent in `x-goog-api-key` by
default.

```json
{
  "security": {
    "auth": {"selectedType": "gemini-api-key"}
  },
  "model": {"name": "YOUR_RUNAPI_MODEL_ID"}
}
```

## Choose a model

Use `GEMINI_MODEL`, `--model YOUR_RUNAPI_MODEL_ID`, or `/model` in an
interactive session. Avoid `auto`, `pro`, and `flash`: these aliases can
resolve to Google model IDs not available in RunAPI. Internal routing,
classification, and loop detection can also request flash or flash-lite
auxiliary models; check their availability separately.

## Verify

Run this in a repository you trust. Check the model with `/about` or
`/stats` in an interactive session, then confirm a matching
`streamGenerateContent` request in RunAPI usage records. A successful
CLI response alone does not prove which endpoint received it.

```shell
gemini --version
gemini -p "Describe this repository in one sentence."
```

## Add RunAPI tools

MCP adds tools, not a model provider. This command registers the local
server; follow [Local MCP](https://runapi.ai/docs/resources/mcp/local.md) for its separate
authentication and verification.

```shell
gemini mcp add runapi npx -y @runapi.ai/mcp
```

## Troubleshoot

If requests still go to Google, check competing `.env` files,
`security.auth.selectedType`, cached login, and Google/Vertex
authentication environment settings. If you see `Invalid auth method
selected`, select `gemini-api-key` in settings rather than `gateway` and
restart.

A `401` means you should check the key and any
`GEMINI_API_KEY_AUTH_MECHANISM` override; the default uses
`x-goog-api-key`. For `404`, remove `/v1beta` from the base URL and copy
a supported Gemini-native model ID again. For an unavailable auxiliary
model, check the exact requested ID; selecting a main model does not
guarantee every CLI feature works.

RunAPI does not expose `countTokens` or `embedContent`. Gemini CLI can
fall back to local token estimation when `countTokens` fails; estimates
may differ from usage records. Use HTTPS except for localhost, and do
not disable certificate verification.

## Remove RunAPI

Remove the three variables from your shell and saved `.env` files,
restore your previous `security.auth.selectedType` and model setting,
and revoke the dedicated key in RunAPI. Remove the separately added MCP
server only if you no longer need its tools.

```shell
unset GOOGLE_GEMINI_BASE_URL GEMINI_API_KEY GEMINI_MODEL
```

## Next steps

Continue with [LLM API Quickstart](https://runapi.ai/docs/guides/llm-api/quickstart.md),
[Gemini generateContent](https://runapi.ai/docs/api/gemini/generate-content.md),
[streamGenerateContent](https://runapi.ai/docs/api/gemini/stream-generate-content.md), the
[Model Catalog](https://runapi.ai/models), or [Local MCP](https://runapi.ai/docs/resources/mcp/local.md).

---

## More from RunAPI

- [Home](https://runapi.ai/.md)
- [Model Catalog](https://runapi.ai/models.md)
- [Pricing](https://runapi.ai/pricing.md)
- [Providers](https://runapi.ai/models)
- [Documentation](https://runapi.ai/docs/guides)
- [SDKs](https://runapi.ai/sdk.md)
- [CLI](https://runapi.ai/cli.md)
- [MCP Server](https://runapi.ai/mcp.md)
- [x402](https://runapi.ai/x402.md)
- [Claude Code vs Cursor](https://runapi.ai/claude-code-vs-cursor.md)
- [Cursor API Setup](https://runapi.ai/cursor-api-setup.md)
- [RunAPI vs OpenRouter](https://runapi.ai/openrouter-alternative.md)
- [Enterprise](https://runapi.ai/contact.md)
- [Contact](https://runapi.ai/contact.md)
- [Terms](https://runapi.ai/terms.md)
- [Privacy](https://runapi.ai/privacy.md)
- [Site index for agents](https://runapi.ai/llms.txt)

Contact: contact@runapi.ai

## Structured data

```json
[
  {
    "@context": "https://schema.org",
    "inLanguage": "en",
    "@type": "WebSite",
    "name": "RunAPI",
    "url": "https://runapi.ai/",
    "potentialAction": {
      "@type": "SearchAction",
      "target": {
        "@type": "EntryPoint",
        "urlTemplate": "https://runapi.ai/models?q={search_term_string}"
      },
      "query-input": "required name=search_term_string"
    }
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "en",
    "@type": "Organization",
    "name": "RunAPI",
    "url": "https://runapi.ai/",
    "logo": {
      "@type": "ImageObject",
      "url": "https://runapi.ai/icon.svg"
    },
    "sameAs": [
      "https://github.com/runapi-ai"
    ]
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "en",
    "@type": "TechArticle",
    "headline": "Gemini CLI",
    "description": "Configure Gemini CLI with RunAPI's Gemini native API, verify requests, and restore your previous setup.",
    "url": "https://runapi.ai/docs/resources/tool-integrations/gemini-cli",
    "mainEntityOfPage": "https://runapi.ai/docs/resources/tool-integrations/gemini-cli"
  }
]
```
