api-credentials
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAPI 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(recommended)GITHUB_API_KEY.txt - Or (combined file)
API_CREDENTIALS.json
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:配置文件(推荐)
- Copy the example config:
bash
cp /home/user/claude-skills/api-credentials/assets/config.json.example \
/home/user/claude-skills/api-credentials/config.json- Edit and add your API keys:
config.json
json
{
"anthropic_api_key": "sk-ant-api03-...",
"google_api_key": "AIzaSy...",
"github_api_key": "ghp_..."
}- Ensure the config file is in (already configured)
.gitignore
- 复制示例配置:
bash
cp /home/user/claude-skills/api-credentials/assets/config.json.example \
/home/user/claude-skills/api-credentials/config.json- 编辑并添加你的API密钥:
config.json
json
{
"anthropic_api_key": "sk-ant-api03-...",
"google_api_key": "AIzaSy...",
"github_api_key": "ghp_..."
}- 确保配置文件已加入(已默认配置)
.gitignore
Option 2: Environment Variables
选项2:环境变量
Set environment variables for the providers you need:
bash
undefined为所需的提供商设置环境变量:
bash
undefinedAnthropic 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:
- in the skill directory (highest priority)
config.json - Environment variable (ANTHROPIC_API_KEY or GOOGLE_API_KEY)
- ValueError raised if neither is available
凭证检索遵循以下优先级(针对每个提供商):
- Skill目录下的(最高优先级)
config.json - 环境变量(ANTHROPIC_API_KEY或GOOGLE_API_KEY等)
- 若两者均不存在,则抛出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 usersapi-credentials/
├── SKILL.md # 本文档
├── config.json # 你的凭证(已忽略Git提交)
├── scripts/
│ └── credentials.py # 凭证检索模块
└── assets/
└── config.json.example # 用户模板Error Handling
错误处理
When credentials are not found, the module raises with clear guidance:
ValueError- Where to place config.json
- How to set environment variables
- Links to provider consoles for key generation
Skills should catch exceptions and handle appropriately.
ValueError当未找到凭证时,模块会抛出并提供明确指引:
ValueError- config.json的放置位置
- 如何设置环境变量
- 生成密钥的提供商控制台链接
Skill应捕获异常并进行适当处理。
ValueErrorAvailable 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:
- Add field to
assets/config.json.example - Add getter function to :
scripts/credentials.pypythondef get_provider_api_key() -> str: # Follow existing pattern with config file + env var pass - Add to mapping
verify_credential() - Update this documentation
要支持其他提供商:
- 向添加字段
assets/config.json.example - 向添加获取函数:
scripts/credentials.pypythondef get_provider_api_key() -> str: # 遵循现有配置文件+环境变量的模式 pass - 在中添加映射
verify_credential() - 更新本文档
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中避免重复编写凭证管理代码。它为所有凭证处理提供了单一、一致的模式。