Skip to content

Use Gemini CLI with InferFoundry

Gemini CLI is Google's open-source terminal AI agent. You can override its base URL to route requests through InferFoundry, giving you regional data residency and budget controls.

Prerequisites

Connect Gemini CLI to InferFoundry

Option 1 — Environment variables

Add to your shell profile (~/.zshrc, ~/.bashrc, or ~/.config/fish/config.fish):

export GEMINI_API_KEY="your-inferfoundry-api-key"
export GOOGLE_GEMINI_BASE_URL="https://gateway.dev.if-service.ai"

Replace [your-region] with your region code (e.g. ch103, us103).

Then reload your shell:

source ~/.zshrc   # or ~/.bashrc

Option 2 — Settings file

Edit ~/.gemini/settings.json:

{
  "model": {
    "name": "claude-sonnet-4-5"
  }
}

The base URL and API key are set via environment variables (Gemini CLI reads GOOGLE_GEMINI_BASE_URL and GEMINI_API_KEY automatically).

Start Gemini CLI

cd /path/to/your/project
gemini

Switching models

Use the --model flag or set GEMINI_MODEL:

gemini --model claude-sonnet-4-5

Or in your shell profile:

export GEMINI_MODEL="claude-sonnet-4-5"

See Available Models for the full list.

Verify

Run a query and check portal.dev.if-service.aiUsage to confirm requests are flowing through your InferFoundry endpoint.

Troubleshooting

Auth errors
Verify GEMINI_API_KEY is set correctly. Run echo $GEMINI_API_KEY to check.
Requests going to Google instead of InferFoundry
Make sure GOOGLE_GEMINI_BASE_URL is set. This variable overrides the default Gemini API endpoint.
Model not found
Check Available Models for models available in your region. Use the exact model ID.