langchain-octen
LangChain integration for Octen Web Search. Use Octen's fast, real-time web search inside LangChain agents and chains.
| Tool class | Tool name | Use it for |
|---|---|---|
OctenSearchResults |
octen_search |
One focused web lookup |
OctenSearchPremier |
octen_search_premier |
A hard-to-find specific fact or page (deeper retrieval and reranking) |
OctenBroadSearch |
octen_broad_search |
Multi-part questions, comparisons, surveys (fans out into sub-queries) |
OctenNewsSearch |
octen_news_search |
Recent news, with articles grouped into storylines |
OctenBusinessSearch |
octen_business_search |
Company and person cards (financials, key people, career history) |
OctenPulseSearch |
octen_pulse_search |
The URL of a docs page or site you could almost name |
OctenPlaceSearch |
octen_place_search |
Real-world places, near a point or in a city |
OctenExtract |
octen_extract |
The clean content of pages you already have the URLs of |
OctenImageSearch |
octen_image_search |
Images on the web, found by a text description or by a reference image URL |
OctenDesignSearch |
octen_design_search |
Design references: web pages, page sections, app screens and slides, with their design values |
Installation
pip install langchain-octen
Setup
Get an API key from octen.ai and set it as an environment variable:
export OCTEN_API_KEY="your-api-key"
Or pass it directly when creating the tool:
from langchain_octen import OctenSearchResults
tool = OctenSearchResults(octen_api_key="your-api-key")
Web search (OctenSearchResults)
Basic Search
from langchain_octen import OctenSearchResults
tool = OctenSearchResults(max_results=5)
results = tool.invoke({"query": "latest AI research papers"})
for r in results:
print(r["title"], r["url"])
With Domain Filtering
# Only include results from specific domains
results = tool.invoke({
"query": "machine learning",
"include_domains": ["arxiv.org", "papers.nips.cc"],
})
# Exclude results from specific domains
results = tool.invoke({
"query": "Python tutorial",
"exclude_domains": ["youtube.com", "reddit.com"],
})
In a LangChain Agent
create_agent comes from the langchain package (1.0 or newer): pip install langchain.
llm is any LangChain chat model, for example ChatOpenAI(...) from langchain-openai.
from langchain.agents import create_agent
from langchain_octen import OctenSearchResults
tool = OctenSearchResults(max_results=5)
agent = create_agent(model=llm, tools=[tool])
response = agent.invoke({"messages": [{"role": "user", "content": "What happened in AI today?"}]})
Async Support
import asyncio
from langchain_octen import OctenSearchResults
tool = OctenSearchResults(max_results=3)
async def main():
results = await tool.ainvoke({"query": "Python 3.13 new features"})
print(results)
asyncio.run(main())
Advanced Options
from langchain_octen import OctenSearchResults
# Time-filtered search
tool = OctenSearchResults(
max_results=5,
time_basis="published",
start_time="2025-01-01",
end_time="2026-03-30",
)
results = tool.invoke({"query": "Python release notes"})
# Search with highlighted snippets
tool = OctenSearchResults(
max_results=5,
highlight_enabled=True,
highlight_max_tokens=200,
)
results = tool.invoke({"query": "LangChain tutorial"})
# Search with full page content
tool = OctenSearchResults(
max_results=3,
full_content_enabled=True,
full_content_max_tokens=1000,
)
results = tool.invoke({"query": "Python documentation"})
# Return only relevant results, up to max_results
tool = OctenSearchResults(max_results=5, result_type="dynamic")
results = tool.invoke({"query": "Python 3.13 free-threaded build"})
Result type
result_type is set by you when the tool is created and applies to every call; the model
cannot see or change it. "standard" returns results as the options you set specify;
"dynamic" returns only relevant results, up to max_results, and adjusts highlight length
per result (with "dynamic", highlight_max_tokens may be adjusted per result). Left
unset, nothing is sent and the server default ("standard") applies. Any other value is
rejected when the tool is created. OctenBroadSearch and OctenSearchPremier take the same
option.
Vertical search tools
OctenSearchPremier, OctenBroadSearch, OctenNewsSearch, OctenBusinessSearch,
OctenPulseSearch and OctenPlaceSearch share one design:
-
The model only controls the query and search filters; you control the billing-related options and limits (result counts, highlight / full content, Broad
max_queries, ...) when you construct the tool. Options you leave unset are not sent, so the server defaults apply. Broad Search is billed per sub-query:max_queriesis an upper bound, and how many sub-queries a question actually produces depends on the query. -
Every call returns a dict:
{ "data": {...}, # the response's data, unchanged (results, places, entities, ...) "request_id": "...", # quote it when contacting support "warning": "...", # only present when the API attached a non-empty warning }
-
Errors are split by who can fix them.
- Raised to your code: authentication failure (
octen.OctenAuthenticationError, 401), no access or insufficient balance (octen.OctenAPIErrorwith status 403) and other 4xx responses. Some agent runtimes catch exceptions raised by tools, so each of these is also logged at ERROR level to thelangchain_octenlogger. - Constructor options are checked when the tool is built: an out-of-range value
(
count=1000), a misspelt option name (max_querys=3) or atimeoutthat is not a positive finite number raisesValueErrornaming it. - Handed to the model as the tool result (a
ToolExceptionwithhandle_tool_error=True): rate limits (429), server errors (5xx), 400/408/422 responses, 2xx responses carrying an error envelope or a malformed body, timeouts and connection errors. For a timeout or connection error that may have happened after the request was sent, a 502 or 504 (a gateway can return these after the backend served the call), or a failed 2xx response, the message also tells the model the call may already have been billed and should not be retried automatically. - Invalid model arguments (an unknown
time_range, a misspelt argument name such asinclude_domain, half a coordinate pair, aradiuswithout a point, values out of range) are rejected before any request is made, and the model gets a message naming the argument.
- Raised to your code: authentication failure (
-
Every tool takes
octen_api_key(falls back toOCTEN_API_KEY; missing key raisesValueErrorat construction) andtimeout(seconds).
from langchain_octen import (
OctenBroadSearch,
OctenBusinessSearch,
OctenNewsSearch,
OctenPlaceSearch,
OctenPulseSearch,
)
from langchain.agents import create_agent
tools = [
OctenNewsSearch(count=5),
OctenBusinessSearch(entities={"count": 2}),
OctenPlaceSearch(places={"count": 5}),
]
agent = create_agent(model=llm, tools=tools)
Web Search Premier (OctenSearchPremier)
Web search with deeper retrieval and reranking, for questions that need the exact page
holding the answer: a specific fact, a detail deep inside a page, a niche document or a
named report. Same request options and response shape as Web Search (data.query,
data.results). For low-latency lookups use OctenSearchResults instead.
The model gets the same arguments as octen_search; everything else is yours.
| Model arguments | Constructor options |
|---|---|
query, include_domains, exclude_domains |
count (1-100), result_type ("standard" or "dynamic"), highlight, full_content (only the enable and max_tokens keys), include_text, exclude_text (up to 5, 30 characters each), language (ISO 639-1 codes), time_basis, time_range, start_time, end_time (RFC 3339, e.g. 2025-01-01T00:00:00Z), format, safesearch, include_images, timeout |
result_type="dynamic" returns only relevant results, up to count, and adjusts the
highlight length per result. Unlike OctenSearchResults, the constructor takes no
include_domains / exclude_domains: those are the model's.
tool = OctenSearchPremier(count=5, highlight={"enable": True, "max_tokens": 1024})
result = tool.invoke({"query": "Kafka default retention period for topics"})
for r in result["data"]["results"]:
print(r["title"], r["url"])
Broad Search (OctenBroadSearch)
Expands one question into several sub-queries, searches them concurrently, and returns the
results grouped per sub-query (data.queries, data.search_results; not deduplicated).
| Model arguments | Constructor options |
|---|---|
query, include_domains, exclude_domains, time_range, language |
count (per sub-query, 1-100), result_type ("standard" or "dynamic"), max_queries (1-30), highlight, full_content, timeout |
result_type applies to every sub-query. "standard" (the default) returns results as the
options you set specify. With "dynamic" only relevant results come back, so count is a
maximum (a sub-query can return fewer, possibly none), and Octen may adjust the highlight
length per result: highlight["max_tokens"] is a cap.
tool = OctenBroadSearch(max_queries=5, count=3)
result = tool.invoke({"query": "compare managed Postgres providers on price and limits"})
for group in result["data"]["search_results"]:
print(group["query"], len(group["results"]))
News Search (OctenNewsSearch)
Recent articles plus data.subjects: storylines with a summary and the time span they cover.
Domain filters narrow the ranked articles only, not the storylines.
| Model arguments | Constructor options |
|---|---|
query, include_domains, exclude_domains, time_range, language |
count (1-100), subjects (e.g. {"enable": True, "count": 2, "max_sub_news": 5}), highlight, full_content, timeout |
tool = OctenNewsSearch(count=5)
result = tool.invoke({"query": "EU AI Act enforcement", "time_range": "week"})
for storyline in result["data"].get("subjects", []):
print(storyline["name"], storyline.get("summary"))
Business Search (OctenBusinessSearch)
Company and person cards in data.entities (profile, financial and stock metrics, key
people, career history, recent announcements) plus the ranked sources in data.results.
The domain, time and language filters narrow the ranked sources only, never the cards.
| Model arguments | Constructor options |
|---|---|
query, include_domains, exclude_domains, time_range, language |
count (1-100), entities (e.g. {"count": 2, "max_news": 5}), highlight, full_content, timeout |
tool = OctenBusinessSearch(entities={"count": 2})
result = tool.invoke({"query": "compare Stripe and Adyen"})
for entity in result["data"].get("entities", []):
print(entity["name"])
Pulse Search (OctenPulseSearch)
Predicts the URL a query most likely means, in about 10ms: official docs, API references,
help centres, sites you could almost name. It takes no filters and sees no fresh content.
In lite mode (the server default) URLs come back without a scheme, e.g. github.com/docs.
| Model arguments | Constructor options |
|---|---|
query |
count (1-10), mode ("lite" or "standard"), highlight, full_content (both only in standard), timeout |
tool = OctenPulseSearch(count=3)
result = tool.invoke({"query": "uv documentation"})
print([r["url"] for r in result["data"]["results"]])
Place Search (OctenPlaceSearch)
Real-world places as cards in data.places: name, category, address, coordinates, phone,
website, opening hours, status, rating and review count. With latitude and longitude each
card carries its distance in metres. When the place engine does not answer in time the
result carries "warning": "places_unavailable".
| Model arguments | Constructor options |
|---|---|
query, latitude + longitude (both or neither), radius (1-50000 m, needs a point), user_location (city, region, country, timezone) |
places (e.g. {"count": 5, "max_reviews": 0}), web_search (e.g. {"enable": True, "count": 3}; off by default), timeout |
tool = OctenPlaceSearch(places={"count": 5})
result = tool.invoke(
{"query": "coffee shops", "latitude": 35.6812, "longitude": 139.7671, "radius": 1000}
)
for place in result["data"].get("places", []):
print(place["name"], place.get("distance"))
The tool sets user_location.type to "approximate" itself.
Extract (OctenExtract)
Reads web pages by URL and returns their clean content (markdown by default). The model
passes the URLs and, only when it wants excerpts about one topic, a query: each result
then carries ranked highlights instead of full_content. It returns the same dict and
splits errors the same way as the vertical search tools above.
| Model arguments | Constructor options |
|---|---|
urls, query (max 500 characters) |
max_urls (1-20, default 5), mode ("standard", "advanced" or "auto"), format ("markdown" or "text"), max_age_seconds (300-31536000), url_timeout (1-60), include_images, include_videos, include_audio, include_links (e.g. {"scope": "prefer_external", "max_links": 50}; {} for the server defaults), timeout |
max_urlscaps each call. A call with more URLs is refused without a request, and the model is told how many it sent and to split them into several calls. The tool description tells the model the cap. Each URL must be 1-2048 characters.- Failures are reported per URL.
data.resultsholds the per-URL items; match them to your inputs by each item'surl, not by position.statusis"success"(withtitle,full_contentorhighlights,time_published/time_last_crawledwhen known,category,page_structure, and media or links only if you enabled them) or"failed"with anerror_message. Failed URLs are not billed; the server then attaches awarningsuch as"1 URL(s) failed and were not billed". Content is not truncated. - Billing.
resolved_modeon each successful item is the mode it was billed at (autopicks per URL;advancedis priced higher). The aggregate usage counts in the response'smetaare not part of the tool result. - Two timeouts.
url_timeoutis the server-side limit per URL (the API'stimeout, server default 30).timeoutis the HTTP request timeout octen applies to each attempt (passed as itsrequest_timeout); left unset it isurl_timeout(or 30) plus 90 seconds. It is not a deadline for the whole call: octen still retries 408, 429, 500, 502, 503 and 504 responses (see Retries), so a call can take longer across attempts. If you set it, keep it aboveurl_timeout.
from langchain_octen import OctenExtract
tool = OctenExtract(max_urls=3)
result = tool.invoke({"urls": ["https://example.com/", "https://docs.octen.ai/"]})
for item in result["data"]["results"]:
if item["status"] == "success":
print(item["url"], item.get("title"), len(item.get("full_content") or ""))
else:
print(item["url"], "failed:", item.get("error_message"))
Image Search (OctenImageSearch)
Finds images on the web from a text description or from a reference image. It returns the same dict and splits errors the same way as the vertical search tools above.
| Model arguments | Constructor options |
|---|---|
exactly one of query (max 500 characters) or image_url (a public https image URL with a domain name); include_domains, exclude_domains (up to 10 each, matched against each result's source page) |
count (1-10, server default 5), safesearch ("off" or "strict", server default strict), timeout |
- One input per call. A call with both
queryandimage_url, or with neither, is refused without a request and the model is told which to pass. The model can only pass an image by URL: base64 data anddata:URIs are refused. To search with image bytes, callocten.Octen().image_search.search(inputs=[{"type": "image", "data": ...}])directly. Animage_urlmust be an https URL with a domain name (the API refuseshttpand IP-address hosts), a valid port and no ASCII spaces or control characters, sohttp://example.com/a.png,https://1.2.3.4/a.pngandhttps://:443/photo.pngare refused too; a blankqueryis refused as well. - Image URLs stay out of this package's logs and error messages. A raised error is
logged with its type, the input kind (
image URLortext query) and the request id, not the URL or query, since a signed URL can carry a token. For animage_urlcall, an error handed to the model is a fixed message (error type, status, request id and, by cause: try another image for a rejected image, "temporarily unavailable" for a transient failure, or only the billing warning when the call may have been billed) with no upstream text, and an error raised to your code keeps its class, status and request id but not the upstream message, body or cause (an exception that is not anoctenerror is raised as a plainocten.OctenError). LangChain's input tracing and callbacks record the raw tool arguments,image_urlincluded, before the tool runs: if the model may pass signed URLs, disable or redact input tracing for this tool. - A rejected image goes back to the model. Unlike the other 4xx responses, 413 (image too large) and 415 (unsupported format) are returned to the model with a hint to try a smaller image, a supported format or another image URL. Authentication, access and balance errors are still raised.
- Results.
datais the response's data unchanged:data.resultsholds each image'stitle,url,source_page,description,width,heightandthumbnail. The response'smeta(usage, latency) is not part of the tool result; a non-emptymeta.warningis returned aswarning.
from langchain_octen import OctenImageSearch
tool = OctenImageSearch(count=5)
result = tool.invoke({"query": "golden gate bridge at night"})
for image in result["data"]["results"]:
print(image["url"], image.get("source_page"))
similar = tool.invoke({"image_url": "https://example.com/photo.jpg"})
Design Search (OctenDesignSearch)
Finds design references for building or restyling a user interface or a slide deck. Each
image result is a screenshot of a web page, a page section, an app screen or a slide (type)
with its url, thumbnail, title, description and source_page (not for app screens),
plus design_facts (colors, fonts, font sizes and the like) and reusable HTML in snippet
when they are returned. Web results on the same query come back alongside in
data.results. data is the response's data unchanged.
| Model arguments | Constructor options |
|---|---|
query (max 500 characters), group_id (at least one of the two) |
images (enable, count 1-100, design_facts, snippet: {"enable", "max_tokens"}), web_search (enable, count 1-100, highlight, full_content (only the enable and max_tokens keys), include_domains, exclude_domains, language (ISO 639-1 codes), time_basis, time_range, start_time, end_time (RFC 3339)), timeout |
-
Follow-up by group. Sections of one web page and slides of one deck carry a
group(group_id,type,name,position,total, and for decksmaster). The model passes thatgroup_idto get the first images of the group in group order instead of a search;querymay then be omitted. It gets at mostimages.countof them (5, the API default, when unset), not necessarily the whole group, and the tool description states that limit. A call with neither is refused without a request.group_idis the model's:images={"group_id": ...}raisesValueErrorat construction. Withimages={"enable": False}the model's input schema has only a requiredquery, the description offers no group lookup, and agroup_idis never forwarded. -
Large output by default. Left unset, the server defaults apply: 5 images, each with
design_factsand asnippetof up to 5000 tokens where the image has reusable code, plus 5 web results with highlights. That can be a lot of text for a model. Turn off or shorten what your agent does not need:To Pass drop the design values images={"design_facts": False}drop the HTML snippets images={"snippet": {"enable": False}}shorten the snippets images={"snippet": {"max_tokens": 1000}}(100-100000)return fewer images images={"count": 3}drop the web results web_search={"enable": False}A part you turned off is absent from
data, and the tool description stops offering it. Turning both off raisesValueErrorat construction, as does aweb_search.end_timebefore itsstart_time.
from langchain_octen import OctenDesignSearch
tool = OctenDesignSearch(
images={"count": 5, "snippet": {"max_tokens": 2000}},
web_search={"count": 3},
)
result = tool.invoke({"query": "pricing section for a SaaS landing page"})
for image in result["data"].get("images", []):
print(image["type"], image["url"], (image.get("group") or {}).get("group_id"))
deck = tool.invoke({"group_id": "<group.group_id of an earlier result>"})
Retries
The tools create their octen clients with retry_after_send=False: a request that times
out or loses its connection after it may already have reached the server is not retried,
because the first attempt may already have been served and billed. Failures known to happen
before sending are still retried, and so are 408, 429, 500, 502, 503 and 504 responses.
Those status-code retries can still be charged twice: a gateway may return 502 or 504 after
the backend has finished. If you also call the API with your own octen.Octen /
octen.AsyncOcten client, consider passing retry_after_send=False there too.
Configuration
Constructor options of OctenSearchResults:
| Parameter | Type | Default | Description |
|---|---|---|---|
octen_api_key |
str |
env OCTEN_API_KEY |
Octen API key |
max_results |
int |
5 |
Number of results (1-100) |
search_type |
str |
None |
Deprecated and ignored (emits FutureWarning); the API no longer accepts it |
include_domains |
list[str] |
None |
Restrict to these domains |
exclude_domains |
list[str] |
None |
Exclude these domains |
include_text |
list[str] |
None |
Text that must appear in results |
exclude_text |
list[str] |
None |
Text to exclude from results |
time_basis |
str |
None |
auto, published, or crawled |
start_time |
str |
None |
Start time (ISO 8601) |
end_time |
str |
None |
End time (ISO 8601) |
format |
str |
None |
text or markdown |
safesearch |
str |
None |
off or strict |
highlight_enabled |
bool |
None |
Return highlighted snippets |
highlight_max_tokens |
int |
None |
Max tokens for highlights |
full_content_enabled |
bool |
None |
Return full page content |
full_content_max_tokens |
int |
None |
Max tokens for full content |
timeout |
float |
None |
Request timeout in seconds |
Development
# Install dependencies
poetry install --with test,dev
# Run unit tests (no API key needed)
make test
# Run live tests against the API (billed; requires OCTEN_API_KEY, sets OCTEN_LIVE=1)
export OCTEN_API_KEY="your-api-key"
make integration_tests
# Run all tests with coverage
poetry run pytest tests/ --cov=langchain_octen --cov-report=term-missing
# Lint and format
make lint
make format
License
MIT
Metadata
Release files for langchain-octen 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langchain_octen-0.4.1.tar.gz | 38.9 kB | Without provenance | Details for langchain_octen-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_octen-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for langchain_octen-0.4.1-py3-none-any.whl |
Total release size: 76.6 kB
Release files / langchain_octen-0.4.1.tar.gz
| Download URL | langchain_octen-0.4.1.tar.gz |
|---|---|
| Size | 38.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b3b917b76dfe66096ea44ab2058012c105af7e2147fbf7ce6f136b18f7094b36
|
|
BLAKE2b-256 checksum How to use checksums |
1cca460e3f3f169200a69434c88007f87ad9f54b6bb0eef2a1dd97db5c0967b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / langchain_octen-0.4.1-py3-none-any.whl
| Download URL | langchain_octen-0.4.1-py3-none-any.whl |
|---|---|
| Size | 37.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3b9e50a53f46f3f582afdaa01e57a5bd3bae0462c35da7cb77eedadef7a5eb68
|
|
BLAKE2b-256 checksum How to use checksums |
96e679c9b2fac1f62386dc1f34a3fb76fb79ccb5514574e60a5a602c446c1364
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for langchain-octen 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.