> ## Documentation Index
> Fetch the complete documentation index at: https://docs.boltzpay.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# LangChain

> 7 LangChain tools for discovering and paying for APIs from Python.

## Install

```bash theme={null}
pip install langchain-boltzpay
```

Requires **Node.js 20+** (the tools call `npx @boltzpay/cli` under the hood).

## Quick Start

```python theme={null}
from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
from langchain_boltzpay import (
    BoltzPayFetchTool,
    BoltzPayQuoteTool,
    BoltzPayDiscoverTool,
)

tools = [BoltzPayDiscoverTool(), BoltzPayQuoteTool(), BoltzPayFetchTool()]
llm = ChatOpenAI(model="gpt-4o-mini")

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a researcher. Use BoltzPay to access paid APIs."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])

agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)

result = executor.invoke({"input": "Check the price of invy.bot/api"})
```

## Enable Payments

Set Coinbase CDP environment variables before running:

```bash theme={null}
export COINBASE_API_KEY_ID="your-key-id"
export COINBASE_API_KEY_SECRET="your-key-secret"
export COINBASE_WALLET_SECRET="your-wallet-secret"
```

```python theme={null}
from langchain_boltzpay import BoltzPayFetchTool

fetch = BoltzPayFetchTool()
result = fetch._run(url="https://invy.bot/api")
print(result)  # Paid API response with payment receipt
```

## Tools

| Tool                   | Name                | Description                                      | Credentials |
| ---------------------- | ------------------- | ------------------------------------------------ | :---------: |
| `BoltzPayFetchTool`    | `boltzpay_fetch`    | Fetch data from a paid API, auto-pay with USDC   |     Yes     |
| `BoltzPayQuoteTool`    | `boltzpay_quote`    | Get price quote without paying                   |      No     |
| `BoltzPayDiscoverTool` | `boltzpay_discover` | Browse available paid APIs                       |      No     |
| `BoltzPayBudgetTool`   | `boltzpay_budget`   | Show remaining spending budget                   |      No     |
| `BoltzPayHistoryTool`  | `boltzpay_history`  | Show payment history                             |      No     |
| `BoltzPayWalletTool`   | `boltzpay_wallet`   | Show wallet and config info                      |      No     |
| `BoltzPayDiagnoseTool` | `boltzpay_diagnose` | Full endpoint diagnostic (DNS, protocol, health) |      No     |

## Error Handling

All tools set `handle_tool_error=True`, so agents recover gracefully. You can also catch errors directly:

```python theme={null}
from langchain_boltzpay import BoltzPayFetchTool
from langchain_boltzpay.errors import (
    BoltzPayBridgeError,
    BoltzPayNodeNotFoundError,
    BoltzPayTimeoutError,
)

try:
    tool = BoltzPayFetchTool()
    tool._run(url="https://example.com/api")
except BoltzPayNodeNotFoundError:
    print("Install Node.js 20+ from https://nodejs.org")
except BoltzPayTimeoutError:
    print("CLI command timed out (default: 30s)")
except BoltzPayBridgeError as e:
    print(f"CLI error [{e.code}]: {e.message}")
```

<Info>
  A Jupyter notebook is included at `notebooks/getting-started.ipynb` for a step-by-step walkthrough.
</Info>
