Buy Credits
FreePOST /api/payment/buy-creditsPOST to this endpoint with amount_usd, sender_wallet, and a quote message signed by sender_wallet (EIP-191 personal_sign) to receive a payment quote: the wallet address to send USDC to, a memo, the credit amount you will receive, and a 30-minute expiry. The signature proves you control sender_wallet (EOA only); the message layout and error codes are at /developers/agent-payments#sender-proof. Send the USDC from sender_wallet, then call /api/payment/confirm with the tx_hash and the memo as nonce.
When to use this endpoint
Step 1 of the credits-first payment flow. Use this for any agent that will make repeat premium calls; the latency cost is paid once on the credits purchase rather than per-call.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
| amount_usd* | body | number | USD value to purchase. Min 0.5, max 10000. Volume discounts at $5 (10%), $30 (25%), $200 (40%). |
| sender_wallet* | body | string | The EOA that will send the USDC on Base and signs message. 0x-prefixed 40-char address. |
| message* | body | string | The quote message: "I am requesting a TensorFeed credit quote for this wallet.", a blank line, then wallet, timestamp (ISO 8601, within 10 minutes of now), and nonce (16 to 64 hex, single use) lines, joined with \n. |
| signature* | body | string | EIP-191 personal_sign of message by sender_wallet (0x hex, 65 bytes). |
* required
Example response
{
"ok": true,
"wallet": "0x549c82e6bfc54bdae9a2073744cbc2af5d1fc6d1",
"sender_wallet": "0xyour_eoa",
"memo": "tf-eb13b1a17c6811d6",
"amount_usd": 1.0,
"credits": 50,
"currency": "USDC",
"network": "base",
"expires_at": "2026-04-27T18:30:00Z",
"ttl_seconds": 1800,
"next_step": "Send 1 USDC on Base from 0xyour_eoa to 0x549..., then POST /api/payment/confirm with { tx_hash, nonce: \"tf-eb13b1a17c6811d6\" }"
}Code samples
Python SDK
import os
from eth_account import Account
from eth_account.messages import encode_defunct
from tensorfeed import TensorFeed
tf = TensorFeed()
acct = Account.from_key(os.environ["WALLET_KEY"]) # the sender_wallet EOA
def sign(message: str) -> str:
signed = acct.sign_message(encode_defunct(text=message)) # EIP-191
return "0x" + bytes(signed.signature).hex()
# The SDK builds the quote message (fresh timestamp and nonce) and signs it.
quote = tf.buy_credits(amount_usd=1.0, sender_wallet=acct.address, sign_message=sign)
print(f"Send {quote['amount_usd']} USDC from {acct.address} to {quote['wallet']}")
print(f"Memo: {quote['memo']}")TypeScript SDK
import { TensorFeed } from 'tensorfeed';
import { privateKeyToAccount } from 'viem/accounts';
const tf = new TensorFeed();
const account = privateKeyToAccount(process.env.WALLET_KEY as `0x${string}`);
// The SDK builds the quote message (fresh timestamp and nonce) and signs it.
const quote = await tf.buyCredits({
amountUsd: 1.0,
senderWallet: account.address,
signMessage: (m) => account.signMessage({ message: m }),
});
console.log(`Send ${quote.amount_usd} USDC to ${quote.wallet}`);FAQ
How much USDC should I send?
Send exactly the amount_usd from the quote. The on-chain verification compares the received amount against the quoted amount within $0.01; if it matches, you get the quoted credits including any volume discount. If you send more or less, credits are calculated from the actual amount at the base rate.
How long is the quote valid?
30 minutes. After expiry, the quote is unusable and you must request a new one with a newly signed quote message (fresh timestamp and nonce).
Why does the quote need a signature?
The quote binds your credits to sender_wallet, so TensorFeed issues one only to a caller that proves control of that wallet. Sign the quote message with sender_wallet (EIP-191 personal_sign) and send it as message and signature. Each signed message works once. Smart contract wallets cannot sign it and should pay per call through the x402 X-PAYMENT header.