Skip to main content
The official SDKs give you web search and page fetch in Python, TypeScript and Go, with results already shaped for a prompt.

What you get

  • search returns ranked pages with their text extracted. fetch returns one page as markdown.
  • to_context() renders results as numbered [n] Title (url) sources a model can cite.
  • TOOLS holds OpenAI-format definitions for keenable_search and keenable_fetch. A helper runs whichever tool the model calls. See Tool calling.
  • In Python, AsyncKeenable has 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:
The Python SDK needs Python 3.9 or newer. The TypeScript SDK needs Node 18 or newer. The Go SDK needs Go 1.22 or newer. The TypeScript and Go SDKs have no runtime dependencies. Keenable has no official SDK for other languages, such as Java, Ruby, PHP, C# or Rust. Call the HTTP API from those languages: see the API reference. On macOS and many Linux distributions, system Python refuses a global 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. This program runs one search without a key and prints the top 3 results as a citable block:
Save it in the directory where you installed the SDK and run it: You see one [n] Title (url) header per result, followed by the page text:
Example output · results vary
To raise your limit, create an API key and set 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, mode accepts only pro.
  • No SDK sends disable_cards or session_id.
  • fetch takes only a URL. For live, prompt and max_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, use AsyncKeenable 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
You see one line per result:
Example output · results vary
The 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.

Source, packages and changelogs