Skip to content
unlob

unlob for LangChain

There is no SDK to install. The API is a GET with a header, which makes a custom tool about ten lines and leaves you in control of exactly which filters your agent may set.

A LangChain toolpython
import os, requests
from langchain_core.tools import tool

BASE = "https://api.unlob.com"
HEADERS = {"x-api-key": os.environ["UNLOB_API_KEY"]}

@tool
def unlob_search(query: str, limit: int = 5) -> list[dict]:
    """Search the web. Returns metadata-only hits, never page bodies."""
    r = requests.get(
        f"{BASE}/search",
        params={"q": query, "limit": limit, "collapse": "story",
                "min_independent_sources": 2},
        headers=HEADERS, timeout=10,
    )
    r.raise_for_status()
    return r.json()["results"]

@tool
def unlob_context(question: str, budget: int = 4000) -> dict:
    """Get a corroborated, trust-ranked context pack for a question."""
    r = requests.get(
        f"{BASE}/assemble_context",
        params={"q": question, "budget": budget},
        headers=HEADERS, timeout=20,
    )
    r.raise_for_status()
    return r.json()

Setup

  1. Get an API key

    10,000 free requests a month.

  2. Define the tools

    Two are usually enough: a search tool and assemble_context. Add get_document if the agent needs full text.

  3. Pin the filters you care about

    Set collapse=story and min_independent_sources in the tool itself rather than exposing them to the model. Defaults you control beat parameters the model guesses.

  4. Bind and run

    Bind the tools to your model as usual. The metadata-only response shape keeps tool results small, which matters in a loop.

Worth knowing

  • Setting filters inside the tool rather than exposing them is the single highest-leverage decision here — most retrieval quality problems in agents are filter problems.
  • assemble_context frequently replaces a whole custom retrieval chain, including the reranking step.

Frequently asked questions

Is there an official LangChain integration?

Not currently. The API is a plain GET with a header, so a custom tool is about ten lines and gives you more control over the filter defaults than a packaged integration would.

Get a key and connect it

10,000 requests a month, no card. The config above works unchanged once you have a key.