Build Your Own AI Proxy Server: Master sub2api & Docker Deployment for Cost-Effective GPT-5.5 Access
Tutorial: How to Build a self-hosted AI Proxy Server
💡 Core Concept: We are using an open-source engine called sub2api. It ACTs as a "translator" and "traffic dispatcher," converting the web session capability of your chatgpt accounts into OpenAI/anthropic protocol-compliant API Keys.
1. Prerequisites & Environment Setup
Server: A Virtual Private Server (VPS) located overseas (e.g., AWS, Tencent Cloud, etc.). I recommend a 2 Core 4GB configuration running Ubuntu (e.g., Tencent Cloud at ~$199/year).
Location: Select nodes in Japan, USA (Silicon Valley), or Europe. Avoid Hong Kong nodes for stability.
Access: Root SSH access to the server.
Connect to your server via SSH:
ssh root@your_server_ip
Step 2: Update System & Install Dependencies
Update the package list and install basic dependencies:
sudo apt update && sudo apt upgrade -y sudo apt install -y ca-certificates curl gnupg
Step 3: Install Docker & docker Compose
sub2api relies heavily on Docker. Add the official Docker repository and install the engine:
# Add Docker's official GPG key sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL https://download.docker.com/Linux/ubuntu/gpg | sudo gpg --deArmor -o /etc/apt/keyrings/docker.gpg sudo chmod a+r /etc/apt/keyrings/docker.gpg # Set up the repository echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linUX/ubuntu \ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null # Install Docker Engine sudo apt update sudo apt install -y docker-ce docker-ce-CLI containerd.io docker-buildx-plugin docker-compose-plugin # Start and enable Docker service sudo systemctl enable --now docker
Step 4: Verify installation
Run a test container to ensure Docker is working:
sudo docker run hello-world
2. Deploy sub2api Service
mkdir -p sub2api cd sub2api curl -sSL https://raw.GitHubusercontent.com/Wei-Shaw/sub2api/main/deploy/docker-deploy.sh | bash
Step 2: Start the Container
docker compose up -d
Open your browser and navigate to
http://your_server_ip:8080.If the page loads, the deployment was successful.
If the page is unreachable, check the Docker service status:
docker compose ps.Ensure your server's Firewall and Security Group rules allow traffic on port 8080.
The first login requires a generated password. Retrieve it via:
docker compose logs sub2api | grep "admin password"
Username:
admin@sub2api.localPassword: (The one-time password shown in the logs)
3. Secure the Server with SSL (HTTPS)
curl https://get.acme.sh | sh
Point your domain (e.g.,
sub2api.yourdomain.com) to your server's IP address. Verify the DNS propagation using ping.Stop Nginx (if running) and issue the certificate using the standalone mode:
# Stop Nginx to free port 80 systemctl stop nginx # Issue certificate (Replace with your domain) /root/.acme.sh/acme.sh --issue -d sub2api.yourdomain.com --standalone --force
Step 4: Install Certificate to Target Directory
Copy the certificate files to your sub2api SSL folder:
# Create SSL directory mkdir -p /root/sub2api/ssl # Install certificate /root/.acme.sh/acme.sh --install-cert -d sub2api.yourdomain.com \ --key-file /root/sub2api/ssl/sub2api.key \ --fullchain-file /root/sub2api/ssl/sub2api.pem \ --reloadcmd "systemctl reload nginx"
Step 5: Configure Nginx reverse proxy
Create an Nginx configuration file (/etc/nginx/conf.d/sub2api.conf) with the following content:
server {
listen 80;
server_name sub2api.yourdomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name sub2api.yourdomain.com;
underscores_in_headers on;
# SSL Certificates
ssl_certificate /root/sub2api/ssl/sub2api.pem;
ssl_certificate_key /root/sub2api/ssl/sub2api.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers on;
# Reverse Proxy to sub2api
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $rEMOte_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
}
}systemctl start nginx. You can now access your dashboard via HTTPS.4. Configure Accounts & API Keys
Go to "Group Management" -> "Create Group."
Platform: openai
Name: Your preferred name.
Self-Usage Rate: Set to
1.
Go to "Account Management" -> "Add Account."
Select OpenAI platform and OAuth authorization method.
Crucial Step: Clear the default model list. This allows the proxy to automatically recognize new models (like GPT-5.5) without manual updates.
Set concurrency (e.g., 10-100 depending on your account's capability).
Generate the authorization link and open it in an Incognito browser window.
Log in with your ChatGPT credentials (or Team workspace).
Note: After login, the page may show an error or go blank. This is normal. Copy the entire URL from the browser's address bar and paste it back into the sub2api confirmation box.
Navigate to "API Key" management and generate a new key.
Go to "User Management" and recharge your account with a high value (e.g., 99999999). Without sufficient balance, you will encounter an
INSUFFICIENT_BALANCE error.5. Testing & Integration
GPT-5.5 or Claude-3-Opus). A successful response indicates the proxy chain is working.You can now use this API key in various development tools:
cc-switch: A powerful routing tool to manage multiple keys.
Codex CLI, openclaw, Hermes: Configure these tools to use your self-hosted proxy endpoint.
By following this guide, you have successfully built a cost-effective AI proxy station. This setup drastically reduces your reliance on expensive official APIs while providing the flexibility to use cutting-edge models like gpt-5.5 through a simple web interface conversion.
Comments & Questions (0)
No comments yet
Be the first to comment!