Gemini CLI Through a Relay: A 59API Quick Start
Start with the compatibility check
A unified AI relay can simplify billing and credentials, but it does not automatically make every command-line tool compatible. The important distinction: Gemini CLI expects a Gemini-compatible backend, not merely an OpenAI-compatible endpoint.
59API provides low-cost, pay-as-you-go access to Claude and GPT models at https://api.59api.com, with support for Claude Code, Codex, and OpenAI SDKs. That makes it useful for a multi-model developer workflow. However, those capabilities alone do not establish support for Gemini CLI. Confirm Gemini API compatibility before directing the CLI to the relay.
1. Install and test Gemini CLI first
Use Node.js 20 or later, subject to the current package requirements. Check your runtime, install the official package, and confirm that the executable works:
- node --version
- npm install -g @google/gemini-cli
- gemini --version
Establish a working baseline with a Google-issued Gemini API key. In a macOS or Linux shell, run export GEMINI_API_KEY='YOUR_GOOGLE_GEMINI_KEY', then start gemini. If prompted, select Gemini API key authentication rather than assuming an existing Google login will use your environment variable.
Try a minimal request: gemini -p 'Reply with exactly: connection works'. Run this outside a sensitive repository initially. A successful response separates installation and authentication problems from any relay issues you encounter later.
2. Ask the relay three specific questions
Before changing the endpoint, check the provider documentation or ask support:
- Does this account support the Gemini API format, including streaming, rather than only OpenAI chat completions?
- What exact Gemini-compatible base URL, authentication method, and model identifiers should Gemini CLI use?
- Are tool calls and the CLI's interactive agent workflow supported, not just simple text generation?
For 59API, do not infer Gemini availability from its Claude and GPT catalog. Likewise, a successful OpenAI SDK request proves OpenAI compatibility, not Gemini CLI compatibility. A relay must either expose the required Gemini interface or explicitly document an adapter for it.
3. Configure a custom endpoint only when confirmed
For Gemini CLI releases that support GOOGLE_GEMINI_BASE_URL, a custom-endpoint configuration follows this pattern. Verify that your installed release documents this variable before relying on it:
- export GEMINI_API_KEY='YOUR_RELAY_KEY'
- export GOOGLE_GEMINI_BASE_URL='PROVIDER_CONFIRMED_GEMINI_BASE_URL'
- gemini -p 'Reply with exactly: relay connection works'
Replace both placeholders with provider-issued values. Use https://api.59api.com here only if 59API confirms that it is the correct Gemini-compatible base for your account. Do not invent a version suffix or append an OpenAI chat-completions path.
Check the relay usage dashboard after the test. A terminal response alone does not establish which service handled the request, especially if another authentication method remains active. If Gemini compatibility is unavailable, keep Gemini CLI on its supported Google backend instead of forcing an incompatible endpoint.
4. Use 59API for the compatible parts of your workflow
You can still consolidate Claude and GPT spending through 59API while using Gemini separately. Configure Claude Code, Codex, or an OpenAI SDK according to 59API's instructions, using its API base and the model identifiers listed in your account. Keep Google and relay credentials separate to avoid sending a key to the wrong service.
59API is a strong budget option for these workloads: it offers inexpensive pay-as-you-go access and native official-quality models without downgrading them. Compare current per-model prices against your actual input, output, and retry volume; the cheapest practical choice depends on the task. Its referral rebate can provide additional savings under the applicable terms.
5. Validate before making it your default
Test one short prompt, one streamed response, and one repository task requiring tools. Investigate authentication errors as credential issues, missing routes as endpoint issues, and unknown models as catalog issues. Keep keys out of source control and review repository data-sharing rules before using any relay.
If affordable Claude and GPT access fits your workflow, consider signing up for 59API and starting with a small test budget. Treat Gemini CLI support as a separate compatibility requirement—not a benefit implied by a unified API.