# LangChain

> Give LangChain agents live web search, agentic search, news, and page content with the official search1api-langchain toolkit.

Canonical URL: https://s1.dev/docs/integrations/langchain

`search1api-langchain` is the official Search1API integration for LangChain. It
exposes web search, agentic search, news search, and page crawling through LangChain's standard
tool interface, and relies on the official Search1API Python SDK for
authentication, retries, timeouts, and API errors.

> **info:** The similarly named `langchain-search1api` package on PyPI is an independent
> third-party project. `search1api-langchain` is the package maintained by
> Search1API.

## Install

```bash
pip install search1api-langchain
```

Create a key in the [dashboard](https://app.s1.dev), then export it:

```bash
export SEARCH1API_API_KEY="your-api-key"
```

`SEARCH1API_KEY` is also accepted, so the same environment works for the
[Search1API CLI](https://s1.dev/docs/integrations/cli).

## Use the whole toolkit

`Search1APIToolkit` returns every tool at once, ready to hand to an agent.

```python
from langchain.agents import create_agent
from search1api_langchain import Search1APIToolkit

agent = create_agent(
    model="openai:gpt-5.4",
    tools=Search1APIToolkit().get_tools(),
)

response = agent.invoke(
    {"messages": [{"role": "user", "content": "What changed in LangChain this month?"}]}
)
```

The toolkit provides `search1api_search`, `search1api_news`,
`search1api_crawl`, and `search1api_ask`. Each tool is also importable on its own when an agent should
only receive one capability.

Every tool supports asynchronous invocation:

```python
from search1api_langchain import Search1APISearchTool

search = Search1APISearchTool()
result = await search.ainvoke({"query": "async Python agents"})
```

An explicit key and client settings can be supplied when environment-based
configuration is not appropriate:

```python
from search1api_langchain import Search1APISearchTool

search = Search1APISearchTool(
    api_key="your-api-key",
    timeout=45,
    max_retries=3,
)
```

API keys use Pydantic's secret type and are excluded from model serialization.

## Search

`search1api_search` returns ranked web results for a query.

```python
from search1api_langchain import Search1APISearchTool

search = Search1APISearchTool()

results = search.invoke(
    {
        "query": "latest LangChain agent releases",
        "max_results": 5,
        "time_range": "month",
    }
)
```

Each result carries `title`, `link`, and `snippet`. Setting `crawl_results` also
fills `content` with the readable page text, and image queries return an
`images` list. `search_service` selects the upstream engine when a specific one
is required.

See [Search](https://s1.dev/docs/basic/search) for the full request and response contract.

## Agentic search

`search1api_ask` accepts only `query` (1-500 characters). Search1API chooses the
sources, search query, and time range. It costs five credits per request and uses
a separate 45-second timeout (`Search1APIToolkit(ask_timeout=45)`).

```python
from search1api_langchain import Search1APIAskTool

result = Search1APIAskTool().invoke(
    {"query": "What are developers discussing about Bun on GitHub this week?"}
)
```

The response includes `query`, `intent`, `results`, and optional `errors`; results
keep their `source` and `relevance`. See [Ask](https://s1.dev/docs/basic/ask).

## News

`search1api_news` returns recent news articles for a query, with the same
result shape as search.

```python
from search1api_langchain import Search1APINewsTool

news = Search1APINewsTool()

articles = news.invoke({"query": "AI regulation", "time_range": "day"})
```

See [News](https://s1.dev/docs/basic/news) for supported sources and parameters.

## Crawl

`search1api_crawl` reads a known URL and returns clean, readable content. It
fetches and extracts page content; it does not drive a browser session.

```python
from search1api_langchain import Search1APICrawlTool

crawl = Search1APICrawlTool()

page = crawl.invoke({"url": "https://example.com/article"})
```

Pass a URL returned by search when an agent needs the full article rather than a
snippet. See [Crawl](https://s1.dev/docs/basic/crawl) for the full contract.

## Credits

Search and news requests cost one credit each. Setting `crawl_results` asks
Search1API to read the top result pages and costs one additional credit for each
page crawled successfully, so the tools default it to `0`. A crawl request costs
one credit. Agentic search costs five credits per request.

New accounts receive 100 credits without a credit card or expiration date. See
[Credits and limits](https://s1.dev/docs/essentials/credits-and-limits) for current rates.

## Search filters and result fields

Version **0.2.0** supports all 19 [search engines](https://s1.dev/docs/basic/search) and all six
[news sources](https://s1.dev/docs/basic/news), including Bing China, Yandex, Grokipedia, and Reuters.
`time_range` supports `day`, `week`, `month`, and `year`; `page` supports search
pagination. These filters apply to search/news; agentic search accepts only `query`.

Engine-specific result fields live in optional `metadata`: GitHub search exposes
`metadata.kind`, `metadata.stars`, `metadata.language`, and `metadata.num_comments`;
Hacker News search exposes `metadata.story_url`, `metadata.points`, and
`metadata.num_comments`. Optional `published_date` stays at the result top level.
The response-level `searchParameters` describes the executed request. These paths
apply to search/news; [trending](https://s1.dev/docs/advanced/trending) keeps its separate response shape.

## Source

[github.com/superagents-lab/search1api-langchain](https://github.com/superagents-lab/search1api-langchain)
· [PyPI](https://pypi.org/project/search1api-langchain/)