# Tutorial: CPU-Only with Cloud BYOK Keys

Run LLMHosts without a GPU by using Bring Your Own Key (BYOK) to proxy requests to cloud APIs (OpenAI, Anthropic). Useful for Raspberry Pi, VPS, or any machine without a GPU.

**Time**: ~10 minutes | **Prerequisites**: Python 3.10+, an OpenAI or Anthropic API key

## 1. Install LLMHosts

```bash
pip install llmhosts

# Verify:
llmhosts --version
llmhosts doctor
```

## 2. Add Your Cloud API Keys

```bash
# OpenAI
llmhosts keys add openai sk-your-openai-key

# Anthropic
llmhosts keys add anthropic sk-ant-your-anthropic-key

# Verify:
llmhosts keys list
```

Keys are encrypted at rest using Fernet symmetric encryption in `~/.config/llmhost/keys/`.

## 3. Configure

```bash
cat > ~/.config/llmhost/config.toml << 'EOF'
[server]
host = "0.0.0.0"
port = 4000

[security]
require_auth = true

[cache]
enabled = true
max_size_mb = 512

# No local backends — all requests go to cloud
EOF
```

## 4. Start and Verify

```bash
llmhosts serve

# Test with OpenAI model
curl -X POST http://localhost:4000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

# Test with Anthropic model
curl -X POST http://localhost:4000/v1/messages \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-3-opus",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
```

## 5. Why Use LLMHosts Without a GPU?

Even without local inference, LLMHosts provides:

- **Unified API**: One endpoint for OpenAI + Anthropic + any future provider
- **Semantic cache**: Avoid paying twice for similar queries (saves 20-40% on API costs)
- **Cost tracking**: See exactly what you're spending per model, per request
- **Audit logging**: Full request/response log for compliance
- **Privacy routing**: PII detection before requests leave your network
- **API key management**: Encrypted key storage, rotation, per-key rate limits

## 6. Hybrid Setup (Optional)

Add Ollama for CPU inference alongside cloud keys. Small models like `phi:2.7b` run well on CPU:

```bash
# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh
ollama pull phi:2.7b

# Update config
cat >> ~/.config/llmhost/config.toml << 'EOF'

[ollama]
host = "http://localhost:11434"
EOF

# Restart
llmhosts serve
```

Now LLMHosts routes simple queries to local Phi and complex ones to cloud GPT-4o/Claude.

## 7. Raspberry Pi Notes

LLMHosts runs on Raspberry Pi 4/5 (4GB+ RAM):

```bash
# Install Python 3.10+ (Pi OS may have 3.9)
sudo apt install python3.11 python3.11-venv
python3.11 -m venv ~/llmhost-env
source ~/llmhost-env/bin/activate

pip install llmhosts
llmhosts keys add openai sk-...
llmhosts serve
```

**Performance**: Expect ~50ms overhead per request (proxy + cache lookup). Cloud API latency dominates.

## Troubleshooting

| Issue | Fix |
|-------|-----|
| `Model not found` for cloud models | Add the provider key: `llmhosts keys add openai sk-...` |
| High latency | Expected for cloud APIs (100-2000ms). Cache helps for repeated queries. |
| `403` from OpenAI/Anthropic | Check your API key has credits and isn't expired |
| Cache not helping | Ensure `LLMHOST_CACHE_ENABLED=true`. Cache saves on semantically similar queries. |

## Next Steps

- [Add a GPU later](./single-gpu-ollama.md) — LLMHosts auto-discovers local backends
- [Remote access with Tailscale](./docker-tailscale.md)
- [Production Docker Compose](../deployment/docker-production.md)
