A Vercel AI SDK agent that pays per call.
A working Vercel AI SDK tool that calls a live Apiosk endpoint. The model picks the tool and reads the result; the x402 client underneath answers the 402 and signs a USDC payment on Base per call. No API key, no account.
npm install ai @ai-sdk/anthropic zod @x402/axios @x402/evm axios viemWhat you are about to do
The whole integration is one tool definition and one wallet key. Everything specific to Vercel AI SDK is below; everything specific to payment happens inside the client.
Install the SDK and a paying HTTP client
npm install ai @ai-sdk/anthropic zod @x402/axios @x402/evm axios viem. Put a funded Base wallet key in WALLET_PRIVATE_KEY. Nothing to sign up for, so there is no API key to add.
Define the tool with inputSchema
Wrap the endpoint in tool() from the ai package. Describe the arguments with zod under inputSchema, and let execute call the gateway through the wrapped axios instance. The x402 interceptor handles the 402 and the retry, so execute reads like an ordinary request.
Hand the tool to generateText
Pass it in the tools map on generateText or streamText and bound the loop with stopWhen: isStepCount(n). The model decides when the job needs the tool, calls it with its own arguments, and reads the returned JSON on the next step.
Vercel AI SDK, end to end
Copy these in order. The endpoints are placeholders. Swap in any endpoint from the catalog.
Three things to know
The key lives in the client, not the tool
WALLET_PRIVATE_KEY is read once, where the axios instance is built. Tools import that instance. The model sees the description and the inputSchema and nothing else: not the wallet, not the price, not the payment header. Keep the client in its own module so a second tool cannot reconstruct it with different settings.
execute is async because the call is two round trips
A paid request is a 402 with a price, then a signed retry. Both happen inside execute, so the promise resolves later than an unpaid fetch would. Return the parsed JSON, not the axios response: whatever you return is what the model reads on the next step, and a response object serialises into noise.
stopWhen is the ceiling on a run
maxSteps is gone. stopWhen: isStepCount(n) bounds how many tool round trips one generateText or streamText can make, which is the upper bound on paid calls per run. Leave it out and a loop that keeps calling the tool keeps paying. stepCountIs still resolves as an alias if you have it in older code.
What is Apiosk?
Apiosk is AI-native compliance infrastructure. It gives your team and your AI agents one way to run compliance checks, such as company verification, beneficial ownership, sanctions screening and court records, against official sources. You ask in plain language, review the sources and maximum cost, approve, and get one sourced answer. Once, or on a schedule.
Which checks can I run?
Company profiles and filed accounts from business registers, beneficial ownership, sanctions and watchlist screening, court records, and identifier checks such as VAT numbers and IBANs. Coverage depends on the country and the source. If a source has no record, the result says what is missing rather than guessing.
Explore all checksDoes Apiosk make the compliance decision?
No. Apiosk retrieves the data, combines it and shows where every part came from. Assessing the result and deciding what to do with it stays with you and your compliance process.
How does ongoing monitoring work?
After your first result, choose Make recurring. Pick the days and time, and how much it may spend: a fixed number of prepaid runs, or pay as you go with a maximum per run. Apiosk repeats the check on that schedule and delivers every result, or only what changed, to Slack or Gmail. Each run and its cost stays visible in the order's history.
Can my AI agent run checks?
Yes. Apiosk is available as a connector for ChatGPT and Claude, and through MCP or API for other agents and tools. Authorize the agent once; your spending limits and approval rules control what it can run.
Connect an agentHow much does it cost?
Each check is priced from the sources it uses. Apiosk shows the sources and maximum cost, including its service fee, before anything runs, and recurring checks stay within the budget you approve. You pay from your Apiosk balance, with no subscription required.
See pricingWhich countries do you cover?
Company-register checks include the Netherlands and the United Kingdom. GLEIF legal-entity data and sanctions screening cover international records; VIES validates EU and Northern Ireland VAT numbers. Availability varies by company, filing and source. When a record is not available, we say so.
How does approval work for agents?
You set spending ceilings per request and per rolling day when you connect an agent. Checks need approval in the conversation or in Apiosk, unless you have explicitly authorized small runs in that conversation. A request above a connection limit is refused before it is charged; a person must review the limit in Apiosk before it can proceed.
