https://api.chipipay.com/v1
When to use
/ai/think and /ai/execute work together to power autonomous DeFi agents. Think decides what to do; Execute builds the how.
What you can build
- Autonomous DeFi agent —
/thinkruns on a schedule (hourly, daily), if it saysswap→/executebuilds the swap → your agent signs and submits via session key. Fully automated, gasless. - Portfolio advisor app — Show users a dashboard with AI recommendations.
/thinkwith their real balances + chosen risk level. They review the suggestion and approve manually. - Risk-managed vault — A smart contract-backed strategy where
/thinkenforces risk params (max drawdown, min stablecoins) before any rebalance. - Telegram trading bot — User sends portfolio snapshot, bot calls
/think, replies with the recommendation and a “execute” button that triggers/execute. - Yield optimizer —
/thinkincludes DeFi yield data from DefiLlama. An agent can compare swap gains vs. yield APY and pick the better move.
/think automatically fetches live signals (RSI, MACD, Fear & Greed, yields) — you don’t need to call /signals first. Just send the portfolio.POST /ai/think
DeFi portfolio advisor. Analyzes your portfolio with real-time market signals (RSI, MACD, Fear & Greed, yields) and returns a structured JSON decision:swap, supply, withdraw or hold, with confidence and reasoning.
Cost: Per token (same as /chat — the model call is the cost)
Request body
Risk parameter overrides
All optional. Defaults scale linearly withriskScore. Override any individual param without affecting others.
How risk scoring works
Risk parameters scale withriskScore from conservative (1) to aggressive (10):
The
/think endpoint automatically injects live market data (signals, yields, Fear & Greed) into the AI prompt. You don’t need to fetch signals separately — just send the portfolio and risk score.Pay per call with x402
An agent can pay a/think call itself, in USDC from its session key, instead of from your org’s credits. Chipi offers this only when your credits are short and you call with a secret key (sk_). The 402 then carries an x402 offer:
The price covers the model, the gas Chipi sponsors for your payment and the platform margin, for the worst case of every payable model. Credits stay cheaper (about $0.002 a decision on
haiku), because they need no payment transaction.
sdk.ai.think pays for you with payWithSession. Without it, a 402 is thrown as before.
- Checks before paying. It refuses
X402_PRICE_ABOVE_MAX,X402_MODEL_NOT_PAYABLE,X402_PAYLOAD_TOO_LARGEorX402_INVALID_MAX_AMOUNT, and nothing is paid. From 14.15.1 it also names the wallet in anX-PAYERheader, and refuses withX402_PAYER_NOT_IN_ORGwhen the offer’sextra.payersays a payment from it would not be accepted. - Pays with a session-signed USDC
transferto the offer’spayToand waits for the receipt. - Sends
X-PAYMENTonly if the USDC reachedpayTo. A transfer the wallet refused comes back succeeded with nothing moved: that throwsX402_PAYMENT_FAILEDand is never sent. Whitelisttransferin the session and cap USDC. - Hands a paid-but-unserved call back. If the call fails after paying (
X402_PAYMENT_PENDING, or an API error on the paid retry),error.details.xPaymentholds the payment: pass it asoptions.xPaymentto retry without paying again. A payment is spent only once a call is served.
POST /ai/execute
Build unsigned swap calldata from AVNU (Starknet DEX aggregator). Returns the transaction calls — you sign and submit via session key or wallet. Cost: $0.002 per call (flat, not per token)Request body
Putting it together: Think + Execute
A typical DeFi agent flow:- Think — send portfolio + risk score, get a decision
- If the decision is
swap→ Execute — get unsigned swap calldata - Sign the calls with your wallet or session key
- Submit via Chipi’s gasless paymaster
With the SDK (14.14.0+)
@chipi-stack/backend wraps these endpoints as sdk.ai. It authenticates with your secret key and refuses to run without one, so it is server-only.
API errors throw
ChipiApiError with the API’s code and status, for example INSUFFICIENT_BALANCE (402), MODEL_RATE_LIMITED (429), MODEL_UNAVAILABLE (503) or SIGNALS_UNAVAILABLE (503). The full error body is on error.details, which is how you read the x402 offer of a 402.
✅ Verified against the live API on 2026-10-05.
