What you get
searchreturns ranked pages with their text extracted.fetchreturns one page as markdown.to_context()renders results as numbered[n] Title (url)sources a model can cite.TOOLSholds OpenAI-format definitions forkeenable_searchandkeenable_fetch. A helper runs whichever tool the model calls. See Tool calling.- In Python,
AsyncKeenablehas the same methods as the sync client. See Async. - Every call works with no account and no key. An API key raises your rate limit.
Install
Install the package for your language:pip install. Install the Python package into a virtual environment: run python3 -m venv .venv, then source .venv/bin/activate. If your Go project already has a go.mod, skip go mod init.
Run a keyless search
This program runs one search without a key and prints the top 3 results as a citable block:
You see one
[n] Title (url) header per result, followed by the page text:
Example output · results vary
KEENABLE_API_KEY. The code stays the same.
Configuration
Every SDK reads two environment variables:
You can also pass settings to the constructor:
The SDK sends the client source as the
X-Keenable-Title header. It defaults to Keenable SDK. If you build an integration on top of an SDK, set it to your product’s name so Keenable attributes your traffic to your product.
Methods
Search filters follow the Search parameters, in each language’s naming style:
published_after in Python, publishedAfter in TypeScript, PublishedAfter in Go. The list of hosts to leave out is exclude_domains in Python, excludeDomains in TypeScript and ExcludeDomains in Go; see Exclude domains. SDK 0.1.x has three gaps:
- In Python and TypeScript,
modeaccepts onlypro. - No SDK sends
disable_cardsorsession_id. fetchtakes only a URL. Forlive,promptandmax_chars, call the HTTP API as shown on Fetch.
Context size
to_context() keeps a prompt small. It collapses the whitespace in each result’s text and adds whole results in rank order. When a result would take the block past 12,000 characters, to_context() leaves out that result and every result after it, so the block never ends in the middle of a result. The first result is always kept, even if it is longer than the limit on its own.
cited() returns the results that to_context() kept, in the same order. Index 0 is the source the model cites as [1].
Set the limits per call:
The limits apply only to the rendered block. Each result’s
snippet keeps the full text. To get shorter text for each result, pass snippet_max_length to search, from 180 to 10000 characters.
On a fetched page, to_context() takes only the character limit and cuts the page content at it.
Async
In Python, useAsyncKeenable when your code already runs on asyncio. It takes the same constructor settings as Keenable, and you await its search and fetch. If you pass your own HTTP client, pass an httpx.AsyncClient.
This program opens the client with async with, awaits one keyless search and prints each result’s title and URL:
Python
Example output · results vary
async with block closes the connection pool when it ends. If you create the client without async with, call await client.aclose() when you finish.
To run several searches at once with a cap on how many are in flight, see Split a broad question into parallel searches.
TypeScript and Go have one client each. In TypeScript, search and fetch return promises. In Go, Search and Fetch take a context.Context as their first argument.
Errors
Every SDK raises typed errors that share one base class. See Errors for what each status code means and how to fix it.
When the API rejects an
exclude_domains entry, the API error carries param (exclude_domains), value (the rejected entry, or the list size for a size limit) and reason. They are value and reason in Python and TypeScript, and Value and Reason on an APIError in Go. Both are unset on every other error.
In 0.1.x, an HTTP 402 (out of credits) raises the generic API error. To catch it, check status_code == 402 in Python, statusCode === 402 in TypeScript, or StatusCode == 402 on an APIError in Go.