#!/usr/bin/env python3
"""Quick script to update the ElevenLabs API key in Claude Desktop config."""
import json
import sys
from pathlib import Path
def get_claude_desktop_config_path():
"""Get the Claude Desktop configuration file path for the current OS."""
if sys.platform == "darwin": # macOS
return Path.home() / "Library/Application Support/Claude/claude_desktop_config.json"
elif sys.platform == "win32": # Windows
return Path.home() / "AppData/Roaming/Claude/claude_desktop_config.json"
else: # Linux
return Path.home() / ".config/Claude/claude_desktop_config.json"
def update_api_key(api_key):
"""Update the API key in the Claude Desktop configuration."""
config_path = get_claude_desktop_config_path()
if not config_path.exists():
print(f"ā Config file not found: {config_path}")
return False
try:
# Read current config
with open(config_path, 'r') as f:
config = json.load(f)
# Update API key
if "mcpServers" in config and "elevenlabs" in config["mcpServers"]:
config["mcpServers"]["elevenlabs"]["env"]["ELEVENLABS_API_KEY"] = api_key
# Write back to file
with open(config_path, 'w') as f:
json.dump(config, f, indent=2)
print(f"ā
API key updated successfully!")
print(f" Config file: {config_path}")
print(f" API key: {api_key[:8]}...{api_key[-4:] if len(api_key) > 12 else api_key}")
print(f"\nš Now restart Claude Desktop to apply changes.")
return True
else:
print(f"ā ElevenLabs server not found in config")
return False
except Exception as e:
print(f"ā Error updating API key: {e}")
return False
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python update_api_key.py <your-api-key>")
print("Example: python update_api_key.py sk-your-actual-api-key-here")
sys.exit(1)
api_key = sys.argv[1]
if api_key in ["your-api-key-here", "your-elevenlabs-api-key-here"]:
print("ā Please provide your actual ElevenLabs API key, not the placeholder!")
sys.exit(1)
success = update_api_key(api_key)
sys.exit(0 if success else 1)