> ## 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

# Read long web pages without filling your context

> How to cap fetch output with max_chars, read truncated and total_chars to see what was cut, and switch to a prompt when a page runs past 50,000 characters.

Keep a long page from taking over your agent's context. Cap `content` with `max_chars`, read `truncated` and `total_chars` to see how much was left out, and ask a `prompt` for the part you need when the page is longer than your budget.

## Parameters

| Parameter | In | Type | Default | Limits | What it does |
| - | - | - | - | - | - |
| `max_chars` | Query, `/v1/fetch` | integer | `50000` | At least 1 | Maximum number of characters of `content`, counted in Unicode code points. Longer content is cut so that `content`, including a trailing `...`, is never longer than this, and `truncated` is `true`. The `...` is left out when this is 3 or less. |
| `prompt` | Query, `/v1/fetch` | string | None | At most 2,000 characters | An instruction for extracting part of the page, at most 2000 characters. When set, a model reads the page and `content` holds only its answer instead of the whole page. |

Without `max_chars`, a fetch returns up to 50,000 characters of `content`. Over MCP, `fetch_page_content` returns up to 20,000 unless you set `max_chars`.

## Cap a page, then extract

This sample reads the first 2,000 characters of the Python 3.13 release notes, prints whether the page was cut and how long it is, and then asks a prompt for one list from the whole page. It runs with no API key:

```typescript TypeScript theme={"theme":{"light":"github-light-high-contrast","dark":"dark-plus"}}
// Needs keenable 0.2.0 or later on npm.
import { Keenable } from "keenable";

const URL = "https://docs.python.org/3/whatsnew/3.13.html";

async function main() {
  const client = new Keenable(); // keyless: no API key needed to try it

  // 1. Read the start of the page, capped at 2,000 characters
  const page = await client.fetch(URL, { maxChars: 2000 });
  console.log(`truncated: ${page.truncated}, total_chars: ${page.totalChars}`);

  // 2. The page is longer than the cap: ask for only the part you need
  if (page.truncated) {
    const part = await client.fetch(URL, {
      prompt: "List the PEP 594 modules this page says were removed from the standard library, as a comma-separated list.",
    });
    console.log(part.content);
  }
}

main();
```

```python Python theme={"theme":{"light":"github-light-high-contrast","dark":"dark-plus"}}
from keenable import Keenable

URL = "https://docs.python.org/3/whatsnew/3.13.html"
client = Keenable()  # keyless: no API key needed to try it

# 1. Read the start of the page, capped at 2,000 characters
page = client.fetch(URL, max_chars=2000)
print(f"truncated: {page.truncated}, total_chars: {page.total_chars}")

# 2. The page is longer than the cap: ask for only the part you need
if page.truncated:
    part = client.fetch(
        URL,
        prompt="List the PEP 594 modules this page says were removed from the standard library, as a comma-separated list.",
    )
    print(part.content)
```

```go Go theme={"theme":{"light":"github-light-high-contrast","dark":"dark-plus"}}
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/keenableai/keenable-sdk/go"
)

const url = "https://docs.python.org/3/whatsnew/3.13.html"

func main() {
	ctx := context.Background()
	client, err := keenable.New(nil) // keyless: no API key needed to try it
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()

	// 1. Read the start of the page, capped at 2,000 characters
	page, err := client.FetchWithOptions(ctx, url, &keenable.FetchOptions{MaxChars: 2000})
	if err != nil {
		log.Fatal(err)
	}
	truncated := page.Truncated != nil && *page.Truncated
	if page.TotalChars != nil {
		fmt.Printf("truncated: %t, total_chars: %d\n", truncated, *page.TotalChars)
	}

	// 2. The page is longer than the cap: ask for only the part you need
	if truncated {
		part, err := client.FetchWithOptions(ctx, url, &keenable.FetchOptions{
			Prompt: "List the PEP 594 modules this page says were removed from the standard library, as a comma-separated list.",
		})
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(part.Content)
	}
}
```

```rust Rust theme={"theme":{"light":"github-light-high-contrast","dark":"dark-plus"}}
use keenable::{Client, FetchOptions};

const URL: &str = "https://docs.python.org/3/whatsnew/3.13.html";

#[tokio::main]
async fn main() -> Result<(), keenable::Error> {
    let client = Client::new()?; // keyless: no API key needed to try it

    // 1. Read the start of the page, capped at 2,000 characters
    let page = client
        .fetch_with(URL, &FetchOptions { max_chars: Some(2000), ..Default::default() })
        .await?;
    let truncated = page.truncated.unwrap_or(false);
    println!("truncated: {}, total_chars: {}", truncated, page.total_chars.unwrap_or(0));

    // 2. The page is longer than the cap: ask for only the part you need
    if truncated {
        let part = client
            .fetch_with(
                URL,
                &FetchOptions {
                    prompt: Some(
                        "List the PEP 594 modules this page says were removed from the standard library, as a comma-separated list."
                            .into(),
                    ),
                    ..Default::default()
                },
            )
            .await?;
        println!("{}", part.content);
    }
    Ok(())
}
```

```bash curl theme={"theme":{"light":"github-light-high-contrast","dark":"dark-plus"}}
# 1. Read the start of the page, capped at 2,000 characters
curl -G https://api.keenable.ai/v1/fetch/public \
  -H "X-Keenable-Title: My App" \
  --data-urlencode "url=https://docs.python.org/3/whatsnew/3.13.html" \
  --data-urlencode "max_chars=2000"

# 2. If the response has "truncated": true, ask for only the part you need
curl -G https://api.keenable.ai/v1/fetch/public \
  -H "X-Keenable-Title: My App" \
  --data-urlencode "url=https://docs.python.org/3/whatsnew/3.13.html" \
  --data-urlencode "prompt=List the PEP 594 modules this page says were removed from the standard library, as a comma-separated list."
```

You see that the page is 191,381 characters long, so the first call kept about 1% of it. The second call returns only the list of PEP 594 removals. This run was made on 19 November 2026, and the Python output is shown:

```text Example output · results vary theme={"theme":{"light":"github-light-high-contrast","dark":"dark-plus"}}
truncated: True, total_chars: 191381
aifc, audioop, cgi, cgitb, chunk, crypt, imghdr, mailcap, msilib, nis, nntplib, ossaudiodev, pipes, sndhdr, spwd, sunau, telnetlib, uu, xdrlib
```

## Read what was cut

These fields of the fetch response tell your code whether it has the whole page:

| Field | Value when the page fits | Value when the page was cut |
| - | - | - |
| `truncated` | `false` | `true` |
| `total_chars` | The length of `content` | The length of the full page, before the cut |
| `content` | The whole page | The start of the page, ending with `...`, never longer than `max_chars` |

Lengths count Unicode code points, not bytes or tokens. With a `prompt`, all three describe the model's answer instead of the page.

## Choose a strategy

| Situation | What to send |
| - | - |
| You need the opening of the page, such as a summary or an abstract | `max_chars` set to your budget |
| You need a few facts from anywhere in the page | `prompt` that names them |
| You need exact text from the middle or the end | A more specific URL, such as the page's own subpage, or a larger `max_chars` |
| You don't know yet | A small `max_chars` first, then decide from `total_chars` |

Fetch always cuts from the end: `max_chars` keeps the start of the page, and there is no parameter to start reading later in the page. To reach text near the end of a long page, use a `prompt` or a URL closer to that text.

## Common mistakes

| Wrong | Right | Why |
| - | - | - |
| Treat `content` as the whole page | Check `truncated` first | A page longer than `max_chars` is cut, and the default cap is 50,000 characters. |
| `max_chars=0` or `max_chars=-1` | A positive integer | The API returns `400` with `"max_chars": must be a positive integer`. |
| Raise `max_chars` until the whole page fits | Ask a `prompt` for the part you need | A 191,381-character page fills most of an agent's context. The list of PEP 594 removals it needed was 142 characters. |
| A `prompt` on a page that fails as too long | Fetch without `prompt`, or use a more specific URL | If the page is too long to run a prompt over, the API returns `400` with `The page is too long to run a prompt over`. |
| Count `max_chars` in tokens | Count characters | `max_chars` caps Unicode code points. A token is often several characters. |

## In the SDKs, CLI and MCP

Every SDK returns `truncated` and `total_chars` on the page it fetches: `page.truncated` and `page.total_chars` in Python and Rust, `page.truncated` and `page.totalChars` in TypeScript (from `keenable` 0.2.0), `Truncated` and `TotalChars` in Go. The CLI takes `--max-chars` and prints both fields (see [CLI](https://docs.keenable.ai/cli.md)). Over MCP, `fetch_page_content` adds a line such as `Truncated: showing the first 2000 of 191381 characters` when it cuts a page (see [MCP server](https://docs.keenable.ai/mcp-server.md#available-tools)).

## API reference

* [Fetch response](https://docs.keenable.ai/api-reference/fetch.md#response): `content`, `truncated` and `total_chars`.
* [Extract part of a page with a prompt](https://docs.keenable.ai/guides/fetch-with-prompt.md): write a prompt that returns parseable output.
* [Search, then fetch](https://docs.keenable.ai/guides/search-then-fetch.md): answer from snippets before you fetch at all.


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