Gemini CLI access
Connect to the Gemini native interface of this site through API Key mode.
Gemini CLI uses the Gemini native protocol of this site. First confirm that the target model supports the Gemini request format, then select API Key authentication and configure the site root address and model ID.
Step one: Installation and preparation
Follow Official Installation Instructions to prepare a supported Node.js environment. Install via npm and view the version:
npm install -g @google/gemini-cli
gemini --version
Create an independent key in API Key and query Available Models. For the model to be visible, you need to confirm that it supports Gemini native protocol. You cannot directly select a model that only supports Chat.
Step 2: Set address and credentials
Bash or zsh
printf 'API Key: '
read -rs GEMINI_API_KEY
printf '\n'
export GEMINI_API_KEY
export GOOGLE_GEMINI_BASE_URL="https://dunduntoken.com"
export GOOGLE_GENAI_API_VERSION="v1beta"
export GEMINI_MODEL="GEMINI_MODEL_ID"
gemini
Windows PowerShell
$credential = Get-Credential -UserName "api" -Message "在密码栏填写本站 API Key"
$env:GEMINI_API_KEY = $credential.GetNetworkCredential().Password
Remove-Variable credential
$env:GOOGLE_GEMINI_BASE_URL = "https://dunduntoken.com"
$env:GOOGLE_GENAI_API_VERSION = "v1beta"
$env:GEMINI_MODEL = "GEMINI_MODEL_ID"
gemini
Replace GEMINI_MODEL_ID with the model ID available for the current key. These variables only take effect on the current terminal and its child processes.
| Variable | Purpose |
|---|---|
GEMINI_API_KEY |
Use this site API Key |
GOOGLE_GEMINI_BASE_URL |
Use the root address of this site without appending /v1beta |
GOOGLE_GENAI_API_VERSION |
Used by client v1beta version path |
GEMINI_MODEL |
Specify actual model ID |
Step 3: Select API Key authentication
Select Gemini API Key authentication on first launch. Clients that have logged in using other methods can switch the authentication method through /auth.
When you need to explicitly save the authentication method, back up and merge the settings in user-level ~/.gemini/settings.json:
{
"security": {
"auth": {
"selectedType": "gemini-api-key"
}
}
}
This site’s key is used in conjunction with the Gemini API Key mode. Google login and Vertex project credentials are other connection methods and will not be automatically switched due to setting the site key.
Optional: Save user-level environment configuration
After successful terminal verification, the variables can be saved to ~/.gemini/.env in the user directory to avoid resetting each time:
GEMINI_API_KEY=YOUR_DUNDUN_API_KEY
GEMINI_MODEL=GEMINI_MODEL_ID
GOOGLE_GEMINI_BASE_URL=https://dunduntoken.com
GOOGLE_GENAI_API_VERSION=v1beta
Replace key and model placeholders. This file contains usable keys and should be restricted to local access and not put into repositories or publicly synced. Environment variables and project configuration may affect the loading results; exit the old process after modification and restart.
Step 4: Send request and verify tool
Execute in the terminal where the variables have been set:
gemini -p "Reply with OK only." --output-format json
Confirm receipt of the reply, and then go to Call Record on this site to check the model and status. Then start an interactive session, request to read a file in the test project, and verify the tool call separately.
The final generated address should be /v1beta/models/{model}:generateContent or the corresponding streaming method. The success of ordinary text requests does not mean that all CLI auxiliary interfaces are available; this site currently does not implement countTokens. If a certain version relies on this call, it is necessary to distinguish between the failure of the auxiliary interface and the failure of the generated interface.
FAQ
| Phenomenon | Troubleshooting steps |
|---|---|
| Google login still pops up | Check the authentication method, use API Key mode and restart |
401 |
Check the key and key status in the actual process |
404 |
Check whether /v1beta is repeatedly spliced and confirm the model agreement |
| No change after configuration modification | Check the coverage relationship between project .env, process variables and user configuration |
| Tool or auxiliary request failed | Keep the error path and check the interface and model capabilities; do not directly apply other platform patches |
Continue reading
Gemini native protocol · CC-Switch · Error troubleshooting
Field basis: Gemini CLI official configuration reference.