
Dev VN dùng Claude Code, Cline, OpenCode, Aider, Codex CLI ngày càng nhiều - và càng dùng càng gặp 2 vấn đề: rate limit theo IP (Anthropic, OpenAI limit per-IP) và latency US-VN trên đường truyền consumer (FPT, Viettel, VNPT). Route AI agent traffic qua proxy IPv4 dedicated US giúp giảm latency (peering tốt hơn) và tách quota theo IP. Bài này hướng dẫn cấu hình HTTPS_PROXY env variable cho 5 AI coding agent phổ biến + verify traffic qua mitmproxy.
Mục lục
- Vì sao dev cần proxy cho AI agent
- Environment variable HTTPS_PROXY HTTP_PROXY ALL_PROXY NO_PROXY
- Cấu hình Claude Code (Anthropic CLI)
- Cấu hình Cline (VS Code extension)
- Cấu hình OpenCode (Continue.dev)
- Cấu hình Aider (Python CLI)
- Cấu hình Codex CLI
- Verify traffic qua mitmproxy
- Benchmark latency US-VN qua TND IPv4
- Use case: rate limit, geo API, test scrape giả lập
1. Vì sao dev cần proxy cho AI agent
- Rate limit per-IP: Anthropic/OpenAI có quota theo IP, dùng quá bị 429 Too Many Requests. Proxy fresh IP reset quota.
- Latency tối ưu: Đường truyền consumer VN sang AWS US thường có hop chậm. TND peering tốt với US backbone, latency ổn định hơn.
- Geo-restricted API: Một số feature OpenAI/Google chỉ active cho IP US (vd: GPT-4o realtime API).
- Isolation per project: Mỗi client/project 1 IP riêng, audit clean, không lẫn quota.
- Test scrape giả lập: AI agent gửi request mô phỏng user thật từ IP US/VN cho QA test.
2. Environment variable HTTPS_PROXY HTTP_PROXY ALL_PROXY NO_PROXY
Hầu hết tool Unix-based (Node.js, Python, cURL, wget) đọc proxy config từ environment variable:
| Variable | Mục đích | Format |
|---|---|---|
HTTP_PROXY |
Proxy cho request HTTP | http://user:pass@ip:port |
HTTPS_PROXY |
Proxy cho request HTTPS (CONNECT) | http://user:pass@ip:port |
ALL_PROXY |
Proxy cho mọi protocol (SOCKS5) | socks5://user:pass@ip:port |
NO_PROXY |
Domain bypass proxy | localhost,127.0.0.1,*.local |
Set trong shell session (bash/zsh):
export HTTPS_PROXY="http://us01_S21130_P60:••••••••@23.155.xxx.xxx:2021" export HTTP_PROXY="http://us01_S21130_P60:••••••••@23.155.xxx.xxx:2021" export ALL_PROXY="socks5://us01_S21130_P60:••••••••@23.155.xxx.xxx:2020" export NO_PROXY="localhost,127.0.0.1,.local"
Permanent: thêm vào ~/.bashrc hoặc ~/.zshrc.
Windows PowerShell:
$env:HTTPS_PROXY="http://us01_S21130_P60:••••••••@23.155.xxx.xxx:2021" $env:HTTP_PROXY=$env:HTTPS_PROXY # Permanent: setx HTTPS_PROXY "..."
3. Cấu hình Claude Code (Anthropic CLI)
Claude Code là CLI Node.js của Anthropic. Nó respect HTTPS_PROXY env tự động.
# 1. Set env variable export HTTPS_PROXY="http://us01_S21130_P60:••••••••@23.155.xxx.xxx:2021" # 2. Run Claude Code claude # 3. Verify - trong session Claude: /status # Hiển thị: Network: proxy http://...:2021
Hoặc set trong ~/.claude/settings.json:
{
"proxy": "http://us01_S21130_P60:••••••••@23.155.xxx.xxx:2021"
}
4. Cấu hình Cline (VS Code extension)
Cline (former Claude Dev) là VS Code extension. Settings > Cline:
- API Provider: Anthropic / OpenAI / OpenRouter / Custom
- API Base URL: giữ mặc định
- Proxy URL: điền
http://us01_S21130_P60:••••••••@23.155.xxx.xxx:2021
Hoặc set env trước khi mở VS Code:
HTTPS_PROXY="http://..." code .
5. Cấu hình OpenCode (Continue.dev)
OpenCode là fork mã nguồn mở từ Continue.dev. Config file ~/.continue/config.json:
{
"models": [{
"title": "Claude 3.7 Sonnet",
"provider": "anthropic",
"model": "claude-3-7-sonnet-20250219",
"apiKey": "sk-ant-...",
"requestOptions": {
"proxy": "http://us01_S21130_P60:••••••••@23.155.xxx.xxx:2021"
}
}]
}
6. Cấu hình Aider (Python CLI)
Aider là Python CLI - dùng env variable hoặc .aider.conf.yml:
# ~/.aider.conf.yml openai-api-base: https://api.openai.com/v1 anthropic-api-base: https://api.anthropic.com
Set env variable trong shell trước run aider:
export HTTPS_PROXY="http://us01_S21130_P60:••••••••@23.155.xxx.xxx:2021" aider --model claude-3-7-sonnet-20250219
Aider dùng Python requests + litellm nên auto pick HTTPS_PROXY env.
7. Cấu hình Codex CLI
Codex CLI (OpenAI's terminal-based coding agent) là Node.js. Cấu hình:
export HTTPS_PROXY="http://us01_S21130_P60:••••••••@23.155.xxx.xxx:2021" export NO_PROXY="localhost,127.0.0.1" codex
Hoặc trong ~/.codex/config.toml:
[network] proxy_url = "http://us01_S21130_P60:••••••••@23.155.xxx.xxx:2021"
8. Verify traffic qua mitmproxy
mitmproxy là tool inspect HTTP/HTTPS traffic ở Layer 7 - hữu ích để verify AI agent thực sự đi qua proxy TND.
# Cài mitmproxy
pip install mitmproxy
# Run local mitmproxy port 8888, upstream tới TND
mitmproxy --mode upstream:http://us01_S21130_P60:••••••••@23.155.xxx.xxx:2021 \
--listen-port 8888
# Trong terminal khác, set HTTPS_PROXY về mitmproxy local
export HTTPS_PROXY="http://localhost:8888"
# Run Claude Code
claude
# mitmproxy hiển thị mọi request đi qua, bao gồm:
# - api.anthropic.com/v1/messages
# - upstream qua TND IP 23.155.xxx.xxx
Nếu thấy traffic đi qua mitmproxy + upstream TND, setup đúng.
9. Benchmark latency US-VN qua TND IPv4
# Test direct (no proxy)
curl -o /dev/null -s -w 'DNS: %{time_namelookup}s | Connect: %{time_connect}s | TTFB: %{time_starttransfer}s | Total: %{time_total}s\n' \
https://api.anthropic.com/v1/messages -X POST \
-H "x-api-key: sk-..." -H "content-type: application/json" \
-d '{"model":"claude-3-7-sonnet-20250219","max_tokens":10,"messages":[{"role":"user","content":"hi"}]}'
# Test qua TND HTTP
HTTPS_PROXY="http://[email protected]:2021" curl -o /dev/null -s -w '...' ...
# Test qua TND SOCKS5
curl --socks5 [email protected]:2020 -o /dev/null -s -w '...' ...
| Tuyến | DNS | Connect | TTFB | Total |
|---|---|---|---|---|
| VN consumer → Anthropic direct | 20-50ms | 200-280ms | 800-1500ms | 1.5-3s |
| VN → TND US → Anthropic | 1ms (cached) | 180-220ms | 500-900ms | 1-2s |
| VN → TND VN → Anthropic | 1ms | 30ms (local) | 700-1100ms | 1.2-2.5s |
Lợi thế TND US: stable peering, ít packet loss giờ peak. Lợi thế TND VN: connect nhanh, nhưng vẫn phải qua sea cable đến US server, không nhanh hơn nhiều.
10. Use case: rate limit, geo API, test scrape giả lập
Use case 1: Tránh rate limit per-IP
Bạn chạy AI agent agressively cho 1 project, hit 429 rate limit. Tạm thời switch sang TND IPv4 #2 (1 client = 1 IP), reset quota. Đây là workaround tạm thời, lâu dài cần upgrade plan API.
Use case 2: Geo-restricted API feature
OpenAI GPT-4o realtime voice API chỉ active cho region US. Route Claude Code/Codex qua TND US, API trả về voice endpoint, work bình thường.
Use case 3: Isolation per client/project
Bạn freelance 5 client. Mỗi client 1 TND IPv4 + 1 Anthropic billing account. Audit log clean - mỗi client thấy API call từ IP cố định của họ.
Use case 4: Test geo cho automation user-facing
QA test app từ "góc nhìn user US" - Claude Code route qua TND US, kiểm tra response API có khác với user VN không.
Tổng kết
5 AI agent phổ biến (Claude Code, Cline, OpenCode, Aider, Codex) đều respect HTTPS_PROXY env hoặc có proxy field trong config. Set 1 env variable là route được. TND IPv4 dedicated US là lựa chọn phù hợp cho dev VN: latency US ổn định, IP cố định để build trust với API provider, dedicated 1 user (không bị flag liên đới).
Tham khảo thêm:
- SOCKS5 vs HTTP - chọn protocol nào cho AI agent
- Proxifier - alternative cho desktop app GUI
- Proxy cho Playwright Puppeteer automation
- IPv4 Dedicated vs Residential
Mua Proxy IPv4 Dedicated US + VN tại TND
Flat 95.000 VNĐ/IP/tháng. Fresh IP US dedicated cho AI agent: latency US ổn định, peering tốt với Anthropic/OpenAI backbone. Hỗ trợ HTTP và SOCKS5. Set HTTPS_PROXY env là chạy. Support tiếng Việt 24/7.
Tham gia nhóm Vibe Coder Việt Nam
Bạn đang code cùng Claude, Codex, Gemini, Cursor hay Windsurf? Vào nhóm Facebook để trao đổi tip, debug giúp nhau, chia sẻ workflow vibe coding, và update tool mới mỗi tuần. Cộng đồng dev tự host stack đang grow nhanh tại Việt Nam.


