> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qwedai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Self-hosting

> Run QWED on your own infrastructure using Docker Compose. Quick start guide with services overview including API, PostgreSQL, Redis, and Grafana monitoring.

## Quick start

```bash theme={null}
# Clone the repository
git clone https://github.com/QWED-AI/qwed-verification.git
cd qwed-verification

# Start with Docker Compose
docker-compose up -d

# Check status
docker-compose ps
```

## Services

| Service    | Port  | Purpose               |
| ---------- | ----- | --------------------- |
| QWED API   | 8000  | Main API              |
| PostgreSQL | 5432  | Database              |
| Redis      | 6379  | Cache & rate limiting |
| Grafana    | 3000  | Dashboards            |
| Prometheus | 9090  | Metrics               |
| Jaeger     | 16686 | Tracing               |

## Configuration

### Environment variables

```bash theme={null}
# .env file

# Required — server will not start without these
API_KEY_SECRET=your-generated-secret
QWED_CORS_ORIGINS=https://app.yourcompany.com

# Infrastructure
DATABASE_URL=postgresql://user:pass@localhost:5432/qwed
REDIS_URL=redis://localhost:6379

# LLM provider
ACTIVE_PROVIDER=openai
OPENAI_API_KEY=sk-...

# Required — server will not start without these
API_KEY_SECRET=your-generated-secret  # python -c "import secrets; print(secrets.token_urlsafe(48))"
QWED_CORS_ORIGINS=https://app.yourcompany.com
```

<Warning>
  `API_KEY_SECRET` and `QWED_CORS_ORIGINS` are mandatory as of v5.0.0. See the [deployment guide](/advanced/deployment#environment-variables-reference) for the full reference.
</Warning>

### API configuration

```python theme={null}
# config.py
SETTINGS = {
    "rate_limit_enabled": True,
    "rate_limit_per_minute": 60,
    "cache_ttl_seconds": 3600,
    "max_query_length": 10000,
    "allowed_engines": ["math", "logic", "code", "sql"],
}
```

## Docker

### API only

```dockerfile theme={null}
FROM python:3.13-slim-bookworm
WORKDIR /app
COPY . .
RUN pip install -e .
EXPOSE 8000
CMD ["uvicorn", "qwed_new.api.main:app", "--host", "0.0.0.0"]
```

### Build and run

```bash theme={null}
docker build -t qwed-api .
docker run -p 8000:8000 \
  -e QWED_API_KEY=... \
  -e API_KEY_SECRET=... \
  -e QWED_CORS_ORIGINS="https://app.yourcompany.com" \
  qwed-api
```

## Kubernetes

```yaml theme={null}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: qwed-api
spec:
  replicas: 3
  selector:
    matchLabels:
      app: qwed-api
  template:
    metadata:
      labels:
        app: qwed-api
    spec:
      containers:
      - name: qwed
        image: qwed/qwed-api:latest
        ports:
        - containerPort: 8000
        env:
        - name: QWED_API_KEY
          valueFrom:
            secretKeyRef:
              name: qwed-secrets
              key: api-key
```

> 🏢 **Enterprise Support Coming Soon:** Managed hosting, dedicated support, and SLA guarantees. Contact [support@qwedai.com](mailto:support@qwedai.com)

## Scaling

### Horizontal scaling

* Stateless API servers behind load balancer
* Redis for distributed rate limiting
* PostgreSQL with read replicas

### Performance tuning

```bash theme={null}
# Increase workers
uvicorn qwed_new.api.main:app --workers 4

# Enable connection pooling
export QWED_DB_POOL_SIZE=20
```

## Monitoring

### Health check

```bash theme={null}
curl http://localhost:8000/health
```

### Prometheus metrics

```text theme={null}
qwed_verification_total{engine="math", status="verified"}
qwed_verification_latency_seconds
qwed_cache_hit_rate
```

## Security

1. **Always use HTTPS** in production
2. **Set `API_KEY_SECRET`** — mandatory, no default value
3. **Set `QWED_CORS_ORIGINS`** — mandatory, explicitly list allowed origins
4. **Set strong API keys**
5. **Enable rate limiting**
6. **Use network isolation**
7. **Rotate secrets regularly**
