Antigravity CLI (agy) with a Custom API Base URL: Tested Setup
Run Google's Antigravity CLI (agy) on a Gemini API key and a custom base URL: settings.json, custom models, the 404 trap, and what API-key mode turns off.
Antigravity CLI is Google's terminal agent. Its command is agy, and in mid-2026 it replaced Gemini CLI. By default it signs in with a Google account and uses that account's quota. Since version 1.5.x it can also run on a plain Gemini API key, and it can send that key to any endpoint that speaks the Gemini API: Google's own, a company gateway, or a relay like XCoffee.
The official docs cover each setting on its own page, but they never put the steps together. We tested the full setup on agy 1.5.18 (macOS) on November 26, 2026. Below are the steps that worked, the configuration that returned a 404, and what you give up when you leave the Google sign-in.
What you need
agy1.5.x or newer. Runagy --versionto check;agy updateupgrades it.- An API key for a Gemini-compatible endpoint. The endpoint must serve
POST /v1beta/models/<model>:streamGenerateContent?alt=sse. An OpenAI-compatible/v1/chat/completionsendpoint is not enough: agy speaks only Gemini's native API. - The model name your endpoint expects. On XCoffee that is a group name:
xcoffee-coding,xcoffee-fastorxcoffee.
Check the endpoint before you touch agy:
curl -s https://api.xcoff.ee/v1beta/models \
-H "x-goog-api-key: $XCOFFEE_API_KEY"
You should get a JSON models list in which every model lists generateContent and streamGenerateContent. A 401 means the key is wrong.
Step 1: Switch agy to API-key mode
Three settings work together:
| Setting | Where | Value |
|---|---|---|
modelProvider |
settings.json |
"gemini" |
GEMINI_API_KEY |
environment | your relay key |
GOOGLE_GEMINI_BASE_URL |
environment | host root, e.g. https://api.xcoff.ee (no /v1beta) |
Leave /v1beta off the base URL. agy adds /v1beta/models/<model>:streamGenerateContent itself, and a base URL ending in /v1beta produces a doubled path.
export GEMINI_API_KEY="<your XCoffee key>"
export GOOGLE_GEMINI_BASE_URL="https://api.xcoff.ee"
Step 2: Add the relay's model as a custom model
This step is easy to skip. Once you switch to API-key mode, agy shows its built-in Google list (Gemini 4 Hydrogen, Gemini 3.8 Flash and so on) and sends that model name to your base URL. For example, it sends POST /v1beta/models/gemini-3.8-flash:streamGenerateContent. A relay that doesn't serve that exact name answers 404, and agy stops with:
AGY_ERROR: {"status":"NOT_FOUND","error_code":404,"code_kind":"http","retryable":false,...}
The fix is customModelsConfig, which agy reads only in API-key mode. Add this to ~/.gemini/antigravity-cli/settings.json:
{
"modelProvider": "gemini",
"customModelsConfig": {
"customModels": {
"xcoffee-coding": {
"modelName": "gemini-api://xcoffee-coding",
"label": "XCoffee Coding",
"toolFormatterType": "TOOL_FORMATTER_TYPE_NONE"
},
"xcoffee-fast": {
"modelName": "gemini-api://xcoffee-fast",
"label": "XCoffee Fast",
"toolFormatterType": "TOOL_FORMATTER_TYPE_NONE"
}
}
}
}
Write the model as gemini-api://<model>, with no host. The settings schema documents the form gemini-api://<base_url>/models/<model>. On 1.5.18, we pointed agy at a local test server and logged the request: with that form, agy pasted the whole URL into the path (POST /models/http:/127.0.0.1:18999/v1beta/models/xcoffee:streamGenerateContent), and every request returned 404. With gemini-api://xcoffee plus GOOGLE_GEMINI_BASE_URL, agy sent POST /v1beta/models/xcoffee:streamGenerateContent?alt=sse, which is correct. A later release may fix the documented form. Until it does, use the short form.
TOOL_FORMATTER_TYPE_NONE makes agy use the API's native function calling. The default is an XML prompt format. Native calling is the setting we tested with tools (see Step 3).
If you only want to try it and don't want to change your saved settings, --settings accepts the same JSON as a file path or inline. It applies to that run only and is never saved:
agy --settings ./agy-relay.json --model xcoffee-coding
Step 3: Verify it
Start with a one-shot prompt:
agy -p "Reply with the single word ok" --model xcoffee-fast
Expected output: ok, exit code 0. Use the fast group for this check. In one of our runs, the same prompt on xcoffee-coding hit a 2-minute --print-timeout (AGY_ERROR ... "reason":"print_timeout") before it answered. The coding group thinks before it replies, so give it a longer timeout or none in scripts.
Then test tool calls. A plain chat reply doesn't prove that the agent can edit files:
mkdir -p /tmp/agy-test && cd /tmp/agy-test
agy -p "Create a file named hello.txt containing exactly: hi from agy" \
--model xcoffee-coding --dangerously-skip-permissions
cat hello.txt
In our run agy answered Created hello.txt with the content hi from agy, and the file held exactly that text. That means streaming, function calling and the file tool all worked through the relay. Use --dangerously-skip-permissions only in a throwaway directory like this one.
In interactive mode, run agy, open /model and pick XCoffee Coding. The banner and /help should show Gemini API key as the credential.
What you lose in API-key mode
The changelog says some features turn off without a Google sign-in. Plan for this before you switch:
- Remote Control,
--remote-agentand voice dictation (/voice,/record) are unavailable.--remote-controland--remote-agentexit with code 2 at launch. /usage,/quotaand/creditsdisappear. An API key has no account quota to show, so check usage on the relay's dashboard instead.- The
AI creditsstatus and setting go away. API keys don't use AI credits. - Headless runs no longer stop after 5 minutes by default. Set
--print-timeoutif you need a limit.
Everything a coding agent needs every day, such as reading and editing files, running shell commands, MCP servers and plugins, keeps working.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
404 NOT_FOUND, exit code 3 |
The relay doesn't serve the model name agy sent | Add a custom model (Step 2) and select it with --model |
| 404 even with a custom model | modelName includes the host |
Use gemini-api://<model> and put the host in GOOGLE_GEMINI_BASE_URL |
| Still signing in with Google | modelProvider isn't "gemini", or GEMINI_API_KEY is empty in this shell |
Check both; echo ${GEMINI_API_KEY:+set} |
401 |
Wrong or expired key | Re-copy the key; test with the curl above |
XCoffee 403 Choose a published purpose group allowed by your pass |
The model name isn't a group your plan allows | Use xcoffee-coding, xcoffee-fast or xcoffee |
Endpoint only offers /v1/chat/completions |
OpenAI-compatible only | agy can't use it. You need a Gemini-native endpoint |
For scripts, failures in -p mode print a structured AGY_ERROR: {...} line on stderr with the HTTP code, a retryable flag and an error ID, then exit with code 3. Parse that line rather than the human-readable message.
FAQ
Can Antigravity CLI use a third-party API?
Yes, if the endpoint speaks Gemini's native API. Set modelProvider: "gemini", export GEMINI_API_KEY and GOOGLE_GEMINI_BASE_URL, and add the endpoint's model as a custom model.
Can agy use an OpenAI-compatible endpoint?
Not directly. In API-key mode it sends Gemini streamGenerateContent requests only.
Where is the agy settings file?
~/.gemini/antigravity-cli/settings.json. agy rewrites it at startup in its own format, but it keeps keys it doesn't recognize.
Do the built-in Gemini models still show up?
Yes. They sit next to your custom models in /model, but on a relay they only work if the relay serves those exact names.
Run agy on a predictable budget
A coding agent reads large amounts of context on every turn, so long sessions use up quota quickly. XCoffee serves the Gemini native API alongside the OpenAI and Anthropic formats, so the same key works in agy, Claude Code and Codex. Compare the current plans and check the setup guide. The same base-URL approach works for Claude Code, too: see our tstack on a budget guide.