Skip to main content

Install


Basic usage


With Alby


Tool reference

Constructor

Tool schema (seen by the LLM)

Methods


Response format

The tool returns a string the LLM can read directly:

POST example


Spending report


Custom agent frameworks

L402Tool is a langchain.tools.BaseTool subclass — it works with any framework that accepts LangChain tools: LangGraph, CrewAI, AutoGen (via adapter), and others.

Error handling

BudgetExceededError is caught internally — the tool returns a [BLOCKED] string instead of raising, so the agent can handle it gracefully in its reasoning loop. All other exceptions (network errors, wallet failures) are returned as [ERROR] <message>. If you need programmatic access:

Without LangChain installed

If langchain is not installed, importing L402Tool succeeds at module level (graceful fallback), but instantiating it raises: