Host Claude AI agent trên Business Hosting TND
Build voice + text agent chạy 24/7 trên Business Hosting Việt Nam với Anthropic SDK, Webhook, FastAPI và Redis. RAM 8GB đủ chạy production cho 5000 user/ngày - không cần VPS đắt tiền.
TL;DR
Business Hosting TND (8GB RAM, 4 vCPU, SSD NVMe 100GB, 89.000đ/tháng) đủ host 1 Claude agent serving ~5000 user/ngày. Stack: FastAPI + Anthropic SDK Python + Redis (cache prompt) + PostgreSQL (history). Chi phí Claude API ~$0.003/request, không tốn server CPU đáng kể vì model chạy trên cloud Anthropic.
Tại sao Business Hosting đủ chạy AI agent
Một nhầm lẫn phổ biến: nghĩ rằng "chạy AI agent" = cần GPU mạnh. Sai. Claude agent của bạn chỉ là 1 API gateway nhận request từ user, forward sang Anthropic Cloud, lưu history, và trả response về. Toàn bộ compute heavy (model inference) chạy trên server Anthropic ở Mỹ - bạn không cần GPU. Một con server 8GB RAM thậm chí 4GB cũng dư.
Các tài nguyên thật sự cần:
- RAM: 2GB cho FastAPI process, 1GB Redis cache, 1GB PostgreSQL = 4GB là đủ.
- CPU: chỉ dùng khi parse JSON, encode/decode payload. 2 vCPU đủ cho 200 req/s.
- Bandwidth: response Claude trung bình 4KB, 5000 user × 5 lượt/ngày × 4KB = 100MB/ngày. Hosting unmetered là quá đủ.
- Latency: từ DC Việt Nam đến API Anthropic (us-west) ~165ms. Không bottleneck với streaming response.
Kiến trúc tổng quan
3 thành phần chính, deploy trên cùng 1 server Business Hosting:
- Edge layer: nginx reverse proxy + Let's Encrypt SSL + rate limit (20 req/min/IP).
- App layer: FastAPI app chạy uvicorn 4 workers + supervisor giữ process sống.
- Data layer: PostgreSQL 16 (history, user metadata) + Redis 7 (cache + queue).
Cài đặt từ đầu
Bước 1: Setup Python 3.11 + uv
# SSH vào hosting
ssh [email protected]
# Cài Python 3.11 + uv (faster pip)
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv .venv
source .venv/bin/activate
uv pip install fastapi uvicorn[standard] anthropic redis psycopg[binary] python-dotenv pydantic
Bước 2: FastAPI agent endpoint
# app.py
from fastapi import FastAPI, HTTPException, BackgroundTasks
from pydantic import BaseModel
from anthropic import Anthropic
import redis, os, json, hashlib
app = FastAPI()
client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
r = redis.Redis(decode_responses=True)
class ChatReq(BaseModel):
user_id: str
message: str
session_id: str | None = None
@app.post("/chat")
async def chat(req: ChatReq, bg: BackgroundTasks):
# Cache key cho FAQ phổ biến
key = "faq:" + hashlib.sha256(req.message.encode()).hexdigest()[:16]
cached = r.get(key)
if cached:
return {"reply": cached, "cached": True}
# Lấy lịch sử 10 turns gần nhất
history = json.loads(r.get(f"sess:{req.session_id}") or "[]")[-10:]
history.append({"role": "user", "content": req.message})
msg = client.messages.create(
model="claude-haiku-4-5",
max_tokens=1024,
system="Bạn là trợ lý chăm sóc khách hàng của TND. Trả lời ngắn gọn, lịch sự.",
messages=history,
)
reply = msg.content[0].text
history.append({"role": "assistant", "content": reply})
r.setex(f"sess:{req.session_id}", 3600, json.dumps(history))
# Cache FAQ 24h
if len(req.message) < 80:
r.setex(key, 86400, reply)
bg.add_task(log_to_db, req.user_id, req.message, reply)
return {"reply": reply, "cached": False}
Bước 3: Webhook nhận từ Facebook Messenger
Plug Claude agent vào Messenger fanpage facebook.com/www.tnd.vn:
@app.post("/webhook/messenger")
async def messenger(payload: dict):
for entry in payload.get("entry", []):
for msg in entry.get("messaging", []):
sender = msg["sender"]["id"]
text = msg.get("message", {}).get("text", "")
if not text: continue
reply = await chat(ChatReq(
user_id=sender, message=text, session_id=f"fb:{sender}"
), BackgroundTasks())
await send_messenger(sender, reply["reply"])
return {"status": "ok"}
Tối ưu chi phí Claude API
Pricing Anthropic tháng 5/2026:
| Model | Input /1M token | Output /1M token | Phù hợp |
|---|---|---|---|
| Claude Haiku 4.5 | $0.80 | $4.00 | FAQ, chat đơn giản |
| Claude Sonnet 4.7 | $3.00 | $15.00 | Agent phức tạp, tool use |
| Claude Opus 4.7 | $15.00 | $75.00 | Reasoning sâu, code |
Với chatbot fanpage thông thường, 1 request = ~200 token input + ~150 token output. Dùng Haiku: $0.80 × 0.0002 + $4 × 0.00015 = $0.00076/request, tức ~20đ. 5000 user × 5 lượt = 25.000 request/ngày × 20đ = 500.000đ/ngày Claude API.
Mẹo giảm 60% chi phí: bật prompt caching của Anthropic cho system prompt dài (knowledge base, FAQ). Cache TTL 5 phút, sau lần đầu chỉ tính $0.08/1M token thay vì $0.80 - giảm 90% cost input.
Áp dụng prompt caching
msg = client.messages.create(
model="claude-haiku-4-5",
system=[
{"type": "text", "text": "Bạn là trợ lý TND. Trả lời ngắn."},
{"type": "text", "text": KNOWLEDGE_BASE_LONG_TEXT,
"cache_control": {"type": "ephemeral"}}
],
messages=history,
)
Voice agent: thêm STT + TTS
Mở rộng agent thành voice qua Twilio + Whisper + ElevenLabs:
- Inbound call tới số Twilio Việt Nam (~250K/tháng) → webhook về
/voice/inbound. - STT: stream audio chunk → OpenAI Whisper API ($0.006/phút).
- Claude: nhận text, generate reply.
- TTS: ElevenLabs Vietnamese voice ($0.30/1K char) → trả audio cho Twilio play.
Latency end-to-end: STT 800ms + Claude 1.2s + TTS 600ms = ~2.6s per turn. Đủ tự nhiên cho call center inbound. Chi phí 1 cuộc gọi 5 phút ~12.000đ.
Scale lên: khi nào nâng cấp khỏi Business Hosting
Business Hosting 8GB phù hợp đến ~10.000 req/ngày. Vượt mức này, các nâng cấp lần lượt:
- 10K-50K req/ngày: chuyển sang Cloud VPS 16GB RAM, 8 vCPU (~349K/tháng). Tách Redis + Postgres ra container riêng.
- 50K-200K req/ngày: thêm VPS n8n riêng để xử lý workflow background (gửi email, sync CRM).
- >200K req/ngày: dedicated server hoặc cluster K8s. Cân nhắc dùng Cloud Phone Android farm cho voice agent đa thuê bao.
Tích hợp với Cloud Phone - agent OmniChannel
Kết hợp Claude agent với Cloud Phone Android để xử lý Zalo, Messenger, TikTok DM:
- Cloud Phone chạy 24/7, login Zalo/TikTok/Messenger thật.
- ADB bridge từ Business Hosting → đọc tin nhắn mới qua accessibility service.
- Forward text về Claude agent → reply tự động, simulate gõ phím trên Cloud Phone.
Mô hình này phù hợp seller bán hàng trên 5+ platform mà không bị ban vì login Zalo từ server (vẫn login từ Android thật).
Bảo mật và compliance
- API key Anthropic: chỉ lưu trong
/etc/secrets/anthropic.env, chmod 600, KHÔNG commit lên Git. - Rate limit: nginx
limit_req_zone $binary_remote_addr zone=ai:10m rate=20r/m, tránh bị quét và burn quota. - PII redaction: trước khi gửi message lên Anthropic, redact số CMND, số thẻ, số điện thoại bằng regex. Tuân thủ Nghị định 13/2023/NĐ-CP về bảo vệ dữ liệu cá nhân.
- Audit log: lưu full prompt + response vào PostgreSQL có encryption at rest, retain 90 ngày rồi xoá.
TND đề xuất: nếu bạn chạy agent cho khách hàng VN, host trên Business Hosting Việt Nam (DC FPT/Viettel) để dữ liệu PII không leave Vietnam. Latency thấp + tuân thủ pháp lý local.
Monitoring và observability
Dùng Grafana + Prometheus + Loki, all-in-one trên cùng server:
- Metric: req/s, latency p50/p95/p99, token usage/giờ, cost ước tính.
- Alert: nếu cost vượt 1.5M/ngày → gửi Telegram cho admin.
- Trace: OpenTelemetry attach vào FastAPI middleware, xem chain STT → Claude → TTS.
FAQ
Q: Tôi có cần GPU cho Claude agent không?
Không. Claude chạy trên cloud Anthropic. Bạn chỉ cần CPU + RAM nhẹ. GPU chỉ cần khi self-host local model (xem chạy Llama 3.3 70B trên GPU VPS).
Q: Business Hosting có cho long-running process không?
Có. TND Business Hosting cho phép systemd/supervisor + cron + WebSocket. Khác với shared hosting truyền thống.
Q: Backup database thế nào?
TND tự động snapshot toàn server mỗi 24h, retain 7 ngày, miễn phí. Bạn có thể thêm pg_dump hàng giờ đẩy lên S3-compatible storage.
Triển khai Claude agent ngay hôm nay
Business Hosting 8GB RAM, Python 3.11, SSH full root từ 89.000đ/tháng. Tặng 30 ngày dùng thử.
Cần tư vấn license + hạ tầng tại TND?
TND đại lý chính thức Microsoft / Adobe / Kaspersky / AutoDesk / VMware / TeamViewer / JetBrains tại Việt Nam - license genuine 100%, kích hoạt online từ nhà sản xuất. Hoá đơn VAT điện tử Thông tư 78 đầy đủ cho doanh nghiệp.