A simple, secure API for storing and retrieving AI conversation contexts using Cloudflare Workers and R2 storage.
CloudContext solves a basic problem: AI assistants forget everything between conversations. This service provides a persistent storage layer for AI contexts, conversation history, and user preferences that survives across sessions.
I built this because I was tired of having to re-explain context to AI assistants every time I started a new conversation. It runs on Cloudflare's infrastructure, so it's fast and has good global coverage.
- Store AI contexts, conversation history, and user data via a REST API
- Data is stored in Cloudflare R2 (S3-compatible object storage)
- Basic authentication with API keys
- Versioning support for tracking context changes
- JavaScript/TypeScript client library included
- REST API for storing/retrieving contexts
- Bearer token authentication
- Context versioning and history
- CORS support for browser usage
- JavaScript client library
- Automated deployment script
- Cloudflare account
- Wrangler CLI installed
- Basic knowledge of Cloudflare Workers
- Clone this repository
- Copy
wrangler.example.tomltowrangler.tomland configure your settings - Run the setup script:
./setup.shOr deploy manually:
npm install -g wrangler
wrangler deployimport CloudContext from './clients/javascript/index.js';
const client = new CloudContext({
baseUrl: 'https://your-worker.your-subdomain.workers.dev',
apiKey: 'your-api-key'
});
// Save some context
await client.save({
conversation: ['Hello', 'Hi there!'],
preferences: { theme: 'dark' }
});
// Retrieve it later
const context = await client.get();
console.log(context.preferences.theme); // 'dark'POST /api/context- Save context dataGET /api/context- Retrieve context dataGET /api/context/list- List all contexts for a userGET /api/context/version- Get context version historyPOST /api/context/restore- Restore a previous versionPOST /api/context/sync- Sync context dataGET /api/health- Health check
This is a working implementation but still evolving. The core functionality is stable, but I'm continuing to add features and improve the API.
Currently implemented:
- ✅ Core storage and retrieval
- ✅ Authentication system
- ✅ Context versioning
- ✅ JavaScript client
- ✅ Automated deployment
- JavaScript/TypeScript: Ready to use (see
clients/javascript/) - Python: Planned
- Go: Planned
Copy wrangler.example.toml to wrangler.toml and update with your settings:
name = "your-cloudcontext-worker"
main = "src/worker.js"
[env.production]
vars = { ENVIRONMENT = "production" }
[[env.production.r2_buckets]]
binding = "CONTEXT_BUCKET"
bucket_name = "your-context-bucket"# Start local development server
wrangler dev
# Run tests
npm test
# Deploy to production
wrangler deployUsing Cloudflare's free tier, this should handle thousands of requests per day at no cost. R2 storage is very affordable - typically under $1/month for most personal use cases.
Pull requests welcome. This is a fairly simple project, so please keep contributions focused and well-tested.
MIT License - see LICENSE file.