Zero-config intelligent egress: discovers, verifies, latency-ranks, rotates, and prunes public HTTP/HTTPS routes with Bun TLS fingerprint synchronization, resilient proxy failover, and real-time SSE streaming.
Warning
This software project is designed and released strictly for educational, protocol research, and reverse-engineering study purposes. It demonstrates modern API translation architectures, loopback TLS fingerprint matching, dynamic proxy pool lifecycle management, and cross-schema streaming protocols between OpenAI SSE and Anthropic Messages.
The developers and contributors do not encourage, condone, or support any abuse of third-party platforms or violation of upstream Terms of Service. Users are exclusively responsible for their own usage and must ensure compliance with all applicable platform policies, terms of service, and local laws.
- What OpenCode2API Does
- Architecture & Upstream Quota Reality
- Key Features in v3.1.0
- Discovered Models Roster
- Quickstart: Local Installation (Recommended)
- Quickstart: Docker & Docker Compose
- Deploying to Dokploy / Coolify
- Zero-Cost Remote Access via Cloudflare Tunnel
- Turnkey PowerShell Testing Scripts
- API Usage Examples
- Configuration Reference
- License
OpenCode2API acts as a drop-in gateway translating standard OpenAI (/v1/chat/completions) and Anthropic (/v1/messages) requests to OpenCode Zen inference endpoints. It eliminates the friction of proprietary CLI formats, offering:
- Universal Client Support: Works natively in Cursor, VS Code (Continue/Cline), LibreChat, OpenAI SDK, Anthropic SDK, LangChain, and LiteLLM.
- Deep Reasoning Traces: Streams interleaved
<think>blocks asreasoning_content(OpenAI) andthinking_delta(Anthropic). - Core Tool Calling: Merges OpenCode CLI tool schemas upstream while allowing custom client function calling.
- Vision Integration: Accepts multi-modal images via OpenAI base64
image_urland Anthropicimageblocks. - Built-in Control Plane: React-based dashboard with live request telemetry, interactive playground, scoped
O2P-API key manager, and proxy diagnostics.
When using the anonymous free tier (Authorization: Bearer public), OpenCode enforces per-IP rate limiting and daily usage quotas guarded by Cloudflare bot management:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β UPSTREAM EGRESS ARCHITECTURE β
βββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ€
β Local PC (Residential ISP) β Cloud VPS / Public Datacenter Proxies β
βββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββ€
β β
Clean Residential IP Range β β Shared Datacenter ASN (AWS/Hetzner) β
β β
Never flagged by Bot Guard β β Cloudflare IP reputation penalty β
β β
Full Free Daily Quota β β Shared Free Quota exhausted early β
β β
100% Success Rate (2β4s) β β οΈ Returns FreeUsageLimitError (429) β
βββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββ
When public proxies from scraped lists are used on cloud servers (Dokploy, VPS, AWS), Cloudflare detects datacenter ASN ranges where multiple bots have already burned the anonymous free tier quota for that day, returning:
{
"type": "error",
"error": {
"type": "FreeUsageLimitError",
"message": "Free usage limit reached. Free models work in OpenCode (https://opencode.ai); subscribe to OpenCode Go to keep going: https://opencode.ai/go"
}
}(With an upstream Retry-After: 41514 header resetting at midnight UTC).
Depending on your environment, you can achieve 100% zero-drop pass rates:
- Dedicated Rotating Proxy (Single Endpoint): Add a single rotating proxy endpoint (Webshare, Smartproxy, Oxylabs, BrightData, IPRoyal) under Settings -> Rotating Proxy Gateway. Each request exits through a different residential/mobile IP automatically, eliminating IP rate limits and avoiding 60s quota lockouts without maintaining proxy lists.
- Local Daemon (Zero Cost, 100% Free): Running OpenCode2API on your local machine uses your personal broadband/residential IP. It bypasses Cloudflare datacenter blocks with 100% success rate across all models.
- Upstream Zen Key (Recommended for Cloud VPS / Dokploy):
Add your genuine OpenCode Zen Key / API key in Dashboard Settings or via
OPENCODE_ZEN_KEYenvironment variable. Authenticated requests useBearer <key>, completely bypassing anonymous IP quotas on any server. - Scraped / Manual US Proxy Pool: If hosting on a VPS without a Zen key or rotating proxy, enable automatic discovery or paste manual proxy URLs under Proxy Egress -> Manual Proxies.
- π Dedicated Rotating Proxy Support: Add a single rotating proxy endpoint in the dashboard instead of managing multi-line lists. Auto-injects dynamic session identifiers and closes TCP keep-alive sockets per request, forcing fresh exit IPs and eliminating 429 quota lockouts.
- β‘ Ultra-Strict 3s High-Throughput Scraper & 5x Verifier: Hard 3000ms screening timeout, 5 consecutive verification checks, and parallelized multi-threaded screening (200 workers) and verification (60 workers) across high-yield public sources.
- π Instant Rate-Limit & Quota Switching: Zero-latency proxy hopping on upstream 429 or quota limits without artificial delays or hangs. Individual proxy timeouts bounded to prevent client hanging.
- π§΅ Loopback Bun TLS Bridge: OpenCode's upstream gate rejects Node.js TLS fingerprints. v3.1.0 launches an embedded Bun worker under
BUN_BE_BUN=1using OpenCode CLI v2.1.4, matching upstream client fingerprints byte-for-byte. - β‘ Latency-Ranked Routing: Active proxies are sorted dynamically by measured latency ascending; completions round-robin exclusively across the top 12 fastest routes.
- π‘οΈ Pool-First Sequential Failover: When a proxy hits an upstream rate limit, it cools down and immediately fails over to the next fastest proxy in the pool (up to 20 failovers) before attempting fallback.
- π 13 US-Targeted Proxy Sources: Continuously screens candidates targeting United States endpoints to eliminate
RegionError: This model is not available in your country(403). - π Bun Proxy Protocol Safety: Enforces pure HTTP/HTTPS CONNECT tunneling across all scraped candidates, eliminating
UnsupportedProxyProtocolcrashes. - π No Synthetic Telemetry: Real 60-second sliding-window RPM, TPM, latency, and token allocation calculations with detailed request audit logs.
Discovered and dynamically mapped from OpenCode Zen:
| Model ID | Provider | Context | Modality | Reasoning |
|---|---|---|---|---|
big-pickle |
OpenCode Zen | 128k | Text | β Extended |
beam |
OpenCode Zen | 128k | Text | β Native |
glm-5.3-flash |
GLM / Zhipu | 128k | Text / Code | β Native |
deepseek-v4.1-flash |
DeepSeek | 128k | Text / Code | β Native |
mimo-v2.6-flash |
Mimo | 128k | Multimodal Vision | β Standard |
nemotron-3.5-super-vl |
NVIDIA | 128k | Multimodal Vision | β Standard |
nemotron-3.5-lightning |
NVIDIA | 128k | Text / Code | β Fast |
flint-40b |
Flint | 128k | Text / Code | β Standard |
Running locally gives you 100% free, unthrottled access through your residential connection.
- Node.js: v20 or higher installed (nodejs.org)
- OpenCode CLI: Installed globally for the Bun TLS engine:
npm install -g @opencode/cli@2.1.4
git clone https://github.com/Nystic-Shadow/Opencode2api.git
cd Opencode2api
npm install
npm run build# Windows PowerShell
$env:DASHBOARD_PASS="762920"; npm start
# Linux / macOS
DASHBOARD_PASS="762920" npm start- Dashboard & Playground: http://127.0.0.1:8080/
- API Base URL:
http://127.0.0.1:8080/v1 - Master API Key: View in
data/keys.jsonor dashboard.
Deploy a self-contained container with Node.js 20 and OpenCode CLI bundled:
# 1. Clone repository
git clone https://github.com/Nystic-Shadow/Opencode2api.git
cd Opencode2api
# 2. Configure environment
cp .env.example .envEdit .env:
PORT=8080
DASHBOARD_USER=admin
DASHBOARD_PASS=MySecretPassword123!
EGRESS_MODE=auto
AUTO_PROXY_TARGET=100
ALLOW_DIRECT_FALLBACK=trueStart the stack:
docker compose up -d --buildOpenCode2API deploys seamlessly on Dokploy or Coolify:
- Create a new Application in Dokploy from GitHub repository:
https://github.com/Nystic-Shadow/Opencode2api.git(Branch:main). - Build Type: Dockerfile (Port:
8080). - Set Environment Variables:
DASHBOARD_USER=shadow DASHBOARD_PASS=762920 EGRESS_MODE=auto AUTO_PROXY_TARGET=100 ALLOW_DIRECT_FALLBACK=true OPENCODE_ZEN_KEY=your_optional_zen_key_here
- Click Deploy. Dokploy will build the image, initialize the Bun TLS bridge, and start serving.
Want to access your local residential gateway from your phone, laptop, or cloud apps without port-forwarding or public IP exposure?
Run Cloudflare Tunnel directly on your local machine:
npx cloudflared tunnel --url http://127.0.0.1:8080Cloudflare generates a secure, free HTTPS URL (e.g. https://random-subdomain.trycloudflare.com). You now have an internet-accessible gateway powered by your clean residential IP!
Ready-to-use PowerShell verification scripts are included in scripts/:
powershell -ExecutionPolicy Bypass -File scripts\test-chat.ps1 -Model "big-pickle"(Supports -Model "beam", -Model "glm-5.3-flash", -Model "deepseek-v4.1-flash").
Streams characters live to console and calculates Time-To-First-Token (TTFT) and token velocity:
powershell -ExecutionPolicy Bypass -File scripts\test-stream.ps1 -Model "glm-5.3-flash"curl http://127.0.0.1:8080/v1/chat/completions \
-H "Authorization: Bearer O2P-54ce9d315cbf95864a41accc5e2fc69e" \
-H "Content-Type: application/json" \
-d '{
"model": "big-pickle",
"messages": [
{"role": "user", "content": "Explain quantum superposition in 20 words."}
],
"stream": false
}'curl http://127.0.0.1:8080/v1/messages \
-H "x-api-key: O2P-54ce9d315cbf95864a41accc5e2fc69e" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.3-flash",
"max_tokens": 150,
"messages": [
{"role": "user", "content": "Write a haiku about high-speed AI gateways."}
]
}'from openai import OpenAI
client = OpenAI(
base_url="http://127.0.0.1:8080/v1",
api_key="O2P-54ce9d315cbf95864a41accc5e2fc69e"
)
response = client.chat.completions.create(
model="glm-5.3-flash",
messages=[{"role": "user", "content": "Count from 1 to 10."}],
stream=True
)
for chunk in response:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
print()Key environment variables in .env:
| Variable | Default | Description |
|---|---|---|
PORT |
8080 |
Port for the gateway server |
DASHBOARD_USER |
admin |
Admin dashboard username |
DASHBOARD_PASS |
Auto-generated | Admin dashboard password (min 12 chars) |
OPENCODE_ZEN_KEY |
"" |
Optional OpenCode Zen Key for paid/authenticated quota |
ROTATING_PROXY_ENABLED |
false |
Enable dedicated single rotating proxy mode |
ROTATING_PROXY_URL |
"" |
Backconnect rotating proxy URL (http://user:pass@host:port) |
ROTATING_PROXY_SESSION_MODE |
auto |
Session rotation strategy (auto, session_suffix, disabled) |
EGRESS_MODE |
auto |
Egress mode (auto, proxy_only, direct) |
ALLOW_DIRECT_FALLBACK |
true |
Fallback to host egress if all proxies are exhausted |
AUTO_PROXY_TARGET |
100 |
Target verified proxy pool size |
MAX_PROXY_POOL |
150 |
Maximum combined proxy pool capacity |
PROXY_QUOTA_FAILOVERS |
10 |
Maximum proxy hops on 429 quota before deadline |
REQUEST_TIMEOUT_MS |
30000 |
Timeout per inference attempt (30 seconds) |
REQUEST_DEADLINE_MS |
90000 |
Total end-to-end inference deadline (90 seconds) |
GLOBAL_CONCURRENCY |
8 |
Maximum simultaneous upstream inferences |
This project is licensed under the MIT License β see the LICENSE file for details.
Developed for educational and technical research into high-performance AI gateways and reverse-proxy protocol adapters.