Telem Python SDK
A typed Python client for the Telem search orchestration API. It wraps the backend's
interaction endpoint and reads back the server's normalized envelope — one result shape for
every provider — with both synchronous and asynchronous clients.
Full documentation, including quickstarts for every surface (SDK, MCP, OpenClaw, OpenCode,
Pi): docs.telem.ai (launching soon).
Installation
pip install telem-sdk
Requires Python 3.10+ (since 0.1.3 — 0.1.2 and earlier declare 3.12+, and pip
will not select them on 3.10 or 3.11). Working from a checkout instead? uv sync
— see CONTRIBUTING.md.
Quickstart
from telem import Telem
client = Telem # reads TELEM_API_KEY and TELEM_BASE_URL from the environment
results = client.search("best python http client").results
for r in results:
print(r.title, r.url)
Configuration
The client is credential-agnostic and resolves configuration from arguments, then the
environment, then — for credentials only — ~/.telem/credentials.json, then defaults:
| Setting |
Argument |
Env var |
Default |
| API key |
api_key |
TELEM_API_KEY |
~/.telem/credentials.json, else none (anonymous) |
| Base URL |
base_url |
TELEM_BASE_URL |
~/.telem/credentials.json, else https://router.telem.ai |
| Result tier |
default_tier |
TELEM_TIER |
the server's (default) |
| Explicit fields |
default_fields |
TELEM_FIELDS (csv) |
unset (the tier decides) |
| Provider allow-list |
default_providers_include |
TELEM_PROVIDERS_INCLUDE (csv) |
the deployment's set |
| Provider deny-list |
default_providers_exclude |
TELEM_PROVIDERS_EXCLUDE (csv) |
unset |
| Full page content |
default_include_full_content |
TELEM_FULL_CONTENT (1 only) |
off |
| Fetch providers |
none (fetch(providers=…)) |
TELEM_FETCH_PROVIDERS (csv) |
the server's chain |
| Fetch tier |
none (fetch(tier=…)) |
TELEM_FETCH_TIER |
the server's |
| Skip the fetch cache |
none (fetch(no_cache=…)) |
TELEM_FETCH_NO_CACHE (1 only) |
off |
When an API key is set, requests carry an Authorization: Bearer <key> header. Anonymous
access works for most endpoints locally; sessions.list requires a token.
~/.telem/credentials.json is the machine-written credentials file ({"apiKey": "tlm_…", "baseUrl": "https://…"}) that the guided installer writes, so an installed user never has
to export anything. It supplies each of the two values only when that value is still
unresolved, and it is opened only when at least one of them is — so a client given both
its key and its base URL by argument or env var never touches the disk. A missing or
malformed file simply supplies nothing, and nothing is printed. TELEM_CONFIG_DIR
relocates the directory. It is the SDK's only config file — repo-local
.telem/telem.json search options, which the Telem plugins do read, are
deliberately never read here: a library must not let a checked-out repository steer an
arbitrary program's spend.
Every search default resolves as call argument → constructor argument → env var →
unset. A csv env var is split on commas with items stripped and empties dropped, so an
all-empty value reads as unset: only a constructor argument can express an explicit empty
list (default_fields=[], a deliberate "send nothing" the server rejects). TELEM_TIER
and TELEM_FULL_CONTENT follow the same rule — TELEM_FULL_CONTENT enables full content
for exactly the value 1. TELEM_PROVIDERS is NOT read by the SDK: it belongs to the
the Telem plugins, where it survives as a
deprecated alias of the provider allow-list, ranked below TELEM_PROVIDERS_INCLUDE
and below both config files. Export TELEM_PROVIDERS_INCLUDE everywhere.
The three fetch defaults have no constructor argument: each resolves as fetch
argument → env var → unset, with the same csv and 1-only rules, and TELEM_FETCH_TIER
is trimmed and lowercased. no_cache=False in a call overrides TELEM_FETCH_NO_CACHE=1.
To use the fetch keys in the Telem config files as well, pass
**telem.resolve_fetch_options(project_root=...).fetch_kwargs to fetch.
num_results, include_raw and provider_overrides are deliberately call-level only:
per-call intent, an audit knob and a surgical escape hatch respectively.
client = Telem(api_key="tlm_...", base_url="https://router.telem.ai", default_tier="extended")
The request timeout defaults to 60 s (the server grants provider timeouts that long at
the max tier and with full content); pass timeout= to change it. A read (GET) is sent
again after a 5xx, a 429 or a lost connection, twice by default; pass max_retries= to
change it (0 turns it off). Writes, such as a search, are sent once.
Search
search performs a single round trip — one Search operation — and returns the server's
normalized envelope for every provider that ran — every provider's rows come back in
one shape, whatever its own API looks like:
resp = client.search(
"climate policy 2026",
tier="extended", # minimalist | default | extended | max
providers_include=["exa"], # omit to use the deployment's default provider set
num_results=10, # rows PER PROVIDER (server default 5, range 1.20)
include_raw=True, # also attach each provider's own response body
goal="brief the user", # merged into request metadata
context="follow-up query", # merged into request metadata
)
resp.results # flattened list[SearchResult]: providers in run order, rows in envelope order
resp.by_provider # list[ProviderRun] — the primary surface; keeps partial failures
resp.session_id # continue the conversation by passing session=resp.session_id
resp.status # "succeeded" | "partially_succeeded" | "failed"
resp.normalized_schema_version # the contract the server answered with
The full option set is tier, fields, providers_include, providers_exclude,
provider_overrides, num_results, include_raw, include_full_content, plus
goal/context/session/metadata. None means unset (fall through to the client
default, then to the server's own default); [], {}, False and True are all
explicit values and are sent verbatim. Nothing is pre-validated client-side — tier names,
field names and the num_results bounds are the server's call and come back as
BadRequestError.
Two options compose rather than stack: a fields list replaces any tier (the level
that set it wins, and fields wins a tie), and when both provider halves are set the
excluded names are subtracted from the allow-list, which then fully determines the set.
provider_overrides is the per-provider escape hatch: raw parameters merged into ONE
provider's request body, keyed by provider name and written in that provider's own
vocabulary, not the SDK's:
resp = client.search("climate policy 2026", provider_overrides={"exa": {"numResults": 2}})
An overridden provider gets its raw payload attached automatically, so you can see what
the override actually did.
Each SearchResult exposes url, title, summary, excerpt, full_content,
publish_date, rank, thumbnail, favicon, source (an object: domain/name/
author), enrichments, fetch_meta, plus provider and raw (the verbatim envelope
row). result.content survives as a legacy alias — summary, else
full_content["content"], else "" — as a property, not a stored field: it never appears
in model_dump.
Providers
for p in client.providers:
print(p.name, p.active_by_default, p.normalized, p.tiers)
normalized marks the providers that return the V2 envelope (they are the ones a search
can select), and tiers lists the tier names each of them serves.
Sessions
client.sessions.list # list[SessionSummary] (requires an API key)
client.sessions.history(session_id) # short history
client.sessions.history(session_id, full=True) # detailed history
client.sessions.results(session_id) # aggregated websearch preprocessor results
Monitors
A monitor runs a query on a schedule, and its agent checks every result against the
query and keeps the ones that match. A monitor has the agent unless you create it with
agent=False, and a monitor with the agent needs a ttl, at most "30d": without one,
create raises ValueError.
monitor = client.monitors.create("Nvidia files a new 8-K with the SEC", frequency="1h", ttl="30d")
print(monitor.agent_state.status if monitor.agent_state else "no agent")
for change in client.monitors.iter_changes(monitor.id):
print(change.seq, change.kind, change.subject.name)
agent = client.monitors.agent(monitor.id)
client.monitors.update(monitor.id, status="paused")
client.monitors.update(monitor.id, ttl="30d") # renew: it ends 30 days from now
client.monitors.delete(monitor.id)
iter_changes reads what the agent kept, oldest first, until you are caught up, and
then stops. Keep the seq of the last change you handled and pass it as cursor next
time: no change comes twice, and none is skipped. changes returns one page
(next_cursor, watermark) and takes cursor, since, kinds and limit. agent
returns the agent itself, and monitor.agent_state shows it on the monitor; when the
agent did not start, the create's monitor.agent_note says why. With AsyncTelem, read
iter_changes with async for.
create sends an Idempotency-Key header, a new one per call unless you pass
idempotency_key. It retries a 429, a 409 idempotency_in_progress, a timeout and a
lost connection for up to about 2 minutes, with the same key. For 24 hours, a retry
with the same key returns the first monitor instead of creating a second one. A
different API key makes a new monitor.
create_many takes a list of dicts of create's arguments and returns one
MonitorBatchResult per monitor, in your order: its status, and its monitor or its
error, and its idempotency_key. It sends them in calls of 10, gives each its own key
(or yours, as idempotency_key), and sends again only the monitors answered with a 429
or a 409 idempotency_in_progress (still being made). A call that fails whole raises
with results (each monitor's last answer so far) and idempotency_keys (every key), and
says the monitors may exist: send the monitors without a final 201 or 200 again with
the same keys.
results = client.monitors.create_many([
{"query": "Nvidia files a new 8-K with the SEC", "ttl": "30d"},
{"query": "AMD files a new 8-K with the SEC", "ttl": "30d", "frequency": "1h"},
])
for result in results: # one per monitor, in your order
print(result.index, result.status, result.monitor.id if result.monitor else result.error)
client.monitors also has get and list. poll is deprecated and warns once:
read the agent's changes with iter_changes instead.
See Monitors for the fields, the errors and
the older reads.
LangChain and LangGraph integration
Install the optional integration to create a native LangChain tool:
pip install "telem-sdk[langchain]"
from telem import Telem
from telem.integrations.langchain import create_telem_search_tool
client = Telem
telem_search = create_telem_search_tool(
client,
providers_include=["exa"],
num_results=5)
Only query is exposed in the model's tool schema. Search policy — tier, providers,
result count, metadata, and the other search options — is fixed by application code
when the tool is created. The tool returns compact text to the model and keeps the full
typed SearchResponse in ToolMessage.artifact for application code.
LangChain agent
Install langchain and the package for your model provider. The current create_agent
runtime uses LangGraph internally and accepts the Telem tool directly:
from langchain.agents import create_agent
from langchain_openai import ChatOpenAI
agent = create_agent(ChatOpenAI(model="gpt-5.4-mini"), tools=[telem_search])
result = agent.invoke(
{"messages": [{"role": "user", "content": "What changed today?"}]},
config={"configurable": {"thread_id": "application-conversation-42"}})
LangGraph ToolNode
Applications using the lower-level graph API can pass the same tool to ToolNode; there
is no separate LangGraph implementation:
from langgraph.prebuilt import ToolNode
tool_node = ToolNode([telem_search])
Pass an AsyncTelem client to create an async-only tool and run the graph with ainvoke.
Telem's typed API errors propagate to LangGraph, whose ToolNode error policy can handle
them normally.
Agent integration (OpenAI wrap)
client.wrap patches an OpenAI client in place (exa-style — the same object is
returned) so the model can call Telem search as a telem_search tool. One wrapped
client = one agent conversation = one Telem session; the wrap sends query lineage so
searches from one conversation stay grouped. Requires the extra:
pip install telem-sdk[openai].
from openai import OpenAI
from telem import Telem
client = Telem
wrapped = client.wrap(OpenAI) # patched in place; same object returned
r = wrapped.chat.completions.create(model="gpt-4o", messages=msgs)
r.telem_responses # list[SearchResponse]; empty if no search ran
wrapped.telem_conversation_id # this agent's conversation identity
wrapped.telem_session_id # the backend session, adopted from the first search
wrapped.telem_messages # recorded conversation snapshot
By default the request's tools are replaced with the telem_search tool (caller
tools are dropped, exa parity) and search rounds complete inside create. Agents
with their own tools switch to loop integration:
run_tool = wrapped.wrap_tool_runner(run_my_tool) # merges tools; create stops auto-completing
r = wrapped.chat.completions.create(model="gpt-4o", messages=msgs, tools=my_tools)
if r.choices[0].message.tool_calls:
msgs.append(r.choices[0].message) # the assistant message that made the tool calls
for tc in r.choices[0].message.tool_calls:
msgs.append(run_tool(tc)) # telem_search handled by the SDK, others by run_my_tool
Pass use_telem="none" on a call to skip Telem for that call. AsyncTelem.wrap
mirrors this for AsyncOpenAI; the async runner accepts sync or async tool functions.
Wrap the subagent at the moment you delegate, passing the parent wrapped client.
The wrap freezes the parent's conversation right then and carries it as the child's
newest ancestor:
root = client.wrap(OpenAI, goal="answer the user task")
root.chat.completions.create(model="gpt-4o", messages=root_msgs)
# Inside the parent's tool handler, when it decides to spawn a researcher:
subagent = client.wrap(OpenAI, parent=root, conversation_id="research-1")
subagent.chat.completions.create(model="gpt-4o", messages=subagent_msgs)
Every search the subagent runs then carries its lineage back to the parent, so parent
and child stitch into one graph. Nested subagents work the same way by passing the
spawning subagent as parent.