Initialization
Configuration Options
Closing the client
The client holds a gRPC channel open. Callclient.close() when you’re done, or use the client as a context manager so it closes for you. Requires seltz v1.4.0 or later.
Methods
search
client.search runs a search query and returns the matching documents.
Returns:
SearchResponse
Timeout: 30 seconds
Filter examples:
answer
Preview.
/answer is grounded in the web scope by default, which is in beta. Pass scope to ground elsewhere — for example, news for current-events questions.client.answer generates a direct, natural-language answer to a question, grounded in live web search results, with citations to the sources used.
Returns:
AnswerResponse
Answer tiers:
An omitted or unrecognized
model falls back to seltz-base; the response shape is unchanged.
response_format — an OpenAI-style object — to get structured output. response.answer then carries a JSON string matching your schema instead of Markdown, and inline citations no longer appear in the answer text; response.citations is returned either way. A malformed response_format is rejected before the request is billed, raised as SeltzAPIError.
system_prompt to steer how the answer is presented — tone, voice, format.
answer_stream
client.answer_stream streams an answer as the model generates it, instead of waiting for the whole thing. It takes the same parameters as answer. Requires seltz v1.5.0 or later.
The stream yields AnswerStreamResponse events, and each event holds exactly one member. The first event holds citations, the next events hold text_delta chunks of the answer, and the final event holds a finish_reason. Call event.WhichOneof("event") to see which member an event holds.
Iterator[AnswerStreamResponse]
Calling A stream also has no per-call deadline.
answer_stream doesn’t send the request. The request goes out when you start iterating, so errors are raised inside the for loop, not at the call. Wrap the whole loop in your try:answer gives up after 30 seconds, but answer_stream keeps going until the answer finishes.fetch
client.fetch retrieves the content of up to 20 URLs you already have and returns each page as Markdown. Requires seltz v1.12.0 or later.
status set to FetchStatus.FETCH_STATUS_ERROR and an error.code, so check each result before you read it.
Returns: FetchResponse, with one FetchResult per requested URL.
See the Fetch reference for the parameters (urls, formats, tier, timeout_ms), the result fields, and the per-URL error codes.
agent
client.agent runs multi-step research over the web and returns a cited report. Requires seltz v1.12.0 or later.
Runs are asynchronous. create returns the run in pending state, and create_and_wait starts a run and blocks until it reaches a terminal state.
create, get, list, cancel, wait, and create_and_wait. See SDK methods for what each returns.
Check run.status and run.stop_reason before you rely on the output: a run can end failed. See the Agent reference for the request fields, the run envelope, and what each status and stop reason means.
monitor
client.monitor manages monitors, which run a set of saved searches on a schedule and deliver each new document once. Requires seltz v1.10.0 or later.
create, get, list, update, delete, list_runs, get_run, list_run_requests, list_records, list_run_records, and stream_records. Each returns the whole response message, so read response.monitor rather than expecting the monitor itself. See SDK methods for what each returns, the rest of the Monitor reference for paging, cadence, limits, and errors, and Webhooks to be told when a run finishes.
Async Client
AsyncSeltz is the asyncio version of Seltz. It takes the same configuration options and has the same methods and namespaces, and you await each call. Requires seltz v1.4.0 or later. Its answer_stream, fetch, agent, and monitor members need the same versions as their Seltz counterparts.
Seltz:
answer_streamandclient.monitor.stream_recordsreturn async iterators. Read them withasync for.close()is a coroutine. Callawait client.close(), or useasync withas shown above.
Response Objects
SearchResponse
Contains the search results.Document
Represents a single search result.AnswerResponse
Contains the generated answer and its citations.Citation
Represents a single source cited by an answer.AnswerStreamResponse
One event fromanswer_stream. Each event sets exactly one member of its event oneof.
Exception Types
All exceptions inherit fromSeltzError.
Exception Handling
This example constructs the client outside thetry, so a missing SELTZ_API_KEY raises SeltzConfigurationError at startup rather than per query. The handler covers only the errors search() can raise.
gRPC Details
The SDK communicates with Seltz via gRPC. The client is configured with optimized keepalive settings for stable connections:Public Exports
Theseltz package exports the client, its response types, and its exceptions. These are the names you use most; seltz.__all__ lists every one.