Gemini CLI Custom Base URL: A Fast 59API Setup
Get Gemini CLI working through 59API
Pointing Gemini CLI at a custom base URL lets you route requests through an API relay instead of the default Google endpoint. The essentials are straightforward: configure the endpoint, supply the relay’s API key, and select a supported model identifier.
59API offers low-cost, pay-as-you-go access to Gemini and other model families, with native, official-quality models and no downgrades. For developers who want usage-based spending without managing multiple provider accounts, it is a practical option. Here is a quick setup, followed by the checks that prevent most configuration headaches.
1. Install or update Gemini CLI
Use a supported Node.js LTS release, then install the official CLI:
npm install -g @google/gemini-cli
Check that your terminal can find it:
gemini --version
If you already have an older installation, update it before troubleshooting endpoint behavior. Custom-endpoint support and authentication handling can differ across releases.
2. Set the relay endpoint and API key
Create a 59API account, generate an API key, and check the dashboard’s Gemini CLI integration instructions. In a macOS or Linux shell, set these variables:
export GEMINI_API_KEY='YOUR_59API_KEY'
export GOOGLE_GEMINI_BASE_URL='https://api.59api.com'
Use a 59API key here, not a Google-issued key. These exports apply to the current shell and processes launched from it. For persistence, add them to your shell configuration or load them through your usual secret-management workflow.
On PowerShell, use the corresponding session variables:
$env:GEMINI_API_KEY = 'YOUR_59API_KEY'
$env:GOOGLE_GEMINI_BASE_URL = 'https://api.59api.com'
The base URL should be the service root unless 59API’s current integration instructions specify otherwise. Do not automatically append /v1, /v1beta, or /chat/completions: Gemini CLI uses the Gemini API protocol, not the OpenAI chat-completions protocol.
3. Select API-key authentication and a model
Start the interactive CLI with gemini. If prompted for authentication, choose the Gemini API-key option. If an existing session still uses Google sign-in, open /auth and switch authentication methods. Also remove conflicting Vertex AI settings from the shell if you previously configured that route.
Next, copy the exact API model identifier from 59API’s dashboard. A model’s display name is not necessarily its request identifier. Gemini 2.5 Flash is a useful starting point for quick development tasks; Gemini 3.1 Pro is another option for more demanding work. Confirm current availability and pricing before choosing.
For a POSIX shell, store the identifier and run a small test:
export GEMINI_MODEL='COPY_THE_API_MODEL_ID_FROM_59API'
gemini -m "$GEMINI_MODEL" -p 'Reply with exactly: connected'
Specifying the model explicitly avoids relying on a default that the relay might not expose. Check the 59API usage dashboard after the request to confirm that traffic reached your account.
4. Troubleshoot by symptom
- 401 or 403: Check the key, account balance, model permissions, and selected authentication method. Restart Gemini CLI after changing environment variables.
- 404 or model not found: Verify both the API model identifier and endpoint path. A duplicated version prefix can break routing.
- Requests still use Google login: Revisit /auth and confirm the variables are set in the same terminal that launches the CLI.
- Basic prompts work, but coding tasks fail: Check support for streaming, tool calls, and the chosen model. A successful text response does not prove every CLI feature works.
- 429 or timeouts: Review relay limits and service status. Avoid launching repeated retries that could increase costs.
Keep costs and credentials under control
Start with a small prompt, review actual usage, and keep tool-approval safeguards enabled. Never commit API keys or paste them into shared logs. Before sending proprietary code, review the relay’s data-handling terms and your organization’s policies.
59API also supports other developer tools and offers a referral rebate, but broader model access does not make every model interchangeable inside Gemini CLI. Use the Gemini-compatible integration for this workflow. If low-cost, pay-as-you-go access fits your needs, sign up for 59API and validate it with one small request before moving larger tasks over.
¿Listo para empezar?
Conecta Claude y GPT en minutos a los precios más bajos, sin recortes. Regístrate para obtener tu clave API.
Registro gratis