Klutch Skill
OpenClaw skill for Klutch programmable credit card API integration.
Overview
This skill provides a command-line interface for accessing Klutch credit card data through their GraphQL API. It supports viewing card information, transaction history, spending categories, and spending analysis.
Prerequisites
- 1. Klutch Account: Active Klutch credit card account
- API Credentials: Client ID and Secret Key from Klutch developer portal
- Python 3.10+: Required for running the scripts
Configuration
Environment Variables
Set your Klutch API credentials:
CODEBLOCK0
Configuration File
The skill stores configuration and session tokens in ~/.config/klutch/:
CODEBLOCK1
Configuration Options
Edit ~/.config/klutch/config.json to customize:
CODEBLOCK2
Commands Reference
Balance
CODEBLOCK3
Transactions
CODEBLOCK4
Card Management
List Cards
CODEBLOCK5
View Categories
CODEBLOCK6
View Spending by Category
CODEBLOCK7
Configuration Management
CODEBLOCK8
API Endpoints
The skill connects to Klutch's GraphQL API:
| Environment | Endpoint |
|---|
| Production | INLINECODE2 |
| Sandbox |
https://sandbox.klutchcard.com/graphql |
Authentication Flow
The skill uses Klutch's session token authentication:
- 1. Initial Request: Sends
createSessionToken mutation with Client ID and Secret Key - Token Caching: Stores the JWT session token in INLINECODE5
- Subsequent Requests: Uses cached token until it expires
- Auto-Refresh: Creates a new session token when the cached one fails
Hypothetical Agent Use Cases
The Klutch skill enables agents to handle their own budget or provide personal finance assistance.
- * Sub-Agent Budgeting: Create a virtual card for a sub-agent to pay for its own usage (AWS, OpenAI) with a hard limit.
- Budget Guardrails: Monitor spending categories (e.g., 'FOOD') and alert the user if they exceed a monthly budget.
- Transaction Alerts: Watch for specific merchants or unusual activity and notify the user immediately.
- Expense Summary: Summarize monthly spending and categorize transactions for personal journaling.
Error Handling
The skill handles common error scenarios:
- - Authentication failures: Prompts to verify credentials
- Session expiration: Automatically creates a new session token
- Network errors: Clear error messages with retry suggestions
- GraphQL errors: Detailed error messages from the API
Integration with OpenClaw
Using from OpenClaw Sessions
CODEBLOCK9
Troubleshooting
Authentication Issues
If you receive authentication errors:
- 1. Verify your credentials with INLINECODE6
- Delete
~/.config/klutch/token.json to force re-authentication - Check that your API credentials are correct
Session Token Issues
Force token refresh:
CODEBLOCK10
Security Notes
- - Never commit credentials to version control
- The skill stores tokens in INLINECODE8
- Session tokens are refreshed automatically when needed
Klutch 技能
用于 Klutch 可编程信用卡 API 集成的 OpenClaw 技能。
概述
本技能提供命令行界面,通过 Klutch 的 GraphQL API 访问信用卡数据。支持查看卡片信息、交易历史、消费类别和消费分析。
前提条件
- 1. Klutch 账户:有效的 Klutch 信用卡账户
- API 凭证:来自 Klutch 开发者门户的客户端 ID 和密钥
- Python 3.10+:运行脚本所需
配置
环境变量
设置您的 Klutch API 凭证:
bash
选项 1:直接凭证
export KLUTCH
CLIENTID=your-client-id
export KLUTCH
SECRETKEY=your-secret-key
选项 2:1Password CLI 集成(需要 op CLI)
export KLUTCH
1PASSWORDITEM=Klutch API Credential
配置文件
技能将配置和会话令牌存储在 ~/.config/klutch/ 目录下:
bash
~/.config/klutch/
├── config.json # 用户偏好设置
└── token.json # 缓存的会话令牌(自动管理)
配置选项
编辑 ~/.config/klutch/config.json 进行自定义:
json
{
api: {
endpoint: https://graphql.klutchcard.com/graphql,
timeout: 30
}
}
命令参考
余额
bash
查看卡片信息
python scripts/klutch.py balance
示例输出:
{
cards: [
{
id: crd_xxx,
name: Martin Kessler,
status: ACTIVE
}
]
}
交易
bash
列出近期交易(最近 30 天)
python scripts/klutch.py transactions
限制结果数量
python scripts/klutch.py transactions --limit 25
示例输出:
{
transactions: [
{
id: txn_xxx,
amount: -100.0,
merchantName: Checking,
transactionStatus: SETTLED
}
]
}
卡片管理
列出卡片
bash
python scripts/klutch.py card list
查看类别
bash
python scripts/klutch.py card categories
按类别查看消费
bash
python scripts/klutch.py card spending
配置管理
bash
获取配置值
python scripts/klutch.py config get api.timeout
设置配置值
python scripts/klutch.py config set api.timeout 60
查看所有配置
python scripts/klutch.py config get
API 端点
技能连接到 Klutch 的 GraphQL API:
| 环境 | 端点 |
|---|
| 生产环境 | https://graphql.klutchcard.com/graphql |
| 沙箱环境 |
https://sandbox.klutchcard.com/graphql |
认证流程
技能使用 Klutch 的会话令牌认证:
- 1. 初始请求:使用客户端 ID 和密钥发送 createSessionToken 变更操作
- 令牌缓存:将 JWT 会话令牌存储在 ~/.config/klutch/token.json
- 后续请求:使用缓存的令牌直至过期
- 自动刷新:当缓存的令牌失效时创建新的会话令牌
假设的代理使用场景
Klutch 技能使代理能够管理自己的预算或提供个人财务协助。
- * 子代理预算管理:为子代理创建虚拟卡,用于支付其自身使用费用(AWS、OpenAI),并设置硬性限额。
- 预算护栏:监控消费类别(例如餐饮),并在超出月度预算时提醒用户。
- 交易提醒:监控特定商户或异常活动,并立即通知用户。
- 费用汇总:汇总月度消费并按类别分类交易,用于个人记账。
错误处理
技能处理常见的错误场景:
- - 认证失败:提示验证凭证
- 会话过期:自动创建新的会话令牌
- 网络错误:清晰的错误信息并附带重试建议
- GraphQL 错误:来自 API 的详细错误信息
与 OpenClaw 集成
在 OpenClaw 会话中使用
bash
OpenClaw 可以直接调用技能
klutch balance
klutch transactions --limit 5
klutch card list
故障排除
认证问题
如果遇到认证错误:
- 1. 使用 python scripts/klutch.py config get 验证您的凭证
- 删除 ~/.config/klutch/token.json 以强制重新认证
- 检查您的 API 凭证是否正确
会话令牌问题
强制刷新令牌:
bash
rm ~/.config/klutch/token.json
安全说明
- - 切勿将凭证提交到版本控制系统
- 技能将令牌存储在 ~/.config/klutch/token.json
- 会话令牌在需要时会自动刷新