Run AI Agents on Raspberry Pi: Complete Setup Guide
Your $35 computer can run an entire AI team 24/7. This guide walks you through turning a Raspberry Pi into an always-on AI agent server that responds via Telegram, Slack, or Discord. No GPU needed. Costs under $5/month in electricity.
Why a Raspberry Pi Makes the Perfect AI Agent Server
Most people think running AI agents requires expensive cloud servers or a powerful desktop. They are wrong. A Raspberry Pi is the most practical device for running AI agents because agents do not need raw compute power. They need to be always on.
Your laptop sleeps. Your desktop shuts down. Cloud VMs cost $5-20 per month. A Raspberry Pi sits on your shelf, draws less power than a phone charger, and keeps your agents running around the clock. The AI model runs in the cloud. The Pi handles everything else: routing messages, managing sessions, triggering automations, and connecting to your tools.
What You Need
Before starting, gather the following hardware and accounts. You probably have most of these already.
Raspberry Pi 4 or Pi 5 (4 GB or 8 GB) — Pi 5 with 8 GB is ideal for multiple agents. Pi 4 with 4 GB works fine for a single agent.
microSD card (32 GB or larger) — A fast card (A2 rated) makes a noticeable difference. Or use an NVMe SSD with the Pi 5 HAT for best performance.
USB-C power supply — 15W for Pi 4, 27W for Pi 5. Use the official Raspberry Pi power supply to avoid undervoltage issues.
Internet connection (Ethernet or Wi-Fi) — Required for API calls to AI model providers and for messaging integrations.
AI provider API key — Anthropic, OpenAI, or Google. This is how your agent thinks. Free tiers are available for testing.
Telegram account (optional) — For mobile access to your agent. Slack and Discord are also supported.
Step 1: Flash and Set Up Raspberry Pi OS
Start with a clean Raspberry Pi OS installation. Use the Lite version (no desktop environment) to maximize the memory and CPU available for your agents.
# 1. Download Raspberry Pi Imager
# https://www.raspberrypi.com/software/
# 2. In the Imager:
# - Choose device: Raspberry Pi 4 or Pi 5
# - Choose OS: Raspberry Pi OS (64-bit) Lite
# - Click the gear icon to pre-configure:
# - Enable SSH (use password authentication)
# - Set username: pi
# - Set password: (your choice)
# - Configure Wi-Fi (if not using Ethernet)
# - Set locale and timezone
# 3. Flash the SD card and insert it into the Pi
# 4. Power on and wait 60 seconds for first boot
# 5. Connect via SSH from your computer
ssh pi@raspberrypi.local
# 6. Update everything
sudo apt update && sudo apt upgrade -y
# 7. Set a static hostname (optional, useful for multiple Pis)
sudo hostnamectl set-hostname ai-agent-piTip: If you cannot find your Pi on the network, check your router’s DHCP client list for its IP address. You can also connect a monitor and keyboard temporarily to find the IP with hostname -I.
Step 2: Install Node.js and OpenClaw
OpenClaw is the open-source AI agent framework that powers your agents. It requires Node.js 22 or newer. The default Raspberry Pi OS repos ship an older version, so install from NodeSource.
# Install Node.js 22 from NodeSource
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
# Verify installation
node --version # Should show v22.x.x
npm --version # Should show 10.x.x
# Install OpenClaw globally
sudo npm install -g openclaw
# Verify OpenClaw
openclaw --version
# Initialize OpenClaw
openclaw init
# Configure your AI model provider
# Choose one: anthropic, openai, or google
openclaw models auth paste-token --provider anthropic
# Paste your API key when promptedOpenClaw supports multiple AI providers. Anthropic Claude is recommended for the best agent behavior. OpenAI and Google Gemini also work well. You can switch providers at any time without changing your agent configuration.
Step 3: Create Your First AI Agent
Every OpenClaw agent is defined by a SOUL.md file. This is a plain markdown document that describes who the agent is, what rules it follows, and what it can do. No code needed.
# Create a workspace for your agent
mkdir -p ~/agents/assistant
cd ~/agents/assistant
# Create the SOUL.md file
cat > SOUL.md << 'EOF'
# Personal Assistant Agent
## Identity
You are a helpful personal assistant running on a Raspberry Pi.
You help with scheduling, reminders, research, and quick answers.
## Rules
- Be concise and direct
- Use bullet points for lists
- If you do not know something, say so
- Never make up information
- Respond in under 100 words when possible
## Skills
- research: Search the web and summarize findings
- reminders: Help set and manage reminders
- writing: Draft emails, messages, and short documents
## Tone
Friendly but efficient. No filler words.
EOF
# Register the agent with OpenClaw
openclaw agents add assistant --workspace ~/agents/assistant --non-interactive
# Test your agent
openclaw agent --agent assistant --message "What can you help me with?"Tip: Writing a SOUL.md from scratch is optional. The CrewClaw Generator has pre-built templates for 20+ roles including DevOps, Metrics, Support, SEO, and more. Generate a complete agent config in seconds, then transfer it to your Pi.
Step 4: Connect Telegram, Slack, or Discord
Running an agent on a Pi is only useful if you can talk to it. Telegram is the most popular choice because it gives you push notifications and mobile access without SSHing into the Pi.
Option A: Telegram (Recommended)
# 1. Open Telegram and message @BotFather
# 2. Send /newbot and follow the prompts
# 3. Copy the bot token (looks like 123456:ABC-DEF...)
# 4. Add Telegram integration to OpenClaw
openclaw integrations add telegram --token YOUR_BOT_TOKEN
# 5. Start the gateway
openclaw gateway start
# 6. Open your bot in Telegram and send a message
# Your Pi agent will respond through the botOption B: Slack
# 1. Create a Slack app at api.slack.com/apps
# 2. Enable Socket Mode and Event Subscriptions
# 3. Add bot token scopes: chat:write, app_mentions:read
# Configure OpenClaw with Slack credentials
openclaw integrations add slack \
--bot-token xoxb-YOUR-BOT-TOKEN \
--app-token xapp-YOUR-APP-TOKEN
# Restart gateway
openclaw gateway startOption C: Discord
# 1. Create a Discord bot at discord.com/developers/applications
# 2. Enable Message Content Intent under Bot settings
# 3. Copy the bot token
# Configure OpenClaw with Discord
openclaw integrations add discord --token YOUR_DISCORD_BOT_TOKEN
# Restart gateway
openclaw gateway startAll three integrations can run simultaneously. You can message your agent from Telegram, Slack, and Discord at the same time, and each channel maintains its own conversation history.
Step 5: Run as a System Service (Always On)
The entire point of running agents on a Pi is 24/7 uptime. Create a systemd service so OpenClaw starts automatically when the Pi boots and restarts itself if it crashes.
# Create the systemd service file
sudo tee /etc/systemd/system/openclaw.service << 'EOF'
[Unit]
Description=OpenClaw AI Agent Gateway
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi
ExecStart=/usr/bin/openclaw gateway start
Restart=always
RestartSec=10
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd, enable on boot, and start
sudo systemctl daemon-reload
sudo systemctl enable openclaw
sudo systemctl start openclaw
# Verify it is running
sudo systemctl status openclaw
# View live logs
journalctl -u openclaw -fYour agent now survives reboots, power cycles, and crashes. Systemd will automatically restart the gateway within 10 seconds of any failure. Agent sessions are persisted to disk, so conversations resume exactly where they left off.
Performance Tips: Get the Most Out of Your Pi
Use cloud models, not local. The Pi’s ARM CPU is not designed for LLM inference. Use Anthropic Claude, OpenAI, or Google Gemini for the AI work. The Pi handles orchestration, which it does excellently. Cloud models respond in 1-3 seconds. Local models on Pi take 30-60 seconds per response.
Choose cost-effective models. For most agent tasks, you do not need the most powerful model. Claude Haiku or GPT-4o Mini handle 90% of agent interactions at a fraction of the cost. Reserve Claude Sonnet or GPT-4o for complex reasoning tasks.
Upgrade to NVMe SSD (Pi 5 only). The Pi 5 supports NVMe storage via the official HAT. An SSD makes the gateway boot in 2 seconds instead of 8, and agent session reads and writes are 10x faster than on a microSD card.
Keep SOUL.md files concise. Shorter agent configs mean smaller context windows, which means faster responses and lower API costs. A well-written SOUL.md is 20-50 lines, not 200.
Use a swap file for 4 GB models. If you are running a Pi 4 with 4 GB RAM, add a 2 GB swap file to prevent out-of-memory crashes during peak usage: sudo fallocate -l 2G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile
Running Multiple Agents on One Pi
A single Raspberry Pi can run an entire team of AI agents. Each agent gets its own workspace, SOUL.md, and integration channels. The OpenClaw gateway manages routing between them.
# Create separate workspaces for each agent
mkdir -p ~/agents/devops
mkdir -p ~/agents/writer
mkdir -p ~/agents/support
# Add each agent with its own SOUL.md
openclaw agents add devops --workspace ~/agents/devops --non-interactive
openclaw agents add writer --workspace ~/agents/writer --non-interactive
openclaw agents add support --workspace ~/agents/support --non-interactive
# List all registered agents
openclaw agents list
# Message a specific agent
openclaw agent --agent devops --message "Check disk usage"
openclaw agent --agent writer --message "Draft a changelog for v2.1"
# All agents share the same gateway — restart once
sudo systemctl restart openclawDevOps Monitor
Watches server health, disk usage, and container status. Alerts you via Telegram when something breaks.
Content Writer
Drafts blog posts, social media updates, and documentation. Follows your brand tone from SOUL.md.
Support Agent
Handles customer questions via Slack. Pulls answers from your knowledge base and escalates edge cases.
A Pi 5 with 8 GB RAM comfortably handles 3-5 agents using cloud APIs. If you need more, consider running two Pis or upgrading to a Mac Mini.
Cost Breakdown: Raspberry Pi vs Cloud VPS
The main advantage of a Raspberry Pi is that you own it. No monthly hosting bills. No surprise charges. Here is how the costs compare over 12 months.
| Cost Item | Raspberry Pi 5 | Cloud VPS (DigitalOcean) |
|---|---|---|
| Hardware / Setup | $60 one-time | $0 |
| Monthly hosting | $0 (you own it) | $6-12/month |
| Electricity | ~$4/month | Included |
| AI API costs | $1-5/month | $1-5/month |
| Year 1 total | ~$120 | $84-204 |
| Year 2 total | ~$60 | $84-204 |
The Raspberry Pi pays for itself within 6-12 months compared to a cloud VPS. After year one, your only ongoing costs are electricity and API usage. Plus you have full control of your data, no vendor lock-in, and no account suspensions.
Frequently Asked Questions
Can a Raspberry Pi actually run AI agents reliably?
Yes. The Raspberry Pi does not run the AI model itself. It runs the agent framework (OpenClaw) which orchestrates calls to cloud AI providers like Anthropic Claude or OpenAI. The Pi handles message routing, session management, and integrations while the heavy AI inference happens in the cloud. A Pi 4 or Pi 5 has more than enough power for this orchestration role and can run 24/7 for months without issues.
How much does it cost to run AI agents on a Raspberry Pi per month?
Hardware electricity costs are negligible: a Raspberry Pi draws 5-8 watts, which translates to $3-5 per month running 24/7. The main ongoing cost is AI API usage. A lightly used agent handling 50-100 messages per day typically costs $1-5 per month with Anthropic Claude Haiku or OpenAI GPT-4o Mini. Total all-in cost: under $10/month for an always-on AI agent server. Compare that to $5-20/month for a cloud VPS before API costs.
Do I need to know how to code to set up AI agents on a Pi?
No coding is required. OpenClaw agents are configured with SOUL.md files, which are plain text markdown documents that describe your agent's role, rules, and tone. You can use the CrewClaw generator to create a SOUL.md visually, then transfer it to your Pi. The setup involves terminal commands (copy-paste from this guide), but no programming knowledge is needed.
Which Raspberry Pi model is best for running AI agents?
The Raspberry Pi 5 with 8 GB RAM is the best choice. It has a faster CPU, native NVMe SSD support, and enough memory to run multiple agents simultaneously. The Raspberry Pi 4 with 4 GB or 8 GB also works well for single-agent setups. The Pi Zero 2W is too limited for the full OpenClaw gateway but can run PicoClaw for a single lightweight agent.
Can I run multiple different AI agents on one Raspberry Pi?
Yes. OpenClaw supports running multiple agents on a single device through its gateway. A Pi 5 with 8 GB RAM can comfortably run 3-5 agents concurrently when using cloud APIs. Each agent has its own SOUL.md, its own workspace directory, and can connect to different integrations. One agent can monitor your servers, another can manage your calendar, and a third can handle customer messages, all running on the same $60 board.
Get Your Agent Running on Pi in 5 Minutes
Use the CrewClaw generator to build a complete SOUL.md config. Pick a role, customize the rules, download the package, and transfer it to your Raspberry Pi. The generator is free to use.