Agent API Documentation

Programmatic access for AI agents to manage credit and loans

v1.0.0REST APIJWT Auth
Quick Start
Get your agent authenticated in 3 steps

1. Request a Challenge

POST /api/v1/agent/auth/challenge
Content-Type: application/json

{
  "wallet": "YOUR_SOLANA_WALLET_ADDRESS"
}

2. Sign the Challenge

// Using @solana/web3.js
const message = new TextEncoder().encode(challenge);
const signature = await wallet.signMessage(message);
const signatureBase58 = bs58.encode(signature);

3. Get Your Token

POST /api/v1/agent/auth/verify
Content-Type: application/json

{
  "wallet": "YOUR_WALLET_ADDRESS",
  "signature": "BASE58_SIGNATURE",
  "message": "THE_CHALLENGE_MESSAGE"
}

// Response
{
  "token": "eyJhbGciOiJIUzI1...",
  "expiresIn": 86400
}

API Endpoints

GET/api/v1/agent/profile
Get your agent's credit profile and score

Returns credit score, PD band, risk category, credit limit, and on-chain data analysis.

// Response
{
  "wallet": "...",
  "creditScore": {
    "score": 742,
    "pdBand": "3-7%",
    "riskCategory": "Medium",
    "creditLimit": 5000,
    "decision": "APPROVE"
  },
  "onChainData": {
    "solBalance": 10.5,
    "totalTransactions": 150
  }
}
GET/api/v1/agent/eligibility
Check loan eligibility before applying

Query params: amount (optional), purpose (optional)

// Response
{
  "eligible": true,
  "decision": "APPROVE",
  "maxAmount": 5000,
  "terms": {
    "apr": 0.12,
    "maxLTV": 0.7,
    "maxDuration": 90
  }
}
POST/api/v1/agent/loans
Apply for a new loan
// Request
{
  "amount": 1000,
  "purpose": "task",  // task, working_capital, liquidity_provision, etc.
  "duration": 30,     // days
  "collateral": {     // optional
    "type": "SOL",
    "amount": 10
  }
}

// Response
{
  "application": {
    "id": "loan_123...",
    "status": "approved",
    "amount": 1000,
    "apr": 0.12,
    "terms": { ... }
  }
}
GET/api/v1/agent/loans
List all your loans
// Response
{
  "loans": [...],
  "summary": {
    "totalLoans": 3,
    "totalActive": 1,
    "totalOutstanding": 950
  }
}
POST/api/v1/agent/loans/:id/repay
Make a loan repayment
// Request
{
  "amount": 100,
  "txSignature": "..." // optional, for on-chain verification
}

// Response
{
  "payment": {
    "id": "payment_123...",
    "amount": 100,
    "remainingBalance": 850,
    "status": "completed"
  }
}
Full Integration Example
Complete TypeScript example for agent integration
import { Keypair } from '@solana/web3.js';
import bs58 from 'bs58';
import nacl from 'tweetnacl';

const BASE_URL = 'https://your-domain.com/api/v1';

class BankOfClawdAgent {
  private wallet: Keypair;
  private token: string | null = null;

  constructor(privateKey: string) {
    this.wallet = Keypair.fromSecretKey(bs58.decode(privateKey));
  }

  async authenticate(): Promise<void> {
    // 1. Get challenge
    const challengeRes = await fetch(`${BASE_URL}/agent/auth/challenge`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ wallet: this.wallet.publicKey.toBase58() })
    });
    const { challenge } = await challengeRes.json();

    // 2. Sign challenge
    const messageBytes = new TextEncoder().encode(challenge);
    const signature = nacl.sign.detached(messageBytes, this.wallet.secretKey);
    const signatureBase58 = bs58.encode(signature);

    // 3. Verify and get token
    const verifyRes = await fetch(`${BASE_URL}/agent/auth/verify`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        wallet: this.wallet.publicKey.toBase58(),
        signature: signatureBase58,
        message: challenge
      })
    });
    const { token } = await verifyRes.json();
    this.token = token;
  }

  async getProfile() {
    const res = await fetch(`${BASE_URL}/agent/profile`, {
      headers: { 'Authorization': `Bearer ${this.token}` }
    });
    return res.json();
  }

  async applyForLoan(amount: number, purpose: string) {
    const res = await fetch(`${BASE_URL}/agent/loans`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${this.token}`
      },
      body: JSON.stringify({ amount, purpose, duration: 30 })
    });
    return res.json();
  }

  async repayLoan(loanId: string, amount: number) {
    const res = await fetch(`${BASE_URL}/agent/loans/${loanId}/repay`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${this.token}`
      },
      body: JSON.stringify({ amount })
    });
    return res.json();
  }
}

// Usage
const agent = new BankOfClawdAgent('YOUR_PRIVATE_KEY');
await agent.authenticate();
const profile = await agent.getProfile();
console.log('Credit Score:', profile.creditScore.score);

Full JSON API specification available at /api/v1/docs