> ## Documentation Index
> Fetch the complete documentation index at: https://x402-stellar.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# @stellar-x402/client

> Autonomous AI Agent client for resolving x402 paywalls

## Installation

```bash theme={null}
pnpm add @stellar-x402/core @stellar-x402/client
```

## Features

* **Automated Handshake**: Automatically detects `402 Payment Required` responses, inspects challenge parameters, and generates cryptographic signatures.
* **Budget Policy Enforcement**: Prevents runaway spending by strictly enforcing per-call caps (`maxSpendPerCall`) and rolling 24-hour spending limits (`maxDailySpend`).
* **Fetch Drop-in Wrapper**: Wraps the standard JavaScript `fetch()` API.

## Usage Example

```typescript theme={null}
import { StellarX402Client } from '@stellar-x402/client';

const client = new StellarX402Client({
  payerSecretKey: process.env.AGENT_STELLAR_SECRET!,
  maxSpendPerCall: '0.05',  // Maximum 0.05 USDC per individual request
  maxDailySpend: '2.50',    // Maximum 2.50 USDC total spend per 24 hours
  network: 'stellar:testnet',
});

// Calling a paywalled endpoint
try {
  const response = await client.fetch('https://api.example.com/api/v1/inference', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ prompt: 'Analyze ledger volume' }),
  });

  const data = await response.json();
  console.log('Result:', data);
} catch (err: any) {
  if (err.message.includes('Budget exceeded')) {
    console.error('Call halted by local spending guardrail:', err.message);
  }
}
```
