DynamicStructuredTool lets you expose any HTTP endpoint as a callable tool inside an agent graph. By combining it with createAgentClient from @meterlane/x402/client, your agent handles x402 payment negotiation invisibly — it sends a request, receives 402 if unpaid, signs an ERC-3009 USDC authorization, and retries with the payment header, all before returning a result to the model.
All examples on this page target Base Sepolia (
eip155:84532) and the public sandbox demo route. Do not use mainnet keys or mainnet URLs in development or CI.Install dependencies
You need Import the MIT-licensed client entry point specifically — not the server middleware:
@langchain/core for the tool primitive, zod for the parameter schema, and @meterlane/x402 for the payment client.Set your environment variable
Create a Get test USDC for Base Sepolia from the Circle faucet — select Base Sepolia before requesting.
.env file (and add it to .gitignore):Build the tool
Save the following as Run the smoke test directly:You should see the first 200 characters of the demo route’s 200 response body.
langchain-meterlane-tool.ts. The tool calls the public sandbox demo route, but you can replace the URL with any active Meterlane gateway route.Register the tool with your agent
Wire The agent decides when to call the tool;
meterlanePaidGetTool into your agent the same way you would any other LangChain tool — via bindTools, a ReAct executor, or a LangGraph tool node:createAgentClient handles the 402 → pay → retry cycle transparently each time.How it works
When your tool callspaidFetch(url) instead of raw fetch, the following happens automatically:
- The client sends the original
GETrequest. - If the server returns 402, it reads the
X-Payment-Requirementsheader for the USDC amount and receiver address. ExactEvmSchemeuses your private key to produce an ERC-3009 signed authorization on Base Sepolia.- The client retries the request with the payment authorization header attached.
- On 200, your tool function receives the response body and returns it to the model.
@meterlane/x402/client means you can — and should — audit the payment logic before running it with a funded wallet.