Use this skill when the user wants to add financial risk management, spending controls, or guardrails to AI agents. Kredit provides wallets, rules, kredit scoring, and spend tracking for autonomous agent fleets.
pip install kredit # Python
npm i @kredit/kredit # JavaScript / TypeScript
curl -sSL https://kredit.sh/install | sh # CLI
npm i -g kredit-mcp
claude mcp add kredit -- kredit-mcp serve --api-key=kr_live_...
# CLI login (opens browser, saves key to ~/.kredit/config)
kredit login
Or set env var
export KREDIT_API_KEY=kr_live_...
Or pass directly
kredit = Kredit(api_key="kr_live_...") # Python
const kr = new Kredit({ apiKey: "kr_live_..." }) # TypeScript
balance — current dollars availablebudget — total allocated dollarsmax_per_txn — max dollars per single transaction (0 = unlimited)daily_spend_limit — max dollars per day (0 = unlimited)match — action pattern (openai.*, flight.*, * for all)max_cost_per_txn — max dollars per call (0 = unlimited)daily_spend_limit — max dollars per day on matched actions (0 = unlimited)hourly_rate_limit — max calls per hour on matched actions (0 = unlimited)flight.booking beats flight.* beats *)normal — blocked when limits hithigh — auto-increase wallet by 50% when balance drops below 10% of budgetcritical — never blocked, always allowed (logs warning)Score factors:
max_per_txn → block if exceeded
5. Global wallet: daily_spend_limit → block if exceeded
6. Wallet balance → block if insufficient
7. Rules: match action pattern → most specific wins → check limits
8. Kredit score < 400 → block
9. Anomaly detection (10x average cost → flag)
10. Score-based risk escalation
from kredit import Kreditkredit = Kredit(api_key="kr_live_...")
org = kredit.orgs.create(name="my-team")
orgs = kredit.orgs.list()
agent = kredit.agents.create(
org_name="my-team",
name="research-bot",
priority="high",
wallet={"balance": 5000, "budget": 5000, "max_per_txn": 100, "daily_spend_limit": 1000},
rules=[
{"name": "OpenAI cap", "match": "openai.*", "max_cost_per_txn": 5, "daily_spend_limit": 100, "hourly_rate_limit": 50},
{"name": "Default", "match": "*", "max_cost_per_txn": 50, "daily_spend_limit": 500, "hourly_rate_limit": 200},
],
)agents = kredit.agents.list() # all agents
agents = kredit.agents.list(org_id=org.id) # by org
agent = kredit.agents.get(agent_id=agent.id)
kredit.agents.update(agent_id=agent.id, priority="critical")
kredit.agents.delete(agent_id=agent.id)
kredit.rules.add(
agent_id=agent.id,
name="Flight cap",
match="flight.*",
max_cost_per_txn=800,
daily_spend_limit=3000,
hourly_rate_limit=10,
)rules = kredit.rules.list(agent_id=agent.id)
kredit.rules.update(agent_id=agent.id, rule_id=rules[0].id, max_cost_per_txn=1000)
kredit.rules.remove(agent_id=agent.id, rule_id=rules[0].id)
# Before any paid action
result = kredit.check(
agent_id=agent.id,
action="openai.chat",
estimated_cost=2.50,
type="api_call", # api_call | compute | data | tool | other
metadata={"model": "gpt-4o"},
)if result.status == "allowed":
# Execute the action...
response = call_openai(prompt)
# Report outcome
kredit.report(
transaction_id=result.transaction_id,
outcome="success", # success | failure | partial
actual_cost=2.40,
)
else:
print(f"Blocked: {result.block_reason}")
# e.g. "rule:OpenAI cap:max_cost_per_txn" or "wallet_empty" or "agent_frozen"
score = kredit.score(agent_id=agent.id)
score.score = 742, score.status = "active"
spend = kredit.spend(agent_id=agent.id)
spend.total_spend, spend.daily_spend, spend.weekly_spend, spend.monthly_spend
fleet = kredit.fleet()
fleet.total_agents, fleet.active_agents, fleet.throttled_agents, fleet.frozen_agents
fleet.total_spend, fleet.risk_events_blocked, fleet.avg_credit_score
txns = kredit.transactions.list(agent_id=agent.id, status="blocked", limit=50)
import { Kredit } from "@kredit/kredit";const kredit = new Kredit({ apiKey: "kr_live_..." });
const org = await kredit.orgs.create({ name: "my-team" });
const orgs = await kredit.orgs.list();
const agent = await kredit.agents.create({
orgName: "my-team",
name: "research-bot",
priority: "high",
wallet: { balance: 5000, budget: 5000, max_per_txn: 100, daily_spend_limit: 1000 },
rules: [
{ name: "OpenAI cap", match: "openai.*", max_cost_per_txn: 5, daily_spend_limit: 100, hourly_rate_limit: 50 },
],
});const agents = await kredit.agents.list();
const agentDetail = await kredit.agents.get({ agentId: agent.id });
await kredit.agents.update({ agentId: agent.id, priority: "critical" });
await kredit.agents.delete({ agentId: agent.id });
await kredit.rules.add({
agentId: agent.id,
name: "Flight cap",
match: "flight.*",
max_cost_per_txn: 800,
daily_spend_limit: 3000,
hourly_rate_limit: 10,
});const rules = await kredit.rules.list({ agentId: agent.id });
await kredit.rules.update({ agentId: agent.id, ruleId: rules[0].id, max_cost_per_txn: 1000 });
await kredit.rules.remove({ agentId: agent.id, ruleId: rules[0].id });
const result = await kredit.check({
agentId: agent.id,
action: "openai.chat",
estimatedCost: 2.50,
type: "api_call",
metadata: { model: "gpt-4o" },
});if (result.status === "allowed") {
const response = await callOpenAI(prompt);
await kredit.report({
transactionId: result.transaction_id,
outcome: "success",
actualCost: 2.40,
});
}
const score = await kredit.score({ agentId: agent.id });
const spend = await kredit.spend({ agentId: agent.id });
const fleet = await kredit.fleet();
const txns = await kredit.transactions.list({ agentId: agent.id, status: "blocked" });
# Auth
kredit login
Organizations
kredit orgs create --name=my-team
kredit orgs list
Agents
kredit agents create --org-name=my-team --name=research-bot
kredit agents list
kredit agents list --org-id=ORG_ID
Rules
kredit rules add --agent-id=ID --name="OpenAI cap" --match="openai.*" \
--max-cost-per-txn=5 --daily-spend-limit=100 --hourly-rate-limit=50
kredit rules list --agent-id=ID
kredit rules remove --agent-id=ID --rule-id=RULE_ID
Check & Report
kredit check --agent-id=ID --action=openai.chat --estimated-cost=2.50
kredit report --transaction-id=TXN_ID --outcome=success --actual-cost=2.40
Score & Wallet
kredit score --agent-id=ID
kredit wallet --agent-id=ID
Demo (1-hour simulation with 5 agents)
kredit demo
When installed as an MCP server, Claude can call these tools natively:
| Tool | Description |
|---|---|
kredit_check | Risk evaluation before a paid action |
kredit_report | Report outcome after action completes |
| Tool | Description |
|---|---|
kredit_list_orgs | List all organizations |
kredit_create_org | Create an organization |
kredit_rename_org | Rename an organization |
kredit_delete_org | Delete an organization |
| Tool | Description |
|---|---|
kredit_list_agents | List agents (filter by org) |
kredit_create_agent | Create agent with wallet, priority, rules |
kredit_get_agent | Get agent details |
kredit_update_agent | Update name, priority, wallet |
kredit_delete_agent | Delete an agent |
| Tool | Description |
|---|---|
kredit_list_rules | List rules for an agent |
kredit_add_rule | Add a spending rule (match pattern + limits) |
kredit_update_rule | Update a rule |
kredit_delete_rule | Delete a rule |
| Tool | Description |
|---|---|
kredit_score | Get kredit score and stats |
kredit_wallet | Get wallet balance and limits |
kredit_update_wallet | Update wallet balance, budget, limits |
| Tool | Description |
|---|---|
kredit_fleet | Fleet overview stats |
kredit_transactions | List transactions (audit log) |
kredit_events | Agent state change history |
Base URL: https://api.kredit.sh
Auth: Authorization: Bearer kr_live_...
| Method | Path | Description |
|---|---|---|
| POST | /check | Risk evaluation (agent_id, action, estimated_cost, type, metadata) |
| POST | /report | Report outcome (transaction_id, outcome, actual_cost) |
| Method | Path | Description |
|---|---|---|
| GET | /orgs | List orgs |
| POST | /orgs | Create org |
| PUT | /orgs/:id | Rename org |
| DELETE | /orgs/:id | Delete org |
| Method | Path | Description |
|---|---|---|
| GET | /agents | List agents (filter: org_id, status) |
| POST | /agents | Create agent (name, org_name/org_id, priority, wallet, rules) |
| GET | /agents/:id | Get agent |
| PUT | /agents/:id | Update agent (name, priority, wallet) |
| DELETE | /agents/:id | Delete agent |
| Method | Path | Description |
|---|---|---|
| GET | /agents/:id/rules | List rules |
| POST | /agents/:id/rules | Add rule |
| PUT | /agents/:id/rules/:rule_id | Update rule |
| DELETE | /agents/:id/rules/:rule_id | Delete rule |
| Method | Path | Description |
|---|---|---|
| GET | /agents/:id/score | Get kredit score |
| GET | /agents/:id/spend | Get spend breakdown |
| GET | /wallets/:id | Get wallet |
| PUT | /wallets/:id | Update wallet |
| Method | Path | Description |
|---|---|---|
| GET | /fleet/overview | Fleet stats |
| GET | /transactions | Audit log (filter: org_id, agent_id, status, risk_level) |
| GET | /transactions/summary | Status counts |
| GET | /agents/:id/events | Agent events |
Use Kredit as a pre/post hook on tool calls — no SDK needed:
// .claude/hooks.json
{
"PreToolCall": {
"tools": ["Bash", "WebFetch"],
"command": "kredit check --agent-id=$CLAUDE_SESSION_ID --action=$TOOL_NAME --estimated-cost=1"
},
"PostToolCall": {
"tools": ["Bash", "WebFetch"],
"command": "kredit report --transaction-id=$TXN_ID --outcome=$EXIT_CODE"
}
}