Read as Markdown · Use with an AI agent
LangChain integration
Run a LangChain agent with a small allowlist of Monocrawl tools, current endpoint discovery and explicit credit limits.
Prepare a server-side project
Use Node.js 22+ in a separate integration project. Create a dedicated Monocrawl key with an explicit cumulative credit cap. Model-provider usage is billed separately; set that provider’s limits too. Keep both credentials in server environment variables.
npm install langchain@1 @langchain/core@1 @langchain/anthropic@1 zod@4
Save both files in the same directory. Set MONOCRAWL_API_KEY, ANTHROPIC_API_KEY, MODEL_ID (a model available to your account), and MONOCRAWL_BUDGET (an integer credit ceiling). The example permits only TikTok and Instagram profile lookups; expand the application-owned allowlist only for an authorized task.
node langchain-agent.mjs
Discovery, retrieval and a grounded answer
- The example gives the model separate discovery, inspection and retrieval tools. It cannot submit an arbitrary REST URL or call account-changing tools.
- Inspection reads current parameters, MCP availability and credit_cost. Retrieval requires that inspection and validates declared and required parameters.
- The client serializes requests, passes the remaining budget as max_credits and counts each logical result once. Repeated identical inputs reuse the saved response within that process.
- Receipts, warnings and source fields reach the model with the data. The prompt asks it to preserve unknown values and cite returned source URLs.
Handle failure and restart deliberately
The shared client does not retry transport failures automatically. It halts further paid retrieval if the result is ambiguous, has pending accounting or exceeds its local budget. Capture onRequest events in your secure job journal before sending; the example journal stores keys and arguments in memory, so it is not automatic crash recovery. Never log the API credential.
Use the original idempotency key and exact parameters for recovery, following the production guide. Each new process has a new local budget; a dedicated server-side key cap bounds cumulative spend across restarts. Model step limits bound the loop, while the shared client also enforces a maximum number of MCP requests.