> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useotto.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Your first paid Otto AI call

> Check an Otto AI route's price for free, then pay for one request in USDC on Base or Solana with copy-paste Python or Node.js.

Every paid Otto AI route states its price before you pay. Check the price for free, then pay for one `/crypto-news` response. Each starter pays **0.001 USDC** and refuses a higher price.

## Check the price for free

This needs Python 3 only. It needs no wallet and no packages:

```python theme={null}
import base64, json, urllib.error, urllib.request

url = "https://x402.ottoai.services/crypto-news"
try:
    urllib.request.urlopen(url, timeout=30)
except urllib.error.HTTPError as err:
    if err.code != 402:
        raise
    challenge = json.loads(base64.b64decode(err.headers["PAYMENT-REQUIRED"]))
    prices = {o["network"]: int(o["amount"]) / 1_000_000 for o in challenge["accepts"]}
    for network, usdc in prices.items():
        print(f"{network}: {usdc} USDC")
```

It prints the price on each network that the route accepts:

```text theme={null}
eip155:8453: 0.001 USDC
solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp: 0.001 USDC
```

`eip155:8453` is Base. `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp` is Solana. To price another route, change the URL. The [API reference](https://docs.useotto.xyz/api-reference/overview.md) lists every route with its price.

## Pay with Python on Base

The payment wallet needs USDC on Base. It needs no ETH. Load `X402_PRIVATE_KEY` through your local secret configuration. Never put a key in source code or an agent conversation.

```bash theme={null}
pip install "x402[requests,evm]>=2.28"
```

Save as `base_request.py` and run it with `python base_request.py`:

```python theme={null}
import base64, json, os
import requests
from eth_account import Account
from x402 import max_amount, x402ClientSync
from x402.http.clients import wrapRequestsWithPayment
from x402.mechanisms.evm.exact import ExactEvmScheme
from x402.mechanisms.evm.signers import EthAccountSigner

account = Account.from_key(os.environ["X402_PRIVATE_KEY"])
client = x402ClientSync()
client.register("eip155:8453", ExactEvmScheme(signer=EthAccountSigner(account)))
client.register_policy(max_amount(1000))  # 0.001 USDC (USDC has 6 decimals)

session = wrapRequestsWithPayment(requests.Session(), client)
response = session.get("https://x402.ottoai.services/crypto-news", timeout=60)
if response.status_code == 402:
    refusal = json.loads(base64.b64decode(response.headers["PAYMENT-REQUIRED"]))
    raise SystemExit(f"Payment refused: {refusal.get('error')}")
response.raise_for_status()
with open("otto-result.json", "w") as f:
    json.dump({
        "data": response.json(),
        "paymentResponse": response.headers.get("PAYMENT-RESPONSE"),
    }, f, indent=2)
print("Saved otto-result.json")
```

## Pay with Python on Solana

Solana payment works on every route whose price quote lists Solana. The payment wallet needs USDC on Solana. It needs no SOL, because the network fee is paid for you. Load `SOLANA_PRIVATE_KEY`, the wallet's base58 secret key, through your local secret configuration.

```bash theme={null}
pip install "x402[requests,svm]>=2.28"
```

Save as `solana_request.py` and run it with `python solana_request.py`:

```python theme={null}
import base64, json, os
import requests
from solders.keypair import Keypair
from x402 import max_amount, x402ClientSync
from x402.http.clients import wrapRequestsWithPayment
from x402.mechanisms.svm import KeypairSigner
from x402.mechanisms.svm.exact import ExactSvmScheme

SOLANA = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
keypair = Keypair.from_base58_string(os.environ["SOLANA_PRIVATE_KEY"])
client = x402ClientSync()
client.register(SOLANA, ExactSvmScheme(KeypairSigner(keypair)))
client.register_policy(max_amount(1000))  # 0.001 USDC (USDC has 6 decimals)

session = wrapRequestsWithPayment(requests.Session(), client)
response = session.get("https://x402.ottoai.services/crypto-news", timeout=60)
if response.status_code == 402:
    refusal = json.loads(base64.b64decode(response.headers["PAYMENT-REQUIRED"]))
    raise SystemExit(f"Payment refused: {refusal.get('error')}")
response.raise_for_status()
with open("otto-result.json", "w") as f:
    json.dump({
        "data": response.json(),
        "paymentResponse": response.headers.get("PAYMENT-RESPONSE"),
    }, f, indent=2)
print("Saved otto-result.json")
```

## Pay with Node.js on Solana

The same Solana payment from Node.js 20.18 or later:

```bash theme={null}
npm install @x402/fetch @x402/svm @solana/kit
```

Save as `solana-request.mjs` and run it with `node solana-request.mjs`:

```javascript theme={null}
import { writeFileSync } from 'node:fs';
import { wrapFetchWithPayment, x402Client } from '@x402/fetch';
import { toClientSvmSigner } from '@x402/svm';
import { ExactSvmScheme } from '@x402/svm/exact/client';
import { createKeyPairSignerFromBytes, getBase58Encoder } from '@solana/kit';

const SOLANA = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';
const USDC = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
const keypair = await createKeyPairSignerFromBytes(
  getBase58Encoder().encode(process.env.SOLANA_PRIVATE_KEY),
);
const client = new x402Client((_version, requirements) => {
  const option = requirements.find(r => r.network === SOLANA && r.asset === USDC);
  if (!option || BigInt(option.amount) > 1000n) {
    throw new Error('No Solana-USDC price at or below 0.001');
  }
  return option;
});
client.register(SOLANA, new ExactSvmScheme(toClientSvmSigner(keypair)));
const paidFetch = wrapFetchWithPayment(fetch, client);
const response = await paidFetch('https://x402.ottoai.services/crypto-news');
if (response.status === 402) {
  const refusal = JSON.parse(Buffer.from(response.headers.get('payment-required'), 'base64'));
  throw new Error(`Payment refused: ${refusal.error}`);
}
if (!response.ok) throw new Error(`HTTP ${response.status}`);
writeFileSync('otto-result.json', JSON.stringify({
  data: await response.json(),
  paymentResponse: response.headers.get('payment-response'),
  requestedAt: new Date().toISOString(),
}, null, 2));
console.log('Saved otto-result.json');
```

For Node.js on Base, follow [Make a paid request](https://docs.useotto.xyz/acp-swarm/x402.md#make-a-paid-request).

## Read the result

Each starter saves `otto-result.json`. It holds the data and the `PAYMENT-RESPONSE` receipt, which is base64 JSON with the settlement transaction. [Read the result](https://docs.useotto.xyz/acp-swarm/x402.md#read-the-result) explains each field.

If the payment is refused, the starter prints the reason from the `402` answer, for example `insufficient_funds`. A refused payment is not charged.

Each starter pays for one call. Give an automated loop its own total budget.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.