← All guides · Markdown: /guides/langchain-js.md

LangChain (JavaScript): a paid tool for createAgent

Give a LangChain JS agent one of the shop's tools: tool() with a zod schema, paid per call with x402, free trial first.

For: LangChain JS 1.x. Endpoint shape: GET https://shop.lordevo.com/api/quick/<tool>?<input>; (HTTP 402 with x402 terms until paid). All guides: https://shop.lordevo.com/guides

Easier: use the SDK: https://shop.lordevo.com/guides/sdk/langchain-js

Prerequisites

Code

Put the helper from https://shop.lordevo.com/guides/x402-fetch in lordevo.mjs next to this file.

// npm i langchain @langchain/core zod   (plus the helper's packages)
import { createAgent, tool } from 'langchain';
import * as z from 'zod';
import { lordevoTool } from './lordevo.mjs'; // tries a free trial call first (X-Lordevo-Trial: 1), then pays

const dnsLookup = tool(input => lordevoTool("dns-lookup", input), {
  name: "dns_lookup",
  description: "DNS records lookup (A, AAAA, CNAME, MX, TXT, NS, SOA, CAA). Costs $0.003 per call (x402, USDC on Base); 3 free trial calls per IP per UTC day (shared by all tools up to $0.005). Instant tools that fail or are refused are not charged. Long jobs (202) are charged when accepted and are not refunded automatically if they fail later. If a paid job failed, email hello@lordevo.com with the transaction hash and we'll review it, usually within 2 business days.",
  schema: z.object({
    host: z.string().describe("Host name to look up, e.g. example.com or mail.example.com (a URL also works; the host part is used)"),
    type: z.enum(["ALL","A","AAAA","CNAME","MX","TXT","NS","SOA","CAA"]).optional().describe("Record type (default ALL = A, AAAA, CNAME, MX, TXT, NS, SOA, CAA)"),
  }),
});

// Any chat model LangChain supports, e.g. "openai:<model>" or "anthropic:<model>" (provider key in its usual env variable).
const agent = createAgent({ model: process.env.LANGCHAIN_MODEL, tools: [dnsLookup] });
const out = await agent.invoke({ messages: [{ role: 'user', content: "Use the dns_lookup tool on example.com and summarise the answer." }] });
console.log(out.messages.at(-1).content);

Try it free (no wallet)

lordevoTool() always tries a free call first (3 per IP per UTC day on tools up to $0.005). Without AGENT_WALLET_KEY the agent gets {"error":"http_402", ...} once the free calls are used up, and can tell the user.

Errors (nothing is charged on any of these)

The tool never throws: errors reach the model as JSON (error, message, retry_after_seconds, charged: false).

Next tools to try

Checked

Written 2026-10-30 against the current public docs:

The snippets follow those docs; they were not executed end to end by the shop. Tell us if something has moved: hello@lordevo.com