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.
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
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 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
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:
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
agyCLI 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_URLin your shell does not redirect Antigravity's built-in agent traffic.
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)
Open Antigravity IDE's integrated terminal (Ctrl + `) and launch Gemini CLI configured with LMU AI:
- Follow the Gemini CLI setup guide to configure
~/.gemini/.env(GOOGLE_GEMINI_BASE_URL=https://api.lmuai.ai+GEMINI_API_KEY) and~/.gemini/settings.json - Run
geminiin the integrated terminal to run agentic edits and tasks directly in your workspace
Option 2: Install VS Code agent extensions in Antigravity IDE
Because Antigravity IDE is built on VS Code, it supports VS Code extensions:
- Open Extensions (
Cmd+Shift+X/Ctrl+Shift+X) and install Cline, Roo Code, or Kilo Code - If an extension is missing from the built-in marketplace (Open VSX), download its
.vsixpackage and choose Install from VSIX from the…menu in the Extensions panel - Point the extension to
https://api.lmuai.aiand yoursk-key using the 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.
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).
3. Third-party agent tools
Gemini CLI
Google's open-source terminal agent natively supports GOOGLE_GEMINI_BASE_URL and GEMINI_API_KEY. See the dedicated Gemini CLI guide for installation, macOS / Linux / Windows / CC Switch setup, and troubleshooting.
Minimal ~/.gemini/.env and ~/.gemini/settings.json:
GOOGLE_GEMINI_BASE_URL=https://api.lmuai.ai
GEMINI_API_KEY=sk-replace-with-your-lmuai-key
GEMINI_MODEL=gemini-3.1-pro-preview{
"security": {
"auth": {
"selectedType": "gemini-api-key"
}
}
}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):
{
"$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" }
}
}
}
}Include the /v1beta suffix here
@ai-sdk/google expects /v1beta as part of baseURL, so set it to https://api.lmuai.ai/v1beta.
{
"$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" }
}
}
}
}Cline / Roo Code / Kilo Code
Works in VS Code, Antigravity IDE, Cursor, Trae, and JetBrains (see IDEA Kilo Code).
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 |
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 |
Cursor / Trae
Cursor and Trae connect third-party models through the OpenAI-compatible protocol (see Cursor and Trae):
- Base URL:
https://api.lmuai.ai/v1 - API Key: your LMU AI
sk-key - Custom Model IDs: add
gemini-3.1-pro-previewandgemini-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
| 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 |
| Chatbox | Add a custom OpenAI-compatible provider and enter Gemini model IDs | https://api.lmuai.ai/v1 | 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 |
| Crush | Use --type openai-compat in crushrc, then register Gemini IDs with model add | https://api.lmuai.ai/v1 | Crush |
4. Third-party APIs & popular SDKs
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)
pip install google-genaifrom 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)
npm install @google/genaiimport { 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)
npm install ai @ai-sdk/googleimport { 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)
pip install langchain-google-genaifrom 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)
Use the gemini/ model prefix for AI Studio-style API key auth (do not use vertex_ai/, which requires GCP service account credentials):
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)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_KEY6. OpenAI SDK calling Gemini (compatible mode)
If your codebase already uses the OpenAI SDK, you can call Gemini models directly without changing client code:
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
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."}]
}]
}'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."}]
}]
}'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 and Gemini Image API |
For full protocol rules see API Protocols; for HTTP status codes see Error Codes.
Last updated:
Still have questions? Ask in the LMU AI Community (in Chinese) and sign in with your console account.
Get an LMU AI key and start using Claude, Codex and more
Free sign-up, flexible plans, one key across Claude Code, Codex CLI, Cursor, VS Code, OpenCode, Cherry Studio and other AI tools.
Sign up