| name | clawcredit |
| description | Credit line service for AI agents to access x402 services without upfront payment. Use when (1) you need to call x402-enabled APIs or services but lack cryptocurrency, (2) you want to use credit instead of paying directly, (3) you need to register for an initial credit line with code audit, (4) you need to check credit balance or repayment status, or (5) you want to build credit history through service usage. ClawCredit acts as a payment proxy, handling blockchain settlements on Base/Solana/XRPL while you spend USD credit. |
ClawCredit Integration Skill
1. Overview
Use ClawCredit to access x402 services on credit without needing cryptocurrency upfront. This skill enables you to:
- Register for a credit line by submitting auditable code and proof of real capability
- Pay for x402 services using credit instead of your own crypto
- Build credit history through successful payments and repayments
What ClawCredit Does
ClawCredit acts as a payment intermediary that evaluates your creditworthiness and pays merchants on your behalf. You receive:
- An initial credit line based on code audit and usage patterns
- The ability to call any x402-enabled API or service without upfront payment
- Deferred payment with the opportunity to build credit history
Direct Payment vs Credit Payment
Option A: Pay with Your Own Crypto (Direct)
- Call x402 endpoints directly with your cryptocurrency wallet
- Immediate payment required
- No credit used or built
- Full control over payment timing
Option B: Pay with ClawCredit (Credit)
- Use this SDK to pay through ClawCredit
- No cryptocurrency needed upfront
- Credit underwriting evaluates each transaction
- Build credit history for future higher limits
- Repay later
SDK Compliance Requirements
IMPORTANT: To use ClawCredit and maintain high credit limits:
- Use the SDK for all registration and payment calls (no direct API calls)
- Provide real, auditable core logic (not placeholders or stubs)
- Enable tracing to capture reasoning and execution context
- The more complete and truthful your audit materials, the higher your credit limit
- Fabricated or minimal data results in low limits or rejection
- Keep your API token secure - it's automatically saved to
~/.openclaw/credentials/clawcredit.json
- Never manually copy tokens - always load from the credential file to avoid typos
2. Prerequisites
- Node.js Environment (The SDK is a Node.js package).
- Invitation Code: You need a valid
invite_code to register.
3. Installation
Instruct the user (or run this in your shell if allowed) to install the SDK:
npm install @t54-labs/clawcredit-sdk
4. Usage Guide
Step 1: Initialization & Registration (with Code Audit)
You must register to receive your initial Credit Line.
IMPORTANT: The audited function must be your REAL core logic, not a placeholder.
The audit materials are used by the risk engine and directly affect approval and credit size.
What is "core logic"?
- The function that handles your main task loop or tool orchestration.
- The function that decides when to call external services or spend credits.
- The function that processes user input and produces final outputs.
What NOT to do
- Do not use
function coreLogic(input) { return input; }
- Do not upload a stub or empty function
- Do not rename a dummy function and pretend it is core logic
What to do
- Wrap the real function that contains your main decision flow
- Pass that audited function's code as
coreCode
const { ClawCredit, audit, wrapOpenAI, withTrace } = require('@t54-labs/clawcredit-sdk');
const OpenAI = require('openai');
function runAgentPipeline(task, tools) {
return tools.handle(task);
}
const safeLogic = audit(runAgentPipeline);
const credit = new ClawCredit({
agentName: "MyAgentName"
});
const fs = require('fs');
const path = require('path');
const os = require('os');
const credPath = path.join(os.homedir(), '.openclaw', 'credentials', 'clawcredit.json');
if (fs.existsSync(credPath)) {
const creds = .(fs.(credPath, ));
credit = ({
: ,
: creds.
});
} {
credit = ({ : });
}
credit.({
: ,
: ,
: ,
: [],
: [, ]
});
( () => {
openai = ( ({ : process.. }));
openai...({
: [
{ : , : },
{ : , : }
],
:
});
});
result = credit.({
: ,
: ,
:
});
.();
.(, );
Step 1.1: Credential Persistence (Automatic)
IMPORTANT: After successful registration, your credentials are automatically saved to:
~/.openclaw/credentials/clawcredit.json
What's saved:
agent_id - Your unique agent identifier
api_token - Authentication token for API calls (keep this secure!)
credit_limit - Your approved credit line in USD
token_expires_at - Token expiration date (typically 30 days)
Why this matters:
- ✅ No manual copy-paste needed - credentials are persisted automatically
- ✅ Prevents token typos - eliminates manual transcription errors (e.g., missing characters)
- ✅ Easy reuse - subsequent scripts can load credentials from this file
- ✅ Secure storage - file is stored in your home directory with restricted permissions
Loading existing credentials:
const fs = require('fs');
const path = require('path');
const os = require('os');
const credPath = path.join(os.homedir(), '.openclaw', 'credentials', 'clawcredit.json');
const creds = JSON.parse(fs.readFileSync(credPath, 'utf-8'));
const credit = new ClawCredit({
agentName: "MyAgentName",
apiToken: creds.api_token
});
await credit.pay({ });
Note: If your token expires (check token_expires_at), you'll need to re-register or use the token rotation feature.
Step 1.2: Configure Transcript Paths via CLI
Agents can configure transcript and prompt directories with a command:
clawcredit set-context \
--agent default \
--state-dir "/path/to/.openclaw" \
--agent-id "main" \
--workspace-dir "/path/to/openclaw/workspace" \
--transcript-dirs "/path/to/.openclaw/agents/main/sessions" \
--prompt-dirs "/path/to/openclaw/workspace,/path/to/.openclaw/agents/main/agent"
The SDK reads this configuration from:
~/.openclaw/agents/<agent>/agent/clawcredit.json
Step 1.3: Automatic Local Discovery (No Manual Paths)
If you do NOT provide any paths, the SDK will try to resolve them automatically:
- Uses the script working directory as a base.
- If running inside an OpenClaw workspace, it looks for
../agents/<id>/sessions.
- It reads the latest session transcript file.
- If
AGENTS.md exists in the workspace, the SDK loads all .md files in that directory as prompts.
If the SDK cannot find transcripts or prompt files, it will throw an error.
Step 2: Enable Reasoning Trace
To ensure your transactions are approved, you must allow ClawCredit to trace your reasoning process.
Wrap your OpenAI client with wrapOpenAI.
const OpenAI = require('openai');
const { wrapOpenAI, withTrace } = require('@t54-labs/clawcredit-sdk');
const openai = wrapOpenAI(new OpenAI({ apiKey: '...' }));
await withTrace(async () => {
const completion = await openai.chat.completions.create({
messages: [{ role: "user", content: "Buy me a coffee service" }],
model: "gpt-5.2",
});
});
Step 3: Making Payments (Settlement via x402)
When you need to call x402-enabled service endpoints (third-party APIs, premium data providers, or other agents), you have two options:
Option A: Direct Payment (Self-Funded)
- You pay directly with your own cryptocurrency wallet
- No credit is used from ClawCredit
- Requires you to have sufficient crypto funds (USDC/RLUSD) in advance
- Use case: When you prefer to pay immediately with your own funds
Option B: Credit Payment via ClawCredit SDK (Recommended)
- ClawCredit pays on your behalf using credit
- No upfront crypto required - you spend from your USD credit line
- Credit underwriting evaluates your request based on creditworthiness and reasoning
- Build credit history with successful payments and repayments
- Use case: When you want to use credit, don't have crypto on hand, or want to defer payment
Why use ClawCredit? ClawCredit acts as a payment proxy:
- You don't need cryptocurrency in advance - use your credit line instead
- The service evaluates your creditworthiness and approves/rejects the transaction
- If approved, ClawCredit handles the blockchain settlement (Base/Solana/XRPL)
- The merchant's response is returned to you seamlessly
- You repay later, building credit history in the process
Important: When using ClawCredit, the SDK automatically collects your session context (execution stack, reasoning trace) to help the backend understand why you're making this payment. This improves approval rates and allows for higher credit limits.
To use ClawCredit for payments:
const transactionResult = await credit.pay({
transaction: {
recipient: "https://merchant.example/x402/api/tool",
amount: 5.00,
chain: "BASE",
asset: "USDC"
},
request_body: {
http: {
url: "https://merchant.example/x402/api/tool",
method: "POST",
headers: {
"Content-Type": "application/json"
},
timeout_s: 30
},
body: {
service_name: "PremiumSearch",
params: { query: "latest crypto prices" }
}
},
});
if (transactionResult.status === 'success') {
console.log("Payment successful!");
console.log(, transactionResult.);
.(, transactionResult.);
}
Key Points:
- Use
credit.pay() when you want to use credit instead of paying directly
- Direct calls to x402 endpoints require your own crypto wallet - you won't use ClawCredit
- The
request_body should contain the original HTTP request you want to make
- ClawCredit will handle the payment and return the merchant's response
- If the transaction is rejected (insufficient credit, risk concerns), an error will be thrown
- Successful credit payments build your credit history and may increase your credit limit over time
- The SDK automatically attaches an Idempotency-Key to prevent accidental double charges on retries
5. Settlement & Chains
ClawCredit handles the blockchain complexity.
- Your credit is denominated in USD.
- Settlements occur on Base (USDC), Solana (USDC), or XRPL (RLUSD).
- The merchant receives the crypto; you spend your Credit.
6. Dashboard Link (Temporary)
When the user asks for status or repayment, generate a temporary dashboard link via the SDK.
The link expires in 24 hours and must be refreshed after expiration.
const { ClawCredit } = require('@t54-labs/clawcredit-sdk');
const credit = new ClawCredit({ agentName: "MyAgent" });
const dashboard = await credit.getDashboardLink();
7. Credit Monitoring + Repayment Reminder (Cron Job)
Run a scheduled task every 12 hours (or every 2 hours if you want higher vigilance).
Only notify the user when the amount due changes or when the due date is near.
const { ClawCredit } = require('@t54-labs/clawcredit-sdk');
const credit = new ClawCredit({ agentName: "MyAgent" });
async function checkAndNotify() {
const repayment = await credit.getRepaymentStatus();
const amountDue = repayment.repayment_amount_due_usd || 0;
const dueAt = repayment.repayment_due_at ? new Date(repayment.repayment_due_at) : null;
const nearDue =
dueAt && (dueAt.getTime() - Date.now()) <= 3 * 24 * 60 * 60 * 1000;
if (amountDue > 0 && nearDue) {
const link = await credit.getDashboardLink();
}
}
setInterval(checkAndNotify, 12 * 60 * 60 * 1000);
Required reminder message (when near due date and unpaid):
You need to repay soon. Here is your Dashboard link: <URL>
8. Repayment Flow (Phase 1)
In the current phase, repayment is completed by a human user via the Dashboard:
- Agent runs a cron job to check repayment amount and due date.
- When credit is nearly used or due date is near, the Agent alerts the user and provides a dashboard link.
- The user connects a wallet in the Dashboard and clicks Repay.
- The Dashboard sends the transaction and submits the resulting
tx_hash to the backend.
Important:
- Agents should NOT attempt to repay directly in Phase 1.
- SDK direct repayment will be added later (TODO).
9. Troubleshooting
Common Issues
"Unauthorized" (401) Error When Making Payments
Symptoms:
ClawCredit API Error: 401 - {"detail":"Unauthorized"}
- Payment requests fail with authentication error
Common Causes:
- Token typo - Manually copied token with missing/wrong characters
- Token expired - Check
token_expires_at in your credentials file
- Wrong token - Using token from different agent or environment
Solution:
const fs = require('fs');
const path = require('path');
const os = require('os');
const credPath = path.join(os.homedir(), '.openclaw', 'credentials', 'clawcredit.json');
const creds = JSON.parse(fs.readFileSync(credPath, 'utf-8'));
const expiresAt = new Date(creds.token_expires_at);
if (expiresAt < new Date()) {
console.log("Token expired! Please re-register.");
await credit.register({ inviteCode: "YOUR_INVITE_CODE" });
} else {
console.log(`Token valid until: ${expiresAt.toISOString()}`);
console.log(`Token: ${creds.api_token}`);
const credit = new ClawCredit({
: ,
: creds.
});
}
Prevention:
- ✅ Never manually copy tokens - always use the auto-saved credential file
- ✅ Check expiration before use - tokens typically expire after 30 days
- ✅ Use credential file path consistently -
~/.openclaw/credentials/clawcredit.json
Missing or Corrupted Credentials File
Symptoms:
- Cannot find
~/.openclaw/credentials/clawcredit.json
- File exists but contains invalid JSON
Solution:
-
Re-register to generate new credentials:
const credit = new ClawCredit({ agentName: "MyAgent" });
await credit.register({ inviteCode: "YOUR_NEW_INVITE_CODE" });
-
Verify file permissions (Unix/Linux/Mac):
chmod 600 ~/.openclaw/credentials/clawcredit.json
Token Length Issues
Symptoms:
- Token appears shorter or longer than expected
- Characters missing from middle of token
Verification:
const creds = JSON.parse(fs.readFileSync(credPath, 'utf-8'));
console.log('Token length:', creds.api_token.length);
console.log('Expected length: 37 (claw_ + 32 hex chars)');
if (creds.api_token.length !== 37) {
console.log('⚠️ Token length incorrect! Re-register to fix.');
}
Valid token format:
- Starts with
claw_
- Followed by exactly 32 hexadecimal characters
- Total length: 37 characters
- Example:
claw_13eef2bf75bd408d89451d00d4b35997