api-credentials

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

API Credentials Management

API凭证管理

🚨 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
  • invoking-gemini
  • invoking-github
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.
🚨 已弃用:托管Skill环境中不再需要此Skill。
新方案: Skill现在可直接从项目知识文件中读取凭证:
  • ANTHROPIC_API_KEY.txt
    GOOGLE_API_KEY.txt
    GITHUB_API_KEY.txt
    (推荐)
  • API_CREDENTIALS.json
    (合并文件)
查看更新后的Skill文档:
  • orchestrating-agents
  • invoking-gemini
  • invoking-github
仅用于旧版场景: 此Skill在本地开发环境或向后兼容场景下可能仍有用处。

⚠️ 警告:这是个人Skill - 请勿分享或提交包含真实凭证的版本!
此Skill为多个提供商提供API凭证的安全存储与检索功能,作为其他需要以编程方式调用外部API的Skill的依赖项。

Supported Providers

支持的提供商

  • Anthropic (Claude API)
  • Google (Gemini API, Vertex AI, etc.)
  • GitHub (GitHub API, Personal Access Tokens)
  • Extensible for additional providers
  • Anthropic(Claude API)
  • Google(Gemini API、Vertex AI等)
  • GitHub(GitHub API、个人访问令牌)
  • 可扩展支持更多提供商

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)
  • 集中存储多个API提供商的凭证
  • 为依赖Skill提供安全的凭证检索方法
  • 当凭证缺失时返回清晰的错误提示
  • 支持多种凭证来源(配置文件、环境变量)

Usage by Other Skills

其他Skill的使用方式

Skills that need to invoke APIs should reference this skill:
需要调用API的Skill应引用此Skill:

Anthropic Claude API

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}")
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()
    # 使用api_key调用Claude API
except ValueError as e:
    print(f"Error: {e}")

Google Gemini API

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}")
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()
    # 使用api_key调用Gemini API
except ValueError as e:
    print(f"Error: {e}")

GitHub API

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}")
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()
    # 使用api_key调用GitHub API
except ValueError as e:
    print(f"Error: {e}")

Setup Instructions

设置说明

Option 1: Configuration File (Recommended)

选项1:配置文件(推荐)

  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
  1. Edit
    config.json
    and add your API keys:
json
{
  "anthropic_api_key": "sk-ant-api03-...",
  "google_api_key": "AIzaSy...",
  "github_api_key": "ghp_..."
}
  1. Ensure the config file is in
    .gitignore
    (already configured)
  1. 复制示例配置:
bash
cp /home/user/claude-skills/api-credentials/assets/config.json.example \
   /home/user/claude-skills/api-credentials/config.json
  1. 编辑
    config.json
    并添加你的API密钥:
json
{
  "anthropic_api_key": "sk-ant-api03-...",
  "google_api_key": "AIzaSy...",
  "github_api_key": "ghp_..."
}
  1. 确保配置文件已加入
    .gitignore
    (已默认配置)

Option 2: Environment Variables

选项2:环境变量

Set environment variables for the providers you need:
bash
undefined
为所需的提供商设置环境变量:
bash
undefined

Anthropic Claude

Anthropic Claude

export ANTHROPIC_API_KEY="sk-ant-api03-..."
export ANTHROPIC_API_KEY="sk-ant-api03-..."

Google Gemini

Google Gemini

export GOOGLE_API_KEY="AIzaSy..."
export GOOGLE_API_KEY="AIzaSy..."

GitHub

GitHub

export GITHUB_TOKEN="ghp_..."
export GITHUB_TOKEN="ghp_..."

or

export GITHUB_API_KEY="ghp_..."

Add to your shell profile (~/.bashrc, ~/.zshrc) to persist.
export GITHUB_API_KEY="ghp_..."

将上述命令添加到你的Shell配置文件(~/.bashrc、~/.zshrc)中以持久化设置。

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
凭证检索遵循以下优先级(针对每个提供商):
  1. Skill目录下的
    config.json
    (最高优先级)
  2. 环境变量(ANTHROPIC_API_KEY或GOOGLE_API_KEY等)
  3. 若两者均不存在,则抛出ValueError

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
  • 绝对不要提交包含真实凭证的config.json
  • config.json文件应加入.gitignore
  • 仅应将config.json.example纳入版本控制
  • 在共享/生产环境中建议使用环境变量
  • 定期轮换API密钥
  • Skill绝对不应记录或显示完整的API密钥

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
api-credentials/
├── SKILL.md              # 本文档
├── config.json           # 你的凭证(已忽略Git提交)
├── scripts/
│   └── credentials.py    # 凭证检索模块
└── assets/
    └── config.json.example  # 用户模板

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.
当未找到凭证时,模块会抛出
ValueError
并提供明确指引:
  • config.json的放置位置
  • 如何设置环境变量
  • 生成密钥的提供商控制台链接
Skill应捕获
ValueError
异常并进行适当处理。

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'
get_anthropic_api_key() → str
  • 返回Anthropic API密钥
  • 若未配置则抛出ValueError
get_google_api_key() → str
  • 返回Google API密钥
  • 若未配置则抛出ValueError
get_github_api_key() → str
  • 返回GitHub API令牌(个人访问令牌)
  • 若未配置则抛出ValueError
get_api_key_masked(api_key) → str
  • 返回用于安全日志的掩码版本
  • 示例:"sk-ant-...xyz"
verify_credential(provider) → bool
  • 检查提供商是否已配置
  • 返回True/False,不抛出异常
  • 支持的提供商:'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
要支持其他提供商:
  1. assets/config.json.example
    添加字段
  2. scripts/credentials.py
    添加获取函数:
    python
    def get_provider_api_key() -> str:
        # 遵循现有配置文件+环境变量的模式
        pass
  3. verify_credential()
    中添加映射
  4. 更新本文档

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.
加载此Skill约消耗300个令牌,但可在多个调用外部API的Skill中避免重复编写凭证管理代码。它为所有凭证处理提供了单一、一致的模式。