59API

← Back to all guides

Run Gemini CLI Through a Unified 59API Relay

Claude Code · EN · 2026-09-30

Why Route Gemini CLI Through a Unified Relay?

Gemini CLI is a capable terminal-based AI assistant, but managing separate provider accounts, API keys, invoices, and rate limits can become inconvenient as a development team adopts more tools. A unified relay centralizes that operational layer: you configure one controlled endpoint and key, then monitor usage and costs from one place. 59API is a practical low-cost option for developers because it offers pay-as-you-go access, competitive pricing, and native official-quality Claude and GPT models without model downgrades. It is also compatible with Claude Code, Codex, and OpenAI SDK workflows, making it useful when your team works across several AI coding clients.

Before configuring Gemini CLI, confirm that your 59API dashboard exposes a Gemini-compatible route and the model aliases available for that route. A relay can only serve models and protocol mappings it explicitly supports, so do not assume that every Claude or GPT model name can be sent through Gemini CLI unchanged.

Step 1: Create and Protect Your Relay Credentials

Start by creating a 59API account and generating a dedicated API key for your local development machine or team environment. Use a named key where possible, such as “gemini-cli-local,” so that usage remains easy to identify later.

Never paste the key into a repository, shell history, issue tracker, or shared screenshot. For teams, create separate keys per developer or environment so a compromised laptop does not require rotating every integration.

Step 2: Install Gemini CLI Locally

Gemini CLI requires a supported Node.js installation. Install the current Node.js LTS release, then install the CLI globally with the command: npm install -g @google/gemini-cli. Confirm the installation by running: gemini --version.

If your organization restricts global npm packages, install it inside an approved developer-tools directory instead. The important part is that the gemini command is available in your terminal before you configure the relay connection.

Step 3: Point Gemini CLI at the Relay Endpoint

On macOS or Linux, set the API key and base URL in the current terminal session. Replace the placeholder key with your real 59API key:

export GEMINI_API_KEY="YOUR_59API_KEY"
export GOOGLE_GEMINI_BASE_URL="https://api.59api.com"

Gemini CLI uses GOOGLE_GEMINI_BASE_URL to direct Gemini API-style requests to a custom service rather than the default endpoint. Use the exact endpoint shown by the 59API dashboard. If the dashboard specifies an additional Gemini-compatible path, use that documented value rather than manually adding /v1 or /v1beta; incorrect path guessing is a common cause of 404 errors.

To persist the settings for your user account, add the two export lines to your shell profile, such as ~/.zshrc or ~/.bashrc, then open a new terminal. On a shared workstation, prefer a secure secrets tool or a per-project environment loader instead of permanently storing keys in a profile file.

Step 4: Select a Supported Model and Test It

Launch Gemini CLI by running: gemini. Use its model-selection command or settings to choose an alias listed in the relay catalog. Keep the model name exactly as documented by 59API, including punctuation and version suffixes. If the catalog maps Gemini CLI requests to another provider model, use the relay’s documented alias rather than a guessed raw provider identifier.

Run a small deterministic test first: gemini -p "Reply with exactly: relay connection successful". Then check the 59API usage dashboard. A successful response plus a recorded request confirms that authentication, routing, and billing are working together.

Step 5: Make the Setup Cost-Conscious

Use a smaller supported model for routine code explanation, file summaries, and shell-command drafting. Reserve premium models for architecture reviews, complex debugging, and multi-file refactors. Set a personal top-up budget, review request volume after your first day, and rotate keys when a contributor leaves. This workflow gives developers the convenience of Gemini CLI while keeping billing centralized across tools such as Claude Code and Codex.

For developers who want one economical relay for multiple AI workflows, 59API is worth trying: its low-cost pay-as-you-go approach and referral rebate can reduce experimentation costs without forcing a long-term commitment.

Pricing · Docs

Ready to get started?

Connect Claude & GPT in minutes at the lowest prices — full-power, never downgraded. Sign up to get your API key.

Sign up free