api-credentials
Securely manages API credentials for multiple providers (Anthropic Claude, Google Gemini, GitHub). Use when skills need to access stored API keys for external service invocations.
Install
npx skills add https://github.com/oaustegard/claude-skills/tree/main/plugins/environment-and-config/skills/api-credentials
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install oaustegard-claude-skills@llmmart
git clone https://github.com/oaustegard/claude-skills.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole oaustegard/claude-skills collection as a plugin from our marketplace. Git is the plain clone.
README
api-credentials - DEPRECATED
DEPRECATED IN FAVOR OF configuring
Securely manages API credentials for multiple providers (Anthropic Claude, Google Gemini, GitHub). Use when skills need to access stored API keys for external service invocations.
Skill manifest
API Credentials Management
🚨 DEPRECATED: This skill is no longer needed for hosted skills environments.
New approach: Skills now read credentials directly from project knowledge files:
ANTHROPIC_API_KEY.txt,GOOGLE_API_KEY.txt,GITHUB_API_KEY.txt(recommended)- Or
API_CREDENTIALS.json(combined file)
See updated skill documentation:
Legacy use only: This skill may still be useful for local development environments or backward compatibility.
⚠️ WARNING: This is a PERSONAL skill - DO NOT share or commit with actual credentials!
This skill provides secure storage and retrieval of API credentials for multiple providers. It serves as a dependency for other skills that need to invoke external APIs programmatically.
Supported Providers
- Anthropic (Claude API)
- Google (Gemini API, Vertex AI, etc.)
- GitHub (GitHub API, Personal Access Tokens)
- Extensible for additional providers
Purpose
- Centralized credential storage for multiple API providers
- Secure retrieval methods for dependent skills
- Clear error messages when credentials are missing
- Support for multiple credential sources (config file, environment variables)
Usage by Other Skills
Skills that need to invoke APIs should reference this skill:
Anthropic Claude API
import sys
sys.path.append('/home/user/claude-skills/api-credentials/scripts')
from credentials import get_anthropic_api_key
try:
api_key = get_anthropic_api_key()
# Use api_key for Claude API calls
except ValueError as e:
print(f"Error: {e}")
Google Gemini API
import sys
sys.path.append('/home/user/claude-skills/api-credentials/scripts')
from credentials import get_google_api_key
try:
api_key = get_google_api_key()
# Use api_key for Gemini API calls
except ValueError as e:
print(f"Error: {e}")
GitHub API
import sys
sys.path.append('/home/user/claude-skills/api-credentials/scripts')
from credentials import get_github_api_key
try:
api_key = get_github_api_key()
# Use api_key for GitHub API calls
except ValueError as e:
print(f"Error: {e}")
Setup Instructions
Option 1: Configuration File (Recommended)
- Copy the example config:
cp /home/user/claude-skills/api-credentials/assets/config.json.example \
/home/user/claude-skills/api-credentials/config.json
- Edit
config.jsonand add your API keys:
{
"anthropic_api_key": "sk-ant-api03-...",
"google_api_key": "AIzaSy...",
"github_api_key": "ghp_..."
}
- Ensure the config file is in
.gitignore(already configured)
Option 2: Environment Variables
Set environment variables for the providers you need:
# Anthropic Claude
export ANTHROPIC_API_KEY="sk-ant-api03-..."
# Google Gemini
export GOOGLE_API_KEY="AIzaSy..."
# GitHub
export GITHUB_TOKEN="ghp_..."
# or
export GITHUB_API_KEY="ghp_..."
Add to your shell profile (~/.bashrc, ~/.zshrc) to persist.
Priority
Credential retrieval follows this priority for each provider:
config.jsonin the skill directory (highest priority)- Environment variable (ANTHROPIC_API_KEY or GOOGLE_API_KEY)
- ValueError raised if neither is available
Security Notes
- Never commit config.json with real credentials
- The config.json file should be in .gitignore
- Only config.json.example should be version controlled
- Consider using environment variables in shared/production environments
- Rotate API keys regularly
- Skills should never log or display full API keys
File Structure
api-credentials/
├── SKILL.md # This file
├── config.json # YOUR credentials (gitignored)
├── scripts/
│ └── credentials.py # Credential retrieval module
└── assets/
└── config.json.example # Template for users
Error Handling
When credentials are not found, the module raises ValueError with clear guidance:
- Where to place config.json
- How to set environment variables
- Links to provider consoles for key generation
Skills should catch ValueError exceptions and handle appropriately.
Available Functions
get_anthropic_api_key() → str
- Returns Anthropic API key
- Raises ValueError if not configured
get_google_api_key() → str
- Returns Google API key
- Raises ValueError if not configured
get_github_api_key() → str
- Returns GitHub API token (Personal Access Token)
- Raises ValueError if not configured
get_api_key_masked(api_key) → str
- Returns masked version for safe logging
- Example: "sk-ant-...xyz"
verify_credential(provider) → bool
- Checks if provider is configured
- Returns True/False without raising exceptions
- Providers: 'anthropic', 'google', 'github'
Adding New Providers
To support additional providers:
- Add field to
assets/config.json.example - Add getter function to
scripts/credentials.py:def get_provider_api_key() -> str: # Follow existing pattern with config file + env var pass - Add to
verify_credential()mapping - Update this documentation
Token Efficiency
This skill uses ~300 tokens when loaded but saves repeated credential management code across multiple skills that invoke external APIs. It provides a single, consistent pattern for all credential handling.
Files (claude-skills)
-
assets
-
config.json.example 567 B · in bundle
-
-
scripts
-
credentials.py 7.6 KB
#!/usr/bin/env python3 """ API Credentials Management Module Provides secure retrieval of API keys for multiple providers (Anthropic, Google) from config files or environment variables. """ import json import os from pathlib import Path def get_anthropic_api_key() -> str: """ Retrieves the Anthropic API key from available sources. Priority order: 1. config.json in the api-credentials skill directory 2. ANTHROPIC_API_KEY environment variable Returns: str: The Anthropic API key Raises: ValueError: If no API key is found in any source """ # Determine the skill directory (parent of scripts/) skill_dir = Path(__file__).parent.parent config_path = skill_dir / "config.json" # Try config.json first if config_path.exists(): try: with open(config_path, 'r') as f: config = json.load(f) api_key = config.get('anthropic_api_key', '').strip() if api_key: return api_key except (OSError, json.JSONDecodeError) as e: # If config exists but is malformed, we should know about it raise ValueError( f"Error reading config.json: {e}\n" f"Please check the file at: {config_path}" ) # Try environment variable api_key = os.environ.get('ANTHROPIC_API_KEY', '').strip() if api_key: return api_key # No key found - provide helpful error message raise ValueError( "No Anthropic API key found!\n\n" "Please configure your API key using one of these methods:\n\n" "Option 1: Create config.json\n" f" 1. Copy: cp {skill_dir}/assets/config.json.example {skill_dir}/config.json\n" f" 2. Edit {skill_dir}/config.json and add your API key\n\n" "Option 2: Set environment variable\n" " export ANTHROPIC_API_KEY='sk-ant-api03-...'\n\n" "Get your API key from: https://console.anthropic.com/settings/keys" ) def get_google_api_key() -> str: """ Retrieves the Google API key for Gemini and other Google services. Priority order: 1. config.json in the api-credentials skill directory 2. GOOGLE_API_KEY environment variable Returns: str: The Google API key Raises: ValueError: If no API key is found in any source """ # Determine the skill directory (parent of scripts/) skill_dir = Path(__file__).parent.parent config_path = skill_dir / "config.json" # Try config.json first if config_path.exists(): try: with open(config_path, 'r') as f: config = json.load(f) api_key = config.get('google_api_key', '').strip() if api_key: return api_key except (OSError, json.JSONDecodeError) as e: # If config exists but is malformed, we should know about it raise ValueError( f"Error reading config.json: {e}\n" f"Please check the file at: {config_path}" ) # Try environment variable api_key = os.environ.get('GOOGLE_API_KEY', '').strip() if api_key: return api_key # No key found - provide helpful error message raise ValueError( "No Google API key found!\n\n" "Please configure your API key using one of these methods:\n\n" "Option 1: Create config.json\n" f" 1. Copy: cp {skill_dir}/assets/config.json.example {skill_dir}/config.json\n" f" 2. Edit {skill_dir}/config.json and add your API key\n\n" "Option 2: Set environment variable\n" " export GOOGLE_API_KEY='AIzaSy...'\n\n" "Get your API key from: https://console.cloud.google.com/apis/credentials" ) def get_api_key_masked(api_key: str) -> str: """ Returns a masked version of an API key for logging/display purposes. Args: api_key: The API key to mask Returns: str: Masked API key (e.g., "sk-ant-...xyz" or "AIzaSy...xyz") """ if len(api_key) > 16: return f"{api_key[:10]}...{api_key[-4:]}" return "***" def get_github_api_key() -> str: """ Retrieves the GitHub API token (Personal Access Token). Priority order: 1. config.json in the api-credentials skill directory 2. GITHUB_TOKEN environment variable 3. GITHUB_API_KEY environment variable Returns: str: The GitHub API token Raises: ValueError: If no API key is found in any source """ # Determine the skill directory (parent of scripts/) skill_dir = Path(__file__).parent.parent config_path = skill_dir / "config.json" # Try config.json first if config_path.exists(): try: with open(config_path, 'r') as f: config = json.load(f) api_key = config.get('github_api_key', '').strip() if api_key: return api_key except (OSError, json.JSONDecodeError) as e: # If config exists but is malformed, we should know about it raise ValueError( f"Error reading config.json: {e}\n" f"Please check the file at: {config_path}" ) # Try environment variables (GitHub Actions uses GITHUB_TOKEN) api_key = os.environ.get('GITHUB_TOKEN', '').strip() if api_key: return api_key api_key = os.environ.get('GITHUB_API_KEY', '').strip() if api_key: return api_key # No key found - provide helpful error message raise ValueError( "No GitHub API token found!\n\n" "Please configure your API token using one of these methods:\n\n" "Option 1: Create config.json\n" f" 1. Copy: cp {skill_dir}/assets/config.json.example {skill_dir}/config.json\n" f" 2. Edit {skill_dir}/config.json and add your GitHub token\n\n" "Option 2: Set environment variable\n" " export GITHUB_TOKEN='ghp_...'\n\n" "Get your token from: https://github.com/settings/tokens\n" "Required scopes: repo (for private repos) or public_repo (for public repos only)" ) def verify_credential(provider: str) -> bool: """ Verify that a credential is configured for a provider. Args: provider: Provider name ('google', 'anthropic', or 'github') Returns: True if credential exists and is non-empty, False otherwise """ credential_map = { 'google': get_google_api_key, 'anthropic': get_anthropic_api_key, 'github': get_github_api_key, } getter = credential_map.get(provider.lower()) if not getter: return False try: key = getter() return bool(key) except ValueError: return False if __name__ == "__main__": # Self-test for all providers print("API Credentials Self-Test") print("=" * 50) providers = { 'anthropic': get_anthropic_api_key, 'google': get_google_api_key, 'github': get_github_api_key } for provider_name, getter_func in providers.items(): try: key = getter_func() masked = get_api_key_masked(key) print(f"✓ {provider_name.capitalize()} API key found: {masked}") print(f" Key length: {len(key)} characters") except ValueError: print(f"✗ {provider_name.capitalize()} API key not configured") # Don't print full error in summary print() print("=" * 50) print("Configuration status:") for provider in ['anthropic', 'google', 'github']: configured = verify_credential(provider) status = "✓ Configured" if configured else "✗ Not configured" print(f" {provider.capitalize()}: {status}")
-
-
.gitignore 136 B · in bundle
-
README.md 255 B
# api-credentials - DEPRECATED ### DEPRECATED IN FAVOR OF `configuring` Securely manages API credentials for multiple providers (Anthropic Claude, Google Gemini, GitHub). Use when skills need to access stored API keys for external service invocations. -
SKILL.md 5.7 KB
--- name: api-credentials description: Securely manages API credentials for multiple providers (Anthropic Claude, Google Gemini, GitHub). Use when skills need to access stored API keys for external service invocations. metadata: version: 0.0.3 --- # API Credentials Management **🚨 DEPRECATED: This skill is no longer needed for hosted skills environments.** **New approach:** Skills now read credentials directly from project knowledge files: - `ANTHROPIC_API_KEY.txt`, `GOOGLE_API_KEY.txt`, `GITHUB_API_KEY.txt` (recommended) - Or `API_CREDENTIALS.json` (combined file) See updated skill documentation: - [orchestrating-agents](../orchestrating-agents/SKILL.md#setup) - [invoking-gemini](../invoking-gemini/SKILL.md#setup) - [invoking-github](../invoking-github/SKILL.md#quick-start) **Legacy use only:** This skill may still be useful for local development environments or backward compatibility. --- **⚠️ WARNING: This is a PERSONAL skill - DO NOT share or commit with actual credentials!** This skill provides secure storage and retrieval of API credentials for multiple providers. It serves as a dependency for other skills that need to invoke external APIs programmatically. ## Supported Providers - **Anthropic** (Claude API) - **Google** (Gemini API, Vertex AI, etc.) - **GitHub** (GitHub API, Personal Access Tokens) - Extensible for additional providers ## Purpose - Centralized credential storage for multiple API providers - Secure retrieval methods for dependent skills - Clear error messages when credentials are missing - Support for multiple credential sources (config file, environment variables) ## Usage by Other Skills Skills that need to invoke APIs should reference this skill: ### Anthropic Claude API ```python import sys sys.path.append('/home/user/claude-skills/api-credentials/scripts') from credentials import get_anthropic_api_key try: api_key = get_anthropic_api_key() # Use api_key for Claude API calls except ValueError as e: print(f"Error: {e}") ``` ### Google Gemini API ```python import sys sys.path.append('/home/user/claude-skills/api-credentials/scripts') from credentials import get_google_api_key try: api_key = get_google_api_key() # Use api_key for Gemini API calls except ValueError as e: print(f"Error: {e}") ``` ### GitHub API ```python import sys sys.path.append('/home/user/claude-skills/api-credentials/scripts') from credentials import get_github_api_key try: api_key = get_github_api_key() # Use api_key for GitHub API calls except ValueError as e: print(f"Error: {e}") ``` ## Setup Instructions ### Option 1: Configuration File (Recommended) 1. Copy the example config: ```bash cp /home/user/claude-skills/api-credentials/assets/config.json.example \ /home/user/claude-skills/api-credentials/config.json ``` 2. Edit `config.json` and add your API keys: ```json { "anthropic_api_key": "sk-ant-api03-...", "google_api_key": "AIzaSy...", "github_api_key": "ghp_..." } ``` 3. Ensure the config file is in `.gitignore` (already configured) ### Option 2: Environment Variables Set environment variables for the providers you need: ```bash # Anthropic Claude export ANTHROPIC_API_KEY="sk-ant-api03-..." # Google Gemini export GOOGLE_API_KEY="AIzaSy..." # GitHub export GITHUB_TOKEN="ghp_..." # or export GITHUB_API_KEY="ghp_..." ``` Add to your shell profile (~/.bashrc, ~/.zshrc) to persist. ## Priority Credential retrieval follows this priority for each provider: 1. `config.json` in the skill directory (highest priority) 2. Environment variable (ANTHROPIC_API_KEY or GOOGLE_API_KEY) 3. ValueError raised if neither is available ## Security Notes - **Never commit config.json with real credentials** - The config.json file should be in .gitignore - Only config.json.example should be version controlled - Consider using environment variables in shared/production environments - Rotate API keys regularly - Skills should never log or display full API keys ## File Structure ``` api-credentials/ ├── SKILL.md # This file ├── config.json # YOUR credentials (gitignored) ├── scripts/ │ └── credentials.py # Credential retrieval module └── assets/ └── config.json.example # Template for users ``` ## Error Handling When credentials are not found, the module raises `ValueError` with clear guidance: - Where to place config.json - How to set environment variables - Links to provider consoles for key generation Skills should catch `ValueError` exceptions and handle appropriately. ## Available Functions **get_anthropic_api_key()** → str - Returns Anthropic API key - Raises ValueError if not configured **get_google_api_key()** → str - Returns Google API key - Raises ValueError if not configured **get_github_api_key()** → str - Returns GitHub API token (Personal Access Token) - Raises ValueError if not configured **get_api_key_masked(api_key)** → str - Returns masked version for safe logging - Example: "sk-ant-...xyz" **verify_credential(provider)** → bool - Checks if provider is configured - Returns True/False without raising exceptions - Providers: 'anthropic', 'google', 'github' ## Adding New Providers To support additional providers: 1. Add field to `assets/config.json.example` 2. Add getter function to `scripts/credentials.py`: ```python def get_provider_api_key() -> str: # Follow existing pattern with config file + env var pass ``` 3. Add to `verify_credential()` mapping 4. Update this documentation ## Token Efficiency This skill uses ~300 tokens when loaded but saves repeated credential management code across multiple skills that invoke external APIs. It provides a single, consistent pattern for all credential handling.
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.