Skip to content

underwoo/opencode-key-updater

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenCode Key Updater

A simple utility to update the USAi API key for OpenCode installations.

Quick Install

curl -fsSL https://raw.githubusercontent.com/underwoo/opencode-key-updater/main/install.sh | bash

Usage

After installation, update your API key with:

install-key <your-new-api-key>

Example

install-key api-key-89bb4500-5704-41b9-97f4-ea8c33b25ff9:B7N8SoTYDKPP9CS8cHCXg4izixL2o6HE

Features

  • Simple: Single command to update your API key
  • Safe: Automatic backups before making changes
  • Smart: Auto-restores on failure
  • Clear: Color-coded output and helpful messages
  • Targeted: Only updates the USAi provider key

What It Does

The install-key command:

  1. Creates a timestamped backup of your OpenCode auth file
  2. Updates only the USAi provider's API key
  3. Preserves all other provider credentials
  4. Shows clear success/failure messages
  5. Provides restore instructions if needed

Requirements

  • macOS or Linux
  • Python 3 (typically pre-installed)
  • OpenCode installed and configured

Manual Installation

If you prefer not to use the curl installer:

# Download the script
curl -fsSL https://raw.githubusercontent.com/underwoo/opencode-key-updater/main/install-key -o ~/.local/bin/install-key

# Make it executable
chmod +x ~/.local/bin/install-key

# Ensure ~/.local/bin is in your PATH
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshenv  # or ~/.bashrc
source ~/.zshenv  # or source ~/.bashrc

Troubleshooting

"command not found: install-key"

Make sure ~/.local/bin is in your PATH:

# For zsh (macOS default):
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshenv
source ~/.zshenv

# For bash:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Or use the full path:

~/.local/bin/install-key <your-api-key>

"OpenCode auth file not found"

Ensure OpenCode is installed and you've run it at least once to create the configuration files.

Restoring a Previous Key

If you need to restore an old key, backups are stored at:

~/.local/share/opencode/auth.json.backup.YYYYMMDD_HHMMSS

Restore with:

cp ~/.local/share/opencode/auth.json.backup.YYYYMMDD_HHMMSS ~/.local/share/opencode/auth.json

Verification

After updating your key, verify the change:

opencode providers list

License

MIT

Contributing

Issues and pull requests welcome at: https://github.com/underwoo/opencode-key-updater

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages