# Third-Party Gemini API in Agent Tools & SDKs

> Complete guide to connecting LMU AI's third-party Gemini API to Google Antigravity, OpenCode, Cline / Roo Code / Kilo Code, Cherry Studio, Cursor, and SDKs including google-genai, @google/genai, Vercel AI SDK, LangChain, and LiteLLM.

URL: https://docs.lmuai.ai/docs/tools/gemini-third-party-tools



LMU AI supports both the **Gemini native `v1beta` protocol** and the **OpenAI-compatible `/v1` protocol**. A single `sk-` API key from a Gemini-enabled group works across terminal agents, IDE extensions, desktop apps, and application SDKs.

***

## 1. Choose the right protocol and Base URL [#1-choose-the-right-protocol-and-base-url]

Different tools and SDKs expect different URL path suffixes — getting this wrong is the #1 cause of `404` errors. Start by choosing the right protocol:

| Aspect               | Gemini native protocol (recommended)                                                                                                   | OpenAI-compatible protocol (universal fallback)                                                               |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| **Typical Base URL** | `https://api.lmuai.ai` (some SDKs require `/v1beta`; see the table below)                                                              | `https://api.lmuai.ai/v1` (**must include** `/v1`)                                                            |
| **Auth header**      | `x-goog-api-key: sk-...` (Bearer also accepted)                                                                                        | `Authorization: Bearer sk-...`                                                                                |
| **Strengths**        | Preserves native multi-turn tool calling, thought signatures, multimodal input, search grounding metadata, and native image generation | Supported out of the box by nearly every editor and client that lacks a custom Gemini host field              |
| **Typical tools**    | Gemini CLI, Google GenAI SDKs, Vercel AI SDK, OpenCode (`@ai-sdk/google`), Roo Code / Kilo Code (native mode), Cherry Studio           | Cursor, Trae, Cline / Roo Code / Kilo Code (OpenAI-compatible mode), Chatbox, Hermes Agent, Crush, OpenAI SDK |

**Common available Gemini model IDs** (see [Models](../guide/models) for the full list):

* Flagship: `gemini-3.1-pro-preview`
* Fast: `gemini-3.8-flash`, `gemini-3.7-flash`, `gemini-3.6-flash`
* Lite: `gemini-3.5-flash-lite`

***

## 2. Google Antigravity (IDE / Desktop / CLI): current support & workarounds [#2-google-antigravity-ide--desktop--cli-current-support--workarounds]

Many users ask whether they can plug a third-party Gemini API key directly into **Google Antigravity** (Antigravity IDE, Antigravity 2.0, or the `agy` CLI). Here is the verified behavior:

<Callout type="warn" title="Antigravity's built-in agent does not support native BYOK or custom Base URLs">
  * Built-in agent chat and Tab autocomplete in Antigravity IDE, Antigravity 2.0, and the `agy` CLI authenticate via Google account OAuth (or Google Cloud Antigravity Enterprise Gateway in enterprise deployments). Native BYOK fields and custom third-party endpoints are not exposed for the built-in agent.
  * Setting `GOOGLE_GEMINI_BASE_URL` in your shell does **not** redirect Antigravity's built-in agent traffic.
</Callout>

If you work inside **Antigravity IDE** and want to use LMU AI's third-party Gemini API, three practical options work today:

### Option 1: Run Gemini CLI in Antigravity's integrated terminal (most direct) [#option-1-run-gemini-cli-in-antigravitys-integrated-terminal-most-direct]

Open Antigravity IDE's integrated terminal (`` Ctrl + ` ``) and launch [Gemini CLI](./gemini-cli) configured with LMU AI:

1. Follow the [Gemini CLI setup guide](./gemini-cli) to configure `~/.gemini/.env` (`GOOGLE_GEMINI_BASE_URL=https://api.lmuai.ai` + `GEMINI_API_KEY`) and `~/.gemini/settings.json`
2. Run `gemini` in the integrated terminal to run agentic edits and tasks directly in your workspace

### Option 2: Install VS Code agent extensions in Antigravity IDE [#option-2-install-vs-code-agent-extensions-in-antigravity-ide]

Because Antigravity IDE is built on VS Code, it supports VS Code extensions:

1. Open Extensions (`Cmd+Shift+X` / `Ctrl+Shift+X`) and install **Cline**, **Roo Code**, or **Kilo Code**
2. If an extension is missing from the built-in marketplace (Open VSX), download its `.vsix` package and choose **Install from VSIX** from the `…` menu in the Extensions panel
3. Point the extension to `https://api.lmuai.ai` and your `sk-` key using the [Cline / Roo Code / Kilo Code](#cline-roo-code-kilo-code) settings below

> To run a Claude / Chinese-model agent inside Antigravity IDE, you can also install the [Claude Code extension](./claude-code-vscode).

### Option 3: Call third-party Gemini SDKs from Antigravity MCP servers or scripts [#option-3-call-third-party-gemini-sdks-from-antigravity-mcp-servers-or-scripts]

When building custom MCP servers, helper scripts, or skills invoked by Antigravity, use the official `google-genai`, `@google/genai`, or `openai` SDK pointed at `https://api.lmuai.ai` (see [Section 4: Third-party APIs & SDKs](#sdk-integrations)).

***

## 3. Third-party agent tools [#3-third-party-agent-tools]

### Gemini CLI [#gemini-cli]

Google's open-source terminal agent natively supports `GOOGLE_GEMINI_BASE_URL` and `GEMINI_API_KEY`. See the dedicated [Gemini CLI guide](./gemini-cli) for installation, macOS / Linux / Windows / CC Switch setup, and troubleshooting.

Minimal `~/.gemini/.env` and `~/.gemini/settings.json`:

```dotenv
GOOGLE_GEMINI_BASE_URL=https://api.lmuai.ai
GEMINI_API_KEY=sk-replace-with-your-lmuai-key
GEMINI_MODEL=gemini-3.1-pro-preview
```

```json
{
  "security": {
    "auth": {
      "selectedType": "gemini-api-key"
    }
  }
}
```

***

### OpenCode [#opencode]

OpenCode supports Gemini via either the native `@ai-sdk/google` provider or an OpenAI-compatible provider. Edit `~/.config/opencode/opencode.json` (see the full [OpenCode guide](./opencode)):

<Tabs items="['Gemini native (@ai-sdk/google, recommended)', 'OpenAI-compatible']">
  <Tab value="Gemini native (@ai-sdk/google, recommended)">
    ```json
    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "google": {
          "npm": "@ai-sdk/google",
          "name": "LMU AI Gemini",
          "options": {
            "baseURL": "https://api.lmuai.ai/v1beta",
            "apiKey": "sk-replace-with-your-lmuai-key"
          },
          "models": {
            "gemini-3.1-pro-preview": { "name": "Gemini 3.1 Pro Preview" },
            "gemini-3.8-flash": { "name": "Gemini 3.8 Flash" }
          }
        }
      }
    }
    ```

    <Callout type="warn" title="Include the /v1beta suffix here">
      `@ai-sdk/google` expects `/v1beta` as part of `baseURL`, so set it to `https://api.lmuai.ai/v1beta`.
    </Callout>
  </Tab>

  <Tab value="OpenAI-compatible">
    ```json
    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "lmuai-gemini": {
          "npm": "@ai-sdk/openai-compatible",
          "name": "LMU AI Gemini (OpenAI)",
          "options": {
            "baseURL": "https://api.lmuai.ai/v1",
            "apiKey": "sk-replace-with-your-lmuai-key"
          },
          "models": {
            "gemini-3.1-pro-preview": { "name": "Gemini 3.1 Pro Preview" },
            "gemini-3.8-flash": { "name": "Gemini 3.8 Flash" }
          }
        }
      }
    }
    ```
  </Tab>
</Tabs>

***

### Cline / Roo Code / Kilo Code [#cline-roo-code-kilo-code]

Works in VS Code, Antigravity IDE, Cursor, Trae, and JetBrains (see [IDEA Kilo Code](./kilo-code-idea)).

<Tabs items="['OpenAI Compatible (most reliable)', 'Google Gemini native (best for tool calling)']">
  <Tab value="OpenAI Compatible (most reliable)">
    When newer client releases hide or omit custom base URL fields for native providers, **OpenAI Compatible** is the most reliable choice:

    | Field            | Value                                          |
    | ---------------- | ---------------------------------------------- |
    | **API Provider** | `OpenAI Compatible`                            |
    | **Base URL**     | `https://api.lmuai.ai/v1`                      |
    | **API Key**      | Your LMU AI `sk-` key                          |
    | **Model ID**     | `gemini-3.1-pro-preview` or `gemini-3.8-flash` |
  </Tab>

  <Tab value="Google Gemini native (best for tool calling)">
    If your extension version exposes a custom base URL under the **Google Gemini** provider, prefer it to preserve multi-turn thought signatures and native function calling:

    | Field                     | Value                                          |
    | ------------------------- | ---------------------------------------------- |
    | **API Provider**          | `Google Gemini`                                |
    | **Google Gemini API Key** | Your LMU AI `sk-` key                          |
    | **Use custom base URL**   | Checked                                        |
    | **Base URL**              | `https://api.lmuai.ai` (no `/v1beta`)          |
    | **Model**                 | `gemini-3.1-pro-preview` or `gemini-3.8-flash` |
  </Tab>
</Tabs>

***

### Cursor / Trae [#cursor--trae]

Cursor and Trae connect third-party models through the **OpenAI-compatible protocol** (see [Cursor](./cursor) and [Trae](./trae)):

* **Base URL**: `https://api.lmuai.ai/v1`
* **API Key**: your LMU AI `sk-` key
* **Custom Model IDs**: add `gemini-3.1-pro-preview` and `gemini-3.8-flash`

> In Cursor, custom third-party endpoints apply only to the **Chat / Plan** panel; Composer and Tab autocomplete stay on Cursor's official backend.

***

### Cherry Studio / Chatbox / Hermes Agent / Crush [#cherry-studio--chatbox--hermes-agent--crush]

| Client            | Configuration                                                                            | Base URL / API Host                                                                | Full guide                |
| ----------------- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | ------------------------- |
| **Cherry Studio** | Add a `Gemini` provider (or an `OpenAI`-compatible provider)                             | `https://api.lmuai.ai` for Gemini; `https://api.lmuai.ai/v1` for OpenAI-compatible | [Cherry Studio](./cherry) |
| **Chatbox**       | Add a custom OpenAI-compatible provider and enter Gemini model IDs                       | `https://api.lmuai.ai/v1`                                                          | [Chatbox](./chatbox)      |
| **Hermes Agent**  | Set `model` in `~/.hermes/config.yaml` to `gemini-3.1-pro-preview` or `gemini-3.8-flash` | `https://api.lmuai.ai/v1`                                                          | [Hermes Agent](./hermes)  |
| **Crush**         | Use `--type openai-compat` in `crushrc`, then register Gemini IDs with `model add`       | `https://api.lmuai.ai/v1`                                                          | [Crush](./crush)          |

***

## 4. Third-party APIs & popular SDKs [#sdk-integrations]

### SDK Base URL cheat sheet [#sdk-base-url-cheat-sheet]

| SDK / Framework                    | Protocol          | Base URL                                                     | Version suffix?                                                      |
| ---------------------------------- | ----------------- | ------------------------------------------------------------ | -------------------------------------------------------------------- |
| Python `google-genai`              | Gemini native     | `https://api.lmuai.ai`                                       | **No** `/v1beta`                                                     |
| JS / TS `@google/genai`            | Gemini native     | `https://api.lmuai.ai`                                       | **No** `/v1beta`                                                     |
| Vercel AI SDK `@ai-sdk/google`     | Gemini native     | `https://api.lmuai.ai/v1beta`                                | **Requires** `/v1beta`                                               |
| LangChain `langchain-google-genai` | Gemini native     | `https://api.lmuai.ai`                                       | **No** `/v1beta`                                                     |
| LiteLLM (`gemini/...`)             | Gemini native     | `https://api.lmuai.ai`                                       | Omit by default (try `/v1beta` only if required by an older version) |
| OpenAI SDK (Python / Node)         | OpenAI-compatible | `https://api.lmuai.ai/v1`                                    | **Requires** `/v1`                                                   |
| `curl` / raw HTTP                  | Gemini native     | `https://api.lmuai.ai/v1beta/models/{model}:generateContent` | Full path                                                            |

***

### 1. Python official SDK (`google-genai`) [#1-python-official-sdk-google-genai]

```bash
pip install google-genai
```

```python
from google import genai
from google.genai import types

client = genai.Client(
    api_key="sk-replace-with-your-lmuai-key",
    http_options=types.HttpOptions(
        base_url="https://api.lmuai.ai",
    ),
)

response = client.models.generate_content(
    model="gemini-3.8-flash",
    contents="Explain MCP in one sentence.",
)
print(response.text)
```

***

### 2. Node.js / TypeScript official SDK (`@google/genai`) [#2-nodejs--typescript-official-sdk-googlegenai]

```bash
npm install @google/genai
```

```typescript
import { GoogleGenAI } from '@google/genai';

const ai = new GoogleGenAI({
  apiKey: 'sk-replace-with-your-lmuai-key',
  httpOptions: {
    baseUrl: 'https://api.lmuai.ai',
  },
});

const response = await ai.models.generateContent({
  model: 'gemini-3.8-flash',
  contents: 'Explain MCP in one sentence.',
});

console.log(response.text);
```

***

### 3. Vercel AI SDK (`@ai-sdk/google`) [#3-vercel-ai-sdk-ai-sdkgoogle]

```bash
npm install ai @ai-sdk/google
```

```typescript
import { createGoogleGenerativeAI } from '@ai-sdk/google';
import { generateText } from 'ai';

const google = createGoogleGenerativeAI({
  apiKey: 'sk-replace-with-your-lmuai-key',
  baseURL: 'https://api.lmuai.ai/v1beta', // /v1beta is required here
});

const { text } = await generateText({
  model: google('gemini-3.8-flash'),
  prompt: 'Explain MCP in one sentence.',
});

console.log(text);
```

***

### 4. LangChain (`langchain-google-genai`) [#4-langchain-langchain-google-genai]

```bash
pip install langchain-google-genai
```

```python
from langchain_google_genai import ChatGoogleGenerativeAI

llm = ChatGoogleGenerativeAI(
    model="gemini-3.8-flash",
    base_url="https://api.lmuai.ai",
    google_api_key="sk-replace-with-your-lmuai-key",
)

resp = llm.invoke("Explain MCP in one sentence.")
print(resp.content)
```

***

### 5. LiteLLM (Python SDK & Proxy) [#5-litellm-python-sdk--proxy]

Use the `gemini/` model prefix for AI Studio-style API key auth (do **not** use `vertex_ai/`, which requires GCP service account credentials):

<Tabs items="['Python SDK', 'LiteLLM Proxy (config.yaml)']">
  <Tab value="Python SDK">
    ```python
    from litellm import completion

    resp = completion(
        model="gemini/gemini-3.8-flash",
        messages=[{"role": "user", "content": "Hello"}],
        api_base="https://api.lmuai.ai",
        api_key="sk-replace-with-your-lmuai-key",
    )
    print(resp.choices[0].message.content)
    ```
  </Tab>

  <Tab value="LiteLLM Proxy (config.yaml)">
    ```yaml
    model_list:
      - model_name: gemini-3.8-flash
        litellm_params:
          model: gemini/gemini-3.8-flash
          api_base: "https://api.lmuai.ai"
          api_key: os.environ/GEMINI_API_KEY
    ```
  </Tab>
</Tabs>

***

### 6. OpenAI SDK calling Gemini (compatible mode) [#6-openai-sdk-calling-gemini-compatible-mode]

If your codebase already uses the OpenAI SDK, you can call Gemini models directly without changing client code:

```python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.lmuai.ai/v1",
    api_key="sk-replace-with-your-lmuai-key",
)

resp = client.chat.completions.create(
    model="gemini-3.8-flash",
    messages=[{"role": "user", "content": "Explain MCP in one sentence."}],
)
print(resp.choices[0].message.content)
```

***

### 7. Native REST / `curl` [#7-native-rest--curl]

<Tabs items="['Non-streaming (generateContent)', 'Streaming (streamGenerateContent)']">
  <Tab value="Non-streaming (generateContent)">
    ```bash
    curl -X POST \
      'https://api.lmuai.ai/v1beta/models/gemini-3.8-flash:generateContent' \
      -H 'x-goog-api-key: sk-replace-with-your-lmuai-key' \
      -H 'Content-Type: application/json' \
      -d '{
        "contents": [{
          "role": "user",
          "parts": [{"text": "Explain MCP in one sentence."}]
        }]
      }'
    ```
  </Tab>

  <Tab value="Streaming (streamGenerateContent)">
    ```bash
    curl -N -X POST \
      'https://api.lmuai.ai/v1beta/models/gemini-3.8-flash:streamGenerateContent?alt=sse' \
      -H 'x-goog-api-key: sk-replace-with-your-lmuai-key' \
      -H 'Content-Type: application/json' \
      -d '{
        "contents": [{
          "role": "user",
          "parts": [{"text": "Explain MCP in one sentence."}]
        }]
      }'
    ```
  </Tab>
</Tabs>

***

## 5. Troubleshooting [#5-troubleshooting]

| Symptom                                       | Usual cause                                                                                                                                               | Fix                                                                                                 |
| --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| `404 Not Found`                               | Wrong Base URL suffix (e.g. adding `/v1beta` to `google-genai` / Gemini CLI, omitting `/v1beta` on `@ai-sdk/google`, or omitting `/v1` on the OpenAI SDK) | Match the suffix in the SDK Base URL cheat sheet above                                              |
| `401 Unauthorized`                            | Invalid key or missing `x-goog-api-key` header on native requests                                                                                         | Verify your `sk-` key in the console; send `x-goog-api-key` for Gemini native calls                 |
| Model unavailable / `No available accounts`   | Your key's group does not include the requested Gemini model                                                                                              | Check **Available Models** in the console or switch to a Gemini-enabled group key                   |
| Multi-step tool calls fail in coding agents   | OpenAI-compatible translation drops native Gemini thought signatures or tool schemas                                                                      | Switch the extension/tool to its **native Google Gemini** provider mode                             |
| Need web search grounding or image generation | Both rely on native Gemini request fields                                                                                                                 | See [Gemini Web Search API](/docs/api/gemini-search) and [Gemini Image API](/docs/api/gemini-image) |

For full protocol rules see [API Protocols](../guide/api-protocols); for HTTP status codes see [Error Codes](../guide/errors).
