Skip to main content
npm install caesar-search ai
The ai package (version 5 or newer) is an optional peer dependency of caesar-search — optional for the rest of the SDK, required for this subpath. Importing caesar-search/ai without it fails at module resolution.
import { generateText } from "ai";
import { caesarTools } from "caesar-search/ai";

const { text } = await generateText({
  model,
  tools: caesarTools(),
  prompt: "What changed in Postgres 17 logical replication?",
});
This works keyless — the default client uses the anonymous tier. Set CAESAR_API_KEY only if you have a partner key for higher throughput.

The tools

caesarTools() returns an object with exactly two tools, keyed caesar_search and caesar_read.
ParameterTypeDescription
querystring, requiredThe search query.
max_resultsnumberMaximum results, 1-50. Default 8.
response_formatcompact | standard | fullcompact (default) is the token-efficient choice.
Runs client.search(query, { maxResults, verbosity }). The ids_only verbosity is deliberately omitted from the tool’s response_format enum — it exists at the client level, but is a poor fit for tool results. See response shaping.

caesar_read

ParameterTypeDescription
targetstring, requiredURL or doc_id to read.
querystringFocus content selection on a question.
max_charsnumberContent character cap. Default 12000 (applied server-side).
start_charnumberResume a truncated read from this character offset.
Runs client.read(target, { query, maxChars, startChar }).

Configuring the client

Pass your own configured client to control auth, timeouts, and retries:
import { Caesar } from "caesar-search";
import { caesarTools } from "caesar-search/ai";

const tools = caesarTools({
  client: new Caesar({ timeoutMs: 10000, maxRetries: 1 }),
});
All TypeScript SDK constructor options apply. If your agent speaks MCP instead of the AI SDK, the remote MCP server exposes the same two tools.

For agents

  • Tool results default to compact to protect the context window. Ask for standard or full only when you need passages or provenance.
  • Thread doc_id values between tool calls: caesar_search returns a doc_id per result, and it is the most reliable target for caesar_read — more stable than re-passing the URL.