Self-hosted large language model inference on a Hong Kong VPS gives Asia-Pacific applications access to capable open-source models (Llama 3, Qwen2.5, Mistral, Gemma 2) without per-token OpenAI API costs, without sending sensitive data to US servers, and with a CN2 GIA-connected endpoint that Asian application servers can reach at 30–50ms rather than 200ms+ from OpenAI’s US infrastructure.
What’s Realistic on a VPS
CPU-only inference on a VPS is practical for smaller quantised models — not for 70B+ models at production throughput. Set expectations correctly:
| Model | RAM Required | CPU Tokens/sec (8-core) | Use Case |
|---|---|---|---|
| Llama 3.2 3B (Q4) | 3 GB | 15–30 tok/s | Chat, classification, simple tasks |
| Llama 3.1 8B (Q4) | 6 GB | 8–15 tok/s | Chat, summarisation, code |
| Qwen2.5 7B (Q4) | 6 GB | 8–15 tok/s | Excellent Chinese language tasks |
| Mistral 7B (Q4) | 5 GB | 10–18 tok/s | Instruction following, reasoning |
| Gemma 2 9B (Q4) | 7 GB | 7–12 tok/s | General purpose, efficient |
| Llama 3.1 70B (Q4) | 48 GB | 1–3 tok/s | Dedicated server required |
For production API use at human typing speed (3–5 tokens/second perceived), 7–8B models on a 8–16 GB VPS are practical. For batch processing where speed is less critical, even 2–4 tok/s is useful.
Step 1: Install Ollama
<code">apt update && apt upgrade -y # Install Ollama (supports Linux x86_64 and ARM64) curl -fsSL https://ollama.com/install.sh | sh # Verify installation ollama --version systemctl status ollama
Configure Ollama for Remote Access
<code"># By default, Ollama only listens on localhost # To expose via Nginx proxy, configure the bind address: cat > /etc/systemd/system/ollama.service.d/override.conf << 'EOF' [Service] Environment="OLLAMA_HOST=127.0.0.1:11434" Environment="OLLAMA_MODELS=/opt/ollama/models" Environment="OLLAMA_NUM_PARALLEL=2" # Serve 2 concurrent requests Environment="OLLAMA_MAX_LOADED_MODELS=1" # Keep 1 model in RAM EOF mkdir -p /opt/ollama/models systemctl daemon-reload && systemctl restart ollama
Step 2: Pull Models
<code"># Pull models (downloads to /opt/ollama/models) # Best for Chinese language tasks (bilingual English/Chinese) ollama pull qwen2.5:7b # Best for English code and reasoning ollama pull llama3.1:8b # Lightweight for classification/embedding ollama pull llama3.2:3b # For embeddings (RAG applications) ollama pull nomic-embed-text # List downloaded models ollama list # Test a model ollama run qwen2.5:7b "用中文解释什么是CN2 GIA网络"
Step 3: Expose Ollama API via Nginx
<code">apt install -y nginx certbot python3-certbot-nginx
cat > /etc/nginx/sites-available/ollama << 'EOF'
server {
listen 443 ssl http2;
server_name ai.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/ai.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/ai.yourdomain.com/privkey.pem;
# Restrict access — Ollama has no built-in auth
# Option A: IP allowlist
# allow YOUR_APP_SERVER_IP;
# deny all;
# Option B: API key via Nginx
if ($http_x_api_key != "YOUR_STRONG_API_KEY") {
return 401;
}
client_max_body_size 10m;
proxy_read_timeout 300s; # LLM responses can take time
location / {
proxy_pass http://127.0.0.1:11434;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_buffering off; # Stream tokens as they generate
proxy_http_version 1.1;
proxy_set_header Connection '';
}
}
EOF
ln -s /etc/nginx/sites-available/ollama /etc/nginx/sites-enabled/
certbot --nginx -d ai.yourdomain.com
nginx -t && systemctl reload nginx
Step 4: Use the Ollama API
OpenAI-Compatible API (Drop-in Replacement)
Ollama exposes an OpenAI-compatible API — existing code using the OpenAI Python SDK or JS SDK works with only the base URL changed:
<code"># Python — with OpenAI SDK
from openai import OpenAI
client = OpenAI(
base_url="https://ai.yourdomain.com/v1",
api_key="YOUR_API_KEY_FROM_NGINX"
)
response = client.chat.completions.create(
model="qwen2.5:7b", # Use any pulled Ollama model
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Summarise this product review in Chinese: ..."}
],
stream=True
)
for chunk in response:
print(chunk.choices[0].delta.content or "", end="", flush=True)
<code"># Node.js — with OpenAI SDK
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://ai.yourdomain.com/v1',
apiKey: 'YOUR_API_KEY'
});
const stream = await client.chat.completions.create({
model: 'llama3.1:8b',
messages: [{ role: 'user', content: 'Explain VPS hosting in simple terms' }],
stream: true
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}
Direct Ollama API
<code"># Generate completion
curl https://ai.yourdomain.com/api/generate \
-H "X-Api-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "qwen2.5:7b", "prompt": "香港VPS有什么优势?", "stream": false}'
# Chat completion
curl https://ai.yourdomain.com/api/chat \
-H "X-Api-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen2.5:7b",
"messages": [{"role": "user", "content": "What is CN2 GIA routing?"}],
"stream": false
}'
Step 5: RAG (Retrieval-Augmented Generation) Setup
For production applications — customer support bots, document search, knowledge bases — RAG grounds LLM responses in your actual data rather than training data alone:
<code"># Install Chroma vector database
pip3 install chromadb --break-system-packages
# Python RAG example using Ollama embeddings
import chromadb
from openai import OpenAI
embed_client = OpenAI(base_url="https://ai.yourdomain.com/v1", api_key="KEY")
chat_client = OpenAI(base_url="https://ai.yourdomain.com/v1", api_key="KEY")
chroma = chromadb.PersistentClient(path="/opt/chroma-db")
collection = chroma.get_or_create_collection("knowledge_base")
def add_document(text, doc_id):
embedding = embed_client.embeddings.create(
model="nomic-embed-text",
input=text
).data[0].embedding
collection.add(documents=[text], embeddings=[embedding], ids=[doc_id])
def rag_query(question):
# Embed the question
q_embedding = embed_client.embeddings.create(
model="nomic-embed-text",
input=question
).data[0].embedding
# Retrieve relevant documents
results = collection.query(query_embeddings=[q_embedding], n_results=3)
context = "\n".join(results['documents'][0])
# Generate answer with context
response = chat_client.chat.completions.create(
model="qwen2.5:7b",
messages=[
{"role": "system", "content": f"Answer based on this context:\n{context}"},
{"role": "user", "content": question}
]
)
return response.choices[0].message.content
Step 6: Model Management
<code"># List models and sizes ollama list # Check which model is currently loaded in RAM curl http://localhost:11434/api/ps # Delete a model to free space ollama rm llama3.2:3b # Update a model to latest version ollama pull qwen2.5:7b # Check Ollama logs journalctl -u ollama -f
Cost Comparison: Self-Hosted vs OpenAI API
| Usage | OpenAI GPT-4o | Ollama (8B) on 8 GB VPS |
|---|---|---|
| 1M tokens/month input | $2.50 | ~$0 (VPS cost amortised) |
| 1M tokens/month output | $10.00 | ~$0 |
| 10M tokens/month total | ~$80–100 | Flat VPS cost |
| 100M tokens/month | ~$800–1,000 | Possibly larger VPS |
| Data sent to third party | Yes (OpenAI US servers) | No (stays on your VPS) |
| China accessibility | Blocked (OpenAI API) | Yes (CN2 GIA) |
| Model quality (7–8B vs GPT-4o) | Superior | Capable for many tasks |
The OpenAI API is blocked in mainland China — applications targeting Chinese users cannot call OpenAI directly. A self-hosted Ollama endpoint on a Hong Kong VPS with CN2 GIA routing solves this: Chinese user requests reach your application, your application calls the local Ollama API, and the LLM response returns in milliseconds without any blocked external API dependency.
Conclusion
Ollama on a Hong Kong VPS brings self-hosted AI inference to Asia-Pacific applications — eliminating per-token API costs at meaningful volume, keeping sensitive data off third-party servers, and providing an LLM endpoint accessible from mainland China that OpenAI’s API cannot be. Qwen2.5 7B is particularly well-suited for Chinese-language tasks, running at 8–15 tokens/second on an 8-core VPS — fast enough for chat interfaces, document summarisation, classification, and embedding generation in production applications.
Deploy your AI endpoint: Browse Server.HK Hong Kong VPS plans — a 16 GB plan with 8 vCPU handles Llama 3.1 8B or Qwen2.5 7B at production throughput alongside your application stack.