# Configuring CliProxyAPI (CPA) to Reverse Proxy Gemini

> This article is currently an experimental machine translation and may contain errors. If anything is unclear, please refer to [original Chinese version](<https://blog.wendain.ing/posts/using-cpa/>). I am continuously working to improve the translation.

## Preface

A while back while scrolling Zhihu, I saw someone say that you could reverse proxy the Gemini API through **some means**, and combined with the dirt-cheap Gemini Pro accounts / top-up services all over Xianyu, you could have a great time.

Then these past couple of days while idling in group chats, I saw someone mention the term **CPA**. I started asking GPT what it was and couldn't even get an answer xD — only by asking directly did I learn it's **Cli Proxy API**.

I looked it up and found it needs to be deployed on a server, so here's a simple tutorial.

## Installing on the Server

CPA's official documentation is written **extremely badly** (**not fit for human consumption**), so it's best to just let an Agent do the work.

I threw this Prompt straight at the Agent:

> Requirements:
>
> - Install according to the current official documentation ([https://help.router-for.me/cn/introduction/quick-start.html](https://help.router-for.me/cn/introduction/quick-start.html)), preferring the official Linux one-click install script (`curl -fsSL https://raw.githubusercontent.com/router-for-me/cliproxyapi-installer/refs/heads/master/cliproxyapi-installer| bash`).
> - Configure it as a systemd service with auto-start on boot.
> - CPA should listen on `127.0.0.1:8317`; do not expose it directly to the public internet.
> - The configuration files and OAuth credentials must be persisted.
> - First help me set up Gemini CLI / Google OAuth login.
> - After OAuth is complete, verify CPA works properly using `/v1/models` and an actual Gemini request.
> - Do not install New API, Sub2API, or other unrelated components.
> - Do not break any existing services on the server.
>
> Before executing, first check the system, any existing CPA installation, port 8317, and the systemd status. Stop and tell me when you need me to open the OAuth link and take action.

Then just wait.)

> [!caution]
>
> Note that I'm using a Linux system here. Users of other systems should consult the documentation to adjust the installation method.)
>
> (Though if you're already running a server, does anyone actually use Windows Server?)

## Accessing the WebUI

You can access CPA's WebUI at http://127.0.0.1:8317/management.html, but first we need to configure a password:

Open an editor and edit the `~/cliproxyapi/config.yaml` file, and find this section:

```yaml
remote-management:
  allow-remote: false
  secret-key: "这里填刚生成的密钥"
  disable-control-panel: false
```

Then, set up an SSH tunnel:

```sh
ssh -N -L 8317:127.0.0.1:8317 tencent-lighthouse
```

Now you can access it from your local browser.

## Setting Up OAuth

![673](https://image.wendaining.top/0x0sd02mm.png)

Configure the login here and just follow the subsequent instructions.

—That's how it should have gone, but I ran into a problem, because I forgot to set up a proxy on my server.)

So I opened a new session, installed the Mihomo core along with its WebUI (MetacubeX), and configured the network proxy (it's not recommended to enable the system proxy or TUN on a server, as it may affect SSH performance):

![638](https://image.wendaining.top/20260904_193809.png)

Just enter it here; `7890` is the Mihomo core's port.

Then the configuration went through fine.

## Using the API

After importing the authentication file, you can use the API — the key is the one in the bottom half of the previous screenshot.

But here CPA's terrible documentation strikes again: no matter how I looked, I couldn't find what the URL was supposed to be — is this OpenAI's or A\ 's?

I asked an LLM and got the answer, though who knows why, but it works anyway:

```text
Provider: OpenAI / OpenAI Compatible
Base URL: http://127.0.0.1:8317/v1
API Key: "YOUR API KEY"
```

It provides a Model List, which is all the currently available models. Anyway, it's usable now.

Honestly, it's a bit crude — there's no way to do "restrict the model list for a specific key". The solution is to put an API gateway in front of it, such as new-api.
