iTranslated by AI
Getting Started with OpenClaw: Building an Automated Tweet Bot using Raspberry Pi and Gemini
Introduction — Experimental Records on Raspberry Pi as a Sandbox Environment
Introduction
"I want to make an AI fetch the latest baseball news and tweet it automatically."
With that in mind, I built a baseball news auto-tweet bot using Raspberry Pi 5 + OpenClaw + Gemini API (free tier). The running cost is 0 yen (excluding electricity).
If you look at articles about building AI bots out there, the composition is usually something like this:
- ChatGPT API → Pay-as-you-go (starts at $5/month even if cheap)
- Claude API → Pay-as-you-go
- AWS Lambda + DynamoDB → Charged if you exceed the free tier
- Heroku / Railway → Free plans are discontinued or strictly limited
For those of you thinking, "No, I want to try this more casually...", I will introduce a completely free configuration. If you have a Raspberry Pi lying around at home, you can start today.
The Final Product
Tweets like this are posted fully automatically 13 times a day:
WBC 2026 starts on March 5th! It's almost here, I can't wait! That excitement is like the silence before the Earth's core boils. ⚾
The persona is a "slightly quirky middle-aged man who loves baseball." The quality is what it is, but it works nonetheless.
Architecture and Costs
[cron schedule] → [OpenClaw Gateway] → [Gemini 2.5 Flash API]
↓
get latest info via web_search
↓
tweet drafting (max 140 chars)
↓
[tweet.js] → Twitter API
| Item | Cost | Notes |
|---|---|---|
| Raspberry Pi 5 | Initial cost only | 4GB model is fine (8GB unnecessary) |
| Gemini 2.5 Flash | Free | 15 RPM / 1500 RPD free tier |
| X (Twitter) API | Free | Free Tier: 500 posts/month |
| OpenClaw | Free | Open-source AI agent framework |
| Electricity | ~300 JPY/month | Max power consumption of Pi 5 is 27W |
Monthly running cost: ~300 JPY (electricity only)
Why Raspberry Pi?
"Isn't a VPS better?" you might think, but there are reasons I chose the Raspberry Pi:
- Perfect as a sandbox environment — Since the AI is allowed to execute shell commands, I want it completely isolated from my main PC. If it breaks, I can just re-flash the SD card.
- Assumption of constant operation — VPS free tiers often have time limits or stop unexpectedly. The Raspberry Pi just stays powered on.
- Low learning curve — Just SSH in and run commands. No Kubernetes, Docker, or AWS required.
- One-time initial cost — No monthly billing, so you don't have to worry if you leave it running.
Tech Stack
What is OpenClaw?
OpenClaw is an open-source AI agent framework. Simply put:
- A gateway for LLMs (Gemini, Claude, Ollama, etc.)
- Can schedule execution with cron jobs
- Can run shell commands with the
exectool (the AI can run scripts itself) - Can search for the latest info with
web_search(may require a Brave Search API key) - Can integrate with Discord, Slack, Telegram, etc.
This time, I am using the flow: cron → Gemini → web_search → exec (tweet.js).
Gemini 2.5 Flash Free Tier
You can use Gemini 2.5 Flash for free with an API key generated in Google AI Studio.
- 15 RPM (15 requests per minute)
- 1500 RPD (1500 requests per day)
This is more than enough for 13 cron jobs a day. I leave at least an hour between jobs.
Twitter API Free Tier
There is a cap of 500 posts per month, but 13 tweets/day × 30 days = 390 posts, so that is plenty. It is write-only (cannot read timelines), but that is enough for a bot.
Setup Steps (Overview)
Detailed steps are summarized in the repository's README, but I will introduce the flow here.
1. Install OpenClaw on Raspberry Pi
curl -fsSL https://openclaw.ai/install.sh | bash
openclaw onboard # Enter your Gemini API key
2. Place the tweet posting script
tweet.js is a simple Node.js script of about 30 lines.
// Simplified version
const { TwitterApi } = require("twitter-api-v2");
const client = new TwitterApi({ /* OAuth 1.0a keys */ });
const text = process.argv.slice(2).join(" ");
await client.v2.tweet(text);
3. Define the bot's persona (SOUL.md)
In OpenClaw, you define the agent's character in SOUL.md within the workspace.
# Baseball Old-timer
## Tweet Style
- Rough, like someone tweeting from an izakaya
- Under 140 characters
- [Absolute Rule] Always include one grand and original analogy
4. Register the cron job
openclaw cron add \
--cron "0 9 * * *" \
--tz "Asia/Tokyo" \
--name "WBC 09:00" \
--system-event "Look up the latest WBC information and tweet it in under 140 characters."
With this, Gemini starts up at 9:00 AM every day to handle web searching, tweet drafting, and posting—all automatically.
5. Persistence with systemd
systemctl --user enable openclaw-gateway
systemctl --user start openclaw-gateway
The Story of My Hellish Experience with Ollama (Bonus)
Actually, at first, I aimed for a completely offline setup using Ollama (a local LLM).
To cut to the chase, it did not work properly on Raspberry Pi 5 + llama3.2:3b.
A series of pitfalls
- OpenClaw hardcodes contextWindow to 128K — Ran out of memory and died immediately. Changed it to 8K with a dist patch.
- CONTEXT_WINDOW_HARD_MIN is 16K — Contradicted the 8K context, causing an error. Also patched.
-
Tools schema alone is 17K characters — Disabled most tools with
tools.deny. - OLLAMA_LOAD_TIMEOUT=0 means "default 5 minutes" instead of "unlimited" — A major trap.
- stream:true causes the GIN server to timeout after 5 minutes of silence — Patched to stream:false.
- prompt eval is at 4.1 tokens/sec — 15 minutes to process a 3800-token prompt. HTTP 500 after 5 minutes.
- Only 200MB of swap — Expanded to 2GB.
Even after solving all these, the tool calling accuracy of llama3.2:3b was disastrous:
- It passed the string
"{}"to theexecenvargument (validation error because it was not an object). - It output tools as text instead of performing a function call.
- I asked for information about the Hanshin Tigers, and it replied in English, "Let's go Orix!" (it got the team name wrong).
After two days of fighting, I switched to Gemini and the tweet was posted in 18 seconds. Sometimes, there are moments when you just have to give up on your rigid preferences.
For details, refer to OLLAMA_TROUBLESHOOTING.md.
Security Considerations
Since I allow the AI to execute shell commands, I have minimized risks by using the Raspberry Pi as a sandbox environment.
- Dedicated machine — No information from my main PC is stored here.
- UFW firewall — Deny all incoming traffic except for SSH.
- Gateway limited to localhost — Cannot be accessed from the outside.
-
tools.deny settings — Limited the tools available to the AI to only
execandweb_search. - Permissions for .env set to 600 — API keys are managed strictly.
Even if the AI happens to go rogue, the damage is contained within the Raspberry Pi. Worst case, I can just re-flash the SD card.
Summary
| Action | Result |
|---|---|
| Aiming for completely free using Ollama (local LLM) | Fought for 2 days and failed |
| Switched to Gemini API (free tier) | Succeeded in 18 seconds |
| Running cost | ~300 JPY/month (electricity only) |
| Setup time (Gemini config) | Approx. 1 hour |
When you think, "I want to automate something with AI," I recommend experimenting on a Raspberry Pi before jumping into paid cloud services. It doesn't hurt if it breaks, and if it works, you can use it as your production environment as is.
The source code is available on GitHub.
Discussion