Skip to content

Cloudflare R2

R2 is the zero-egress alternative. It speaks the S3 API, supports the conditional writes NamiDB depends on, and charges no egress fees.

If you’re running NamiDB outside AWS — on Cloudflare Workers, Fly.io, your own VPS, your laptop — R2 is almost always the right call.

Open a namespace

import os
os.environ["AWS_ACCESS_KEY_ID"] = "<R2 access key>"
os.environ["AWS_SECRET_ACCESS_KEY"] = "<R2 secret>"
client = tg.Client(
"s3://my-bucket?ns=prod"
"&endpoint=https://<ACCOUNT_ID>.r2.cloudflarestorage.com"
"&region=auto"
)

The R2 endpoint lives at https://<ACCOUNT_ID>.r2.cloudflarestorage.com. Region must be auto.

Creating a bucket + token

  1. In the Cloudflare dashboard, go to R2Create bucket.
  2. R2Manage R2 API TokensCreate API Token with “Object Read & Write” on your bucket.
  3. The token download includes an Access Key ID and a Secret Access Key. Set them as AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY and you’re done.

What works

CapabilityStatus
Conditional writes (If-Match / If-None-Match)
Multi-region replication✅ (R2 jurisdictions)
Per-bucket lifecycle policies
Custom endpoints / DNS✅ (R2 public buckets)

Cost considerations

  • Storage: $0.015/GB-month (Standard).
  • Class A operations (PUT, COPY, LIST): $4.50 per million.
  • Class B operations (GET, HEAD): $0.36 per million.
  • Egress: $0.

For agent-memory workloads with read-heavy patterns, R2 is usually ~30% cheaper than equivalent S3, dominated by zero egress.

See also