Ashari Abidin's Developer Docs

OpenClaw Multiple API Key Setup

🔴 Setting Multiple API Keys on OpenClaw
Multiple Google Gemini API Keys Setup for OpenClaw on Ubuntu

⚡ automatic fallback · quota resilience · AI workflow reliability

🎯 Why multi‑key configuration? Eliminate single points of failure, avoid quota exhaustion, and distribute workload across Gemini providers. OpenClaw gains self-healing capabilities for OCR, NLP, Selenium automation, and reasoning chains.

🔁 Architecture: google-1 (primary) → google-2 (fallback) → google-3 (emergency)

📌 Unified model: gemini-2.5-flash — stable, cost‑efficient & fast for agent workflows.

1

Prepare Ubuntu Environment

Run system updates and install core tooling:

sudo apt update && sudo apt upgrade -y
sudo apt install -y python3 python3-pip curl git nano jq
python3 --version # Example: Python 3.12.3
2

Create OpenClaw Structure + Virtual Environment

mkdir -p ~/openclaw/{config,scripts,logs,workspace}

Tree layout: ~/openclaw/ ├── config/ ├── logs/ ├── scripts/ └── workspace/

cd ~/openclaw
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
3

Obtain Google Gemini API Keys

Visit Google AI Studio → Create 3 distinct keys:

Key NamePurpose KEY_1Primary workload KEY_2Fallback 1 KEY_3Emergency Backup
💡 Example key format: AIzaSy_PRIMARY , AIzaSy_FALLBACK , AIzaSy_BACKUP (replace with real keys)
4

OpenClaw Configuration (JSON)

Create ~/openclaw/config/openclaw.json with multi-provider fallback chain:

{
 "providers": {
 "google-1": { "type": "google", "apiKey": "AIzaSy_PRIMARY" },
 "google-2": { "type": "google", "apiKey": "AIzaSy_FALLBACK" },
 "google-3": { "type": "google", "apiKey": "AIzaSy_BACKUP" }
 },
 "agents": {
 "defaults": {
 "model": {
 "primary": "google-1/gemini-2.5-flash",
 "fallbacks": [
 "google-2/gemini-2.5-flash",
 "google-3/gemini-2.5-flash"
 ]
 }
 }
 }
}

Save: CTRL+OENTERCTRL+X

5

Fallback Mechanism & Workflow

🔄 Provider order:
1️⃣ google-1 (primary)
2️⃣ google-2 (fallback)
3️⃣ google-3 (emergency)
⛓️ Request flow:
Request → google-1 ✅
↳ Quota/429/timeout → google-2 ✅
↳ Still failed → google-3 ✅
🚨 Automatic rollover protects against rate limits & quota exhaustion — no manual intervention.
6

Add Environment Variables (.bashrc)

nano ~/.bashrc

Append these lines:

export GOOGLE_API_KEY_1="AIzaSy_PRIMARY"
export GOOGLE_API_KEY_2="AIzaSy_FALLBACK"
export GOOGLE_API_KEY_3="AIzaSy_BACKUP"
source ~/.bashrc
echo $GOOGLE_API_KEY_1 # verification
7

Test Script & Validation

Create ~/openclaw/scripts/test_provider.py to inspect config:

import json

config_path = "/home/$USER/openclaw/config/openclaw.json"
with open(config_path, "r") as f:
 config = json.load(f)

providers = config["providers"]
for name, provider in providers.items():
 print(f"Provider: {name}")
 print(f"Type: {provider['type']}")
 print(f"API Key: {provider['apiKey'][:12]}...")
 print("-" * 30)
python3 ~/openclaw/scripts/test_provider.py

Expected output:

Provider: google-1
Type: google
API Key: AIzaSy_PRIM...
...
Provider: google-2
API Key: AIzaSy_FALL...
8

Install AI Libraries & Routing Example

pip install google-generativeai
pip install selenium pillow opencv-python pytesseract pandas requests beautifulsoup4

Simple router example (~/openclaw/scripts/router.py):

import random
providers = ["google-1", "google-2", "google-3"]
selected = random.choice(providers)
print(f"Using provider: {selected}")
python3 ~/openclaw/scripts/router.py
9

Restart Service & Debugging

If OpenClaw runs via systemd user service:

systemctl --user restart openclaw
systemctl --user status openclaw

Debug commands:

cat ~/openclaw/config/openclaw.json
journalctl --user -u openclaw -f
grep -i quota ~/openclaw/logs/*
🛠️ Tip: verify config syntax with jq . ~/openclaw/config/openclaw.json
10

Production Best Practices

ProviderRecommended Role
google-1User chat + interactive tasks
google-2Automation (OCR, scraping, selenium)
google-3Emergency fallback / critical workflows

✅ Always use the same model (gemini-2.5-flash) for consistent behavior across fallbacks.
✅ Isolate heavy workloads (document parsing, reasoning chains) from real-time chat to avoid cross‑quota interference.

Final Verification & Readiness

python3 -c "print('OpenClaw Ready')"
jq . ~/openclaw/config/openclaw.json
python3 ~/openclaw/scripts/test_provider.py
Success criteria: multi-key config loaded, fallback chain active, environment ready for large‑scale AI automation.

✨ With this setup OpenClaw automatically rotates between Gemini keys — your AI workflows become resilient, scalable, and quota‑proof.

⚙️

Provider architecture summary

google-1 → google-2 → google-3 | Same model: gemini-2.5-flash
Automatic fallback triggers on: quota exceeded, HTTP 429, network timeout, or 5xx errors.
Ideal for OCR/NLP pipelines, browser automation, and agentic workflows.

🔴 OpenClaw · Multi Google Gemini API Keys on Ubuntu  |  Redundant AI infrastructure | Fallback-first design
gemini-2.5-flash self-healing zero-downtime
Back