Your prototype works on your laptop. Now you need to run it for real users — reliably, securely and cost-effectively. This guide covers the four pillars of production deployment.

1. Containerise

A minimal Dockerfile:

FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
ENV PORT=8080
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]

Multi-stage builds, distroless images, and pinned dependency hashes are recommended for hardened deployments.

2. Handle rate limits gracefully

The SDK retries on 5xx and 429 automatically, but you should still wrap user-facing endpoints in a queue:

from openclaw import RateLimiter

limiter = RateLimiter(requests_per_minute=50)

@limiter.limit
async def handle_request(prompt: str):
    return await agent.run(prompt)

3. Monitor cost and latency

Every Result exposes a .usage dict. Log it.

result = await agent.run(prompt)
log.info("openclaw_call",
         prompt_tokens=result.usage["prompt_tokens"],
         completion_tokens=result.usage["completion_tokens"],
         latency_ms=result.latency_ms,
         cost_usd=result.usage["prompt_tokens"] * 0.000003 +
                  result.usage["completion_tokens"] * 0.000015)

Ship these metrics to Prometheus / Grafana or your APM of choice.

4. Secure your API keys

Never bake secrets into images. Pull them at runtime from your platform's secret store:

  • AWS: Secrets Manager / SSM Parameter Store
  • GCP: Secret Manager
  • Azure: Key Vault
  • Kubernetes: sealed-secrets or External Secrets Operator

5. CI/CD

A reference GitHub Actions workflow:

name: deploy
on: { push: { branches: [main] } }
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: pip install -r requirements.txt
      - run: pytest --cov=app
      - run: openclaw eval run --suite evals/

  deploy:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: aws/configure-aws-credentials@v4
      - run: docker build -t $ECR/openclaw:${{ github.sha }} .
      - run: docker push $ECR/openclaw:${{ github.sha }}
      - run: aws ecs update-service --cluster prod --service openclaw \
              --force-new-deployment
AdvertisementAd slot (in-article / responsive)

Cost optimisation cheat-sheet

  • Use openclaw-1-mini for classification / routing tasks.
  • Cache repeated prompts with the built-in PromptCache.
  • Truncate long contexts — most of the cost is usually the prompt, not the completion.
  • Batch non-urgent jobs during off-peak hours.

🎯 Production-ready checklist

  • ☐ Secrets externalised
  • ☐ Rate limiter in front of every agent call
  • ☐ Token / cost metrics logged
  • ☐ Eval suite passing in CI
  • ☐ Health-check endpoint returning model latency
  • ☐ Graceful shutdown (drain in-flight requests)