One-Click Serverless Deployment for nanobot AI Assistant
Deploy nanobot to popular serverless platforms with zero local setup required. Access your AI assistant from Telegram anywhere, anytime.
- π― One-Command Deployment - Deploy to Google Cloud Run with a single script
- π° Free Tier Support - Runs entirely on GCP Always-Free tier
- π 24/7 Availability - No need to keep your computer running
- π± Telegram Integration - Full Telegram bot support via webhooks
- πΎ Persistent Storage - All data stored in Google Cloud Storage (chat history, sessions, files)
- β‘ Serverless Optimized - Cold start optimization and automatic scaling
βββββββββββββββββββββββββββββββββββββββββββ
β Google Cloud Run (Serverless) β
β βββββββββββββββββββββββββββββββββββββ β
β β FastAPI HTTP Handler β β
β β - Telegram webhook endpoint β β
β β - Health check endpoint β β
β βββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββ β
β β nanobot Gateway Adapter β β
β β - Initialize from env vars β β
β β - Handle webhook events β β
β β - Sync files to/from GCS β β
β βββββββββββββββββββββββββββββββββββββ β
β β β
βββββββββββββΌβββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β External Services β
β - Google Cloud Storage (persistent) β
β - OpenRouter API (LLM) β
β - Brave Search API (optional) β
βββββββββββββββββββββββββββββββββββββββββββ
Tip
Get API keys: OpenRouter (LLM) Β· Brave Search (optional, for web search)
You can also change the model to minimax/minimax-m2 for lower cost.
Before deploying, you'll need:
- OpenRouter API Key - Get from OpenRouter.ai
- Telegram Bot Token - Create a bot with @BotFather
- Telegram User ID - Get from @userinfobot
- Google Cloud Platform Account - Create at cloud.google.com
1. Clone repository
git clone elliot35/nanobot-serverless-deploy
cd serverlessbot2. Configure environment
# Copy template
cp .env.example .env
# Edit .env file with your credentials
# Required:
# - NANOBOT_OPENROUTER_API_KEY
# - TELEGRAM_BOT_TOKEN
# - TELEGRAM_ALLOWED_USERS
# Optional:
# - GCS_BUCKET_NAME (auto-created if not set)
# - NANOBOT_MODEL (defaults to anthropic/claude-opus-4-5)
# - BRAVE_SEARCH_API_KEY3. Set GCP project
export GCP_PROJECT_ID=your-project-id
# Or set it permanently:
gcloud config set project your-project-id4. Load environment variables
# For bash/zsh:
set -a
source .env
set +a5. Deploy
./gcp/deploy.shThe script will:
- β Enable required GCP APIs
- β Create GCS bucket for persistent storage
- β Build and push Docker image
- β Deploy to Cloud Run
- β Provide service URL and next steps
6. Set Telegram webhook
After deployment, the script will output your service URL. Then:
curl -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/setWebhook?url=https://your-service-url.run.app/api/webhook/telegram"7. Test
Send a message to your bot on Telegram - it should respond!
All data is automatically stored in Google Cloud Storage:
| Data Type | Storage Location | Format |
|---|---|---|
| Chat History | sessions/{session_key}/chat_history.jsonl |
JSONL (one message per line) |
| Sessions | sessions/{session_key}/session.json |
JSON |
| Agent Actions | sessions/{session_key}/agent_actions.jsonl |
JSONL |
| Files | sessions/{session_key}/files/ |
Any file type |
Automatic syncing:
- Files are synced from GCS before processing (agent can access previous files)
- Chat history is loaded automatically (up to 50 previous messages)
- Files are synced to GCS after processing (persists across invocations)
| Variable | Description | Example |
|---|---|---|
NANOBOT_OPENROUTER_API_KEY |
OpenRouter API key for LLM access | sk-or-v1-xxx |
TELEGRAM_BOT_TOKEN |
Telegram bot token from @BotFather | 123456:ABC... |
TELEGRAM_ALLOWED_USERS |
Comma-separated list of allowed user IDs | 123456789,987654321 |
| Variable | Description | Default |
|---|---|---|
GCS_BUCKET_NAME |
GCS bucket name for storage | {PROJECT_ID}-nanobot-files |
GCP_PROJECT_ID |
GCP project ID | Auto-detected from gcloud |
NANOBOT_MODEL |
LLM model identifier | anthropic/claude-opus-4-5 |
BRAVE_SEARCH_API_KEY |
Brave Search API key | - |
LOG_LEVEL |
Logging level (DEBUG, INFO, WARNING, ERROR) | INFO |
See .env.example for a complete example.
curl https://your-service-url.run.app/api/healthExpected response:
{
"status": "healthy",
"checks": {
"bus": true,
"agent_loop": true,
"session_manager": true,
"config": true,
"workspace": true,
"storage_manager": true,
"gcs": true
}
}gcloud run services logs read nanobot-gateway \
--region us-central1 \
--project your-project-id \
--limit 50To remove all deployed resources:
export GCP_PROJECT_ID=your-project-id
./gcp/destroy.shThis will delete:
- β Telegram webhook
- β Cloud Run service
- β Container images
β οΈ GCS bucket (optional, with confirmation)
Note: GCS data (sessions, chat history, files) will be preserved unless you choose to delete the bucket.
- β 2 million requests/month
- β 360,000 GB-seconds compute/month
- β 180,000 vCPU-seconds/month
- β 1 GB egress/month
β οΈ Requires billing account (but stays within free tier for small usage)
- β 5GB storage/month
- β 1GB egress/month
- β Automatic scaling
β οΈ Requires billing account (but stays within free tier for small usage)
Health check returns "unhealthy"
-
Check logs for detailed error messages:
gcloud run services logs read nanobot-gateway --region us-central1 --project your-project-id --limit 50 -
Common issues:
- Missing environment variables (especially
GCS_BUCKET_NAME) - Invalid API keys or tokens
- GCS bucket permissions issues
- Import errors (check that nanobot is installed correctly)
- Missing environment variables (especially
Bot not responding
-
Check webhook is set correctly:
curl "https://api.telegram.org/bot<TOKEN>/getWebhookInfo" -
Verify webhook URL matches your deployment URL exactly
-
Check logs for errors:
gcloud run services logs read nanobot-gateway --region us-central1 -
Verify environment variables are set correctly in Cloud Run
-
Check user ID is in
TELEGRAM_ALLOWED_USERS(comma-separated, no spaces)
GCS storage errors
-
Verify bucket exists:
gsutil ls gs://your-bucket-name
-
Check bucket permissions - Cloud Run service account needs
storage.objectAdminrole:gsutil iam ch serviceAccount:PROJECT_ID@appspot.gserviceaccount.com:roles/storage.objectAdmin gs://your-bucket-name
-
Verify GCS_BUCKET_NAME environment variable is set correctly
-
Check GCS API is enabled:
gcloud services enable storage-api.googleapis.com --project your-project-id
Cold start delays
- First request may take 5-10 seconds (cold start)
- Subsequent requests are faster (warm instances)
- Consider increasing min instances for production:
gcloud run services update nanobot-gateway \ --min-instances 1 \ --region us-central1
serverlessbot/
βββ README.md # This file
βββ .env.example # Environment variables template
βββ gcp/
β βββ main.py # Cloud Run FastAPI app
β βββ requirements.txt # Python dependencies
β βββ Dockerfile # Docker image for Cloud Run
β βββ cloudbuild.yaml # Cloud Build configuration
β βββ deploy.sh # One-command deployment script
β βββ destroy.sh # Cleanup script
βββ src/
β βββ adapter.py # nanobot gateway adapter
β βββ config.py # Environment-based config loader
β βββ storage.py # GCS persistent storage
β βββ handlers.py # HTTP request handlers
βββ scripts/
βββ setup_mongodb.py # (Deprecated - no longer needed)
# Clone repository
git clone <YOUR_REPO_URL>
cd serverlessbot
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r gcp/requirements.txt
# Copy environment template
cp .env.example .env
# Edit .env file with your credentials
# Load environment variables
set -a
source .env
set +a
# Run locally
python -m uvicorn gcp.main:app --host 0.0.0.0 --port 8080
# Test health endpoint
curl http://localhost:8080/api/health- nanobot Documentation
- Google Cloud Run Documentation
- Google Cloud Storage Documentation
- Telegram Bot API
- OpenRouter Documentation
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Built for nanobot by HKUDS
- Inspired by the need for easy serverless deployment
Made with β€οΈ for the nanobot community
Get Started β’ Troubleshooting β’ Cleanup