Rotate OpenRouter Key for Openclaw

A specialized utility to securely replace OpenRouter API keys across multiple configuration files and environment variables.

chunhualiao
v1.0.0
Feb 22, 2026
0
1.4k
0

Install & Download

1. ClawHub CLI

The fastest way to install a skill directly from the registry.

npx clawhub@latest install rotate-openrouter-key

2. Manual Installation

Copy the skill folder to one of these locations

Global
~/.openclaw/skills/
Workspace
<project>/skills/

Priority: Workspace > Local > Bundled

3. Prompt Installation

Copy this prompt to OpenClaw to install it automatically.

Help me install rotate-openrouter-key using Clawhub. If Clawhub is not installed, install it first (npm i -g clawhub).

Prefer to download?

Get the raw skill files in a ZIP archive.

What is Rotate OpenRouter Key?

The rotate-openrouter-key skill is a critical maintenance tool for developers using Openclaw Skills. It automates the tedious process of finding and replacing OpenRouter API keys across various configuration files, including environment files and agent-specific JSON models. By identifying the priority chain of configuration sources, this skill ensures that the new key is applied where it actually matters, preventing common 401 authentication errors and streamlining the security rotation process.

This skill is particularly useful for maintaining high availability in production environments. It handles the complexity of the OpenClaw priority chain, which spans from global configurations to per-agent overrides, ensuring that no stale credentials remain in the system to cause intermittent failures.

Rotate OpenRouter Key Use Cases

  • When encountering 401 Unauthorized errors from OpenRouter API calls during agent execution.
  • During periodic security audits requiring regular API key rotation for compliance.
  • When migrating from a compromised or expiring OpenRouter key to a new sk-or-v1- formatted key.
  • Synchronizing API keys across local and remote Openclaw Skills installations via SSH.

How Rotate OpenRouter Key Works

  1. Validates the new OpenRouter key format to ensure it begins with the correct prefix.
  2. Scans the local directory for every JSON and .env file containing the existing OpenRouter key signatures.
  3. Executes a specialized Python helper script to create timestamped backups of all configuration files.
  4. Performs a minimal, non-destructive update of the key value within the identified files.
  5. Verifies the new key's validity against the live OpenRouter API endpoint.
  6. Restarts the OpenClaw gateway service to ensure all changes are loaded into memory.
  7. Coordinates with remote hosts to ensure environment parity across distributed setups.

Rotate OpenRouter Key Setup

To get started with this skill within the Openclaw Skills ecosystem, ensure you have your new key ready from the OpenRouter dashboard. Use the following commands to locate and update your keys:

# Identify all current key locations
grep -r "sk-or-v1" ~/.openclaw/ --include="*.json" --include=".env" -l

# Run the update script with verification
python3 scripts/update-openrouter-key.py --key "sk-or-v1-YOUR-NEW-KEY" --verify

# Restart the gateway to apply changes
openclaw gateway restart

Rotate OpenRouter Key Data Schema & Taxonomy

The skill manages sensitive credentials across a hierarchical priority chain. It specifically targets the identification and modification of the OPENROUTER_API_KEY variable.

Location File Type Priority Level
~/.openclaw/.env Environment File 1 (Highest Override)
~/.openclaw/agents//agent/models.json JSON Config 2 (Per-Agent)
~/.openclaw/openclaw.json JSON Config 3 (Global Default)

All modified files generate a timestamped backup (e.g., config.json.bak) before any write operations occur to prevent data loss.

Rotate OpenRouter Key Advanced Features

  • Priority detection logic that ensures the most specific configuration source is updated first.
  • Dry-run capability to preview all file changes and grep matches before committing to disk.
  • Remote host synchronization support for managing Openclaw Skills across multiple servers via SSH.
  • Live API verification that prevents the application of invalid or inactive keys.
  • Non-destructive parsing that preserves original file comments, indentation, and structure.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*