> ## Documentation Index
> Fetch the complete documentation index at: https://docs.keenable.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Every page is listed in https://docs.keenable.ai/llms.txt. To pick a product for a job, read https://docs.keenable.ai/choose.md
> Setup steps for agents, covering the SDKs, the MCP server and the CLI: https://docs.keenable.ai/skill.md
> Keenable search and fetch work without an API key. To add them to code, use the official SDK for the project's language: https://docs.keenable.ai/sdks.md
> Without a key, call POST https://api.keenable.ai/v1/search/public or GET https://api.keenable.ai/v1/fetch/public with an X-Keenable-Title header that names your app.
> With a key, send it in the X-API-Key header and read it from the KEENABLE_API_KEY environment variable. Never ask a user to paste a key into chat. Every access method: https://docs.keenable.ai/auth.md
> To get an API key without the console, use device login: https://docs.keenable.ai/authentication.md#device-login
> MCP server: https://api.keenable.ai/mcp (no key, or X-API-Key; keyless Codex uses https://api.keenable.ai/mcp-public), or https://api.keenable.ai/mcp-oauth for OAuth sign-in. These docs are an MCP server at https://docs.keenable.ai/mcp and the OpenAPI spec is at https://docs.keenable.ai/api-reference/openapi.json
> Keenable searches and fetches public web pages. If a question needs no web information, skip the call.
> On 402 with an API key (code insufficient_credits), stop and ask a human to add credits; don't retry. On 429, wait the number of seconds in Retry-After, then retry. Before you ship, follow https://docs.keenable.ai/production.md
> Every error, with its cause and fix, is in https://docs.keenable.ai/errors.md and moving from another search API is covered in https://docs.keenable.ai/migrate.md
> Before you compare Keenable with another search API, read https://docs.keenable.ai/guides/evaluate-search-apis.md

# Web search tools for OpenRouter models

> Web search and page fetch for any OpenRouter model, as tools it calls itself: from Python, the AI SDK, or the Agent SDK over MCP. No Keenable key needed.

*Tools for any OpenRouter model*

Give any OpenRouter model web search and page fetch as tools. The model decides when to search, your code runs the call, and each result comes back with the page text already extracted. You don't need a Keenable key to start, so each example below runs with only an OpenRouter key.

| Stack | Packages | The model sees |
| - | - | - |
| [Python](#python) | `keenable` with the OpenAI SDK | `keenable_search`, `keenable_fetch` |
| [TypeScript, AI SDK](#typescript-ai-sdk) | `@keenable/ai-sdk` with `@openrouter/ai-sdk-provider` | `keenable_search`, `keenable_fetch` |
| [OpenRouter Agent SDK](#openrouter-agent-sdk-mcp) | `@openrouter/mcp` with the [Keenable MCP server](https://docs.keenable.ai/mcp-server.md) | `search_web_pages`, `fetch_page_content` |

The examples use `deepseek/deepseek-v4.1-flash`. Any OpenRouter model that supports tool calling works. Set `OPENROUTER_API_KEY` first.

## Python

```bash theme={"theme":{"light":"github-light-high-contrast","dark":"dark-plus"}}
pip install keenable openai
```

This loop sends the question, runs each tool call the model makes, and prints the answer once the model stops calling tools:

```python theme={"theme":{"light":"github-light-high-contrast","dark":"dark-plus"}}
import os

from keenable import Keenable, KeenableError, TOOLS, run_tool_call
from openai import OpenAI

openrouter = OpenAI(
    base_url="https://openrouter.ai/api/v1",
    api_key=os.environ["OPENROUTER_API_KEY"],
)
keenable = Keenable()  # reads KEENABLE_API_KEY if set, works without it

messages = [
    {
        "role": "system",
        "content": "Use the web tools when the answer depends on recent information, and cite the URLs you used.",
    },
    {"role": "user", "content": "What changed in the latest Python release?"},
]

while True:
    completion = openrouter.chat.completions.create(
        model="deepseek/deepseek-v4.1-flash", messages=messages, tools=TOOLS
    )
    message = completion.choices[0].message

    if not message.tool_calls:
        print(message.content)
        break

    messages.append(message.model_dump(exclude_none=True))
    for call in message.tool_calls:
        try:
            output = run_tool_call(keenable, call.function.name, call.function.arguments)
        except KeenableError as exc:
            # Hand the failure back so the model can try another source.
            output = f"Tool call failed: {exc}"
        messages.append({"role": "tool", "tool_call_id": call.id, "content": output})
```

`TOOLS` holds OpenAI-format definitions for `keenable_search` and `keenable_fetch`. `run_tool_call` runs whichever one the model picked and returns a numbered, citable block for the `tool` message, so the model can cite a fetched page the same way it cites a search result. Filters, async and errors are in the [SDK reference](https://github.com/keenableai/keenable-sdk).

## TypeScript, AI SDK

```bash theme={"theme":{"light":"github-light-high-contrast","dark":"dark-plus"}}
npm install @keenable/ai-sdk @openrouter/ai-sdk-provider ai zod
```

Pass `keenableTools()` to `generateText` with an OpenRouter model:

```typescript theme={"theme":{"light":"github-light-high-contrast","dark":"dark-plus"}}
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
import { generateText, stepCountIs } from "ai";
import { keenableTools } from "@keenable/ai-sdk";

const openrouter = createOpenRouter({ apiKey: process.env.OPENROUTER_API_KEY });

const { text } = await generateText({
  model: openrouter("deepseek/deepseek-v4.1-flash"),
  tools: keenableTools(),
  stopWhen: stepCountIs(5),
  prompt: "What changed in the latest Bun release? Cite the pages you used.",
});

console.log(text);
```

`stopWhen` lets the model search, read the results and then answer. Without it, `generateText` stops after the first step and returns only the tool call. The same tools work in `streamText`. To keep the key out of environment variables on Vercel, see [Vercel](https://docs.keenable.ai/integrations/vercel.md).

## OpenRouter Agent SDK, MCP

```bash theme={"theme":{"light":"github-light-high-contrast","dark":"dark-plus"}}
npm install @openrouter/agent @openrouter/mcp
```

Connect to the Keenable MCP server and pass its tools to `callModel`:

```typescript theme={"theme":{"light":"github-light-high-contrast","dark":"dark-plus"}}
import { OpenRouter } from "@openrouter/agent";
import { callModel } from "@openrouter/agent/call-model";
import { createMCPTools } from "@openrouter/mcp";

const client = new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY });

const keenable = await createMCPTools({ url: "https://api.keenable.ai/mcp" });

const result = callModel(client, {
  model: "deepseek/deepseek-v4.1-flash",
  input: "What changed in the latest Bun release? Cite the pages you used.",
  tools: keenable.tools,
});

console.log(await result.getText());
await keenable.close();
```

`createMCPTools` reads the tool list from the [Keenable MCP server](https://docs.keenable.ai/mcp-server.md) and runs the calls, so there is no tool code to write. To use your key, pass it as a header:

```typescript theme={"theme":{"light":"github-light-high-contrast","dark":"dark-plus"}}
const keenable = await createMCPTools({
  url: "https://api.keenable.ai/mcp",
  auth: { kind: "headers", headers: { "X-API-Key": process.env.KEENABLE_API_KEY! } },
});
```

## Use your API key

> [!NOTE]
>
> Set `KEENABLE_API_KEY` to remove the hourly request cap. If you don't set a key, calls run on the shared keyless tier, which allows 1,000 requests per hour per IP address. See [Rate limits](https://docs.keenable.ai/rate-limits.md).

The Python SDK and `@keenable/ai-sdk` read `KEENABLE_API_KEY` from the environment. The MCP client takes it as the header above. Create a key in the [Keenable console](https://app.keenable.ai/console).

## Billing

OpenRouter bills the model's tokens, including the search results the model reads. Keenable bills its calls separately to your Keenable organization: 100,000 free requests a month, then \$4 per 1,000. See [Pricing](https://docs.keenable.ai/pricing.md). Without a key, the calls run on the public tier. This setup is separate from OpenRouter's own `openrouter:web_search` server tool: Keenable runs as your tool, so it behaves the same on every model and every call goes through your code.

## Related pages

> [card] [Baseten](https://docs.keenable.ai/integrations/baseten.md)
>
> Keenable web search and page fetch as server-side tools on Baseten Model APIs, called by the model inside the inference loop.

> [card] [Tool calling](https://docs.keenable.ai/tool-calling.md)
>
> Give an LLM web search and page fetch as tools. Pass the SDK's TOOLS to any OpenAI-compatible chat completions client and run each call with run\_tool\_call.

> [card] [Overview](https://docs.keenable.ai/sdks.md)
>
> Install the official Keenable SDK for Python, TypeScript, Go or Rust with one command, search with no key, then add fetch, tool calling and Monitors.

> [card] [Cerebras](https://docs.keenable.ai/integrations/cerebras.md)
>
> Ground Cerebras Inference models in live web results with the Keenable SDK: one search for cited answers, or tool calling with TOOLS, in Python and Node.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.