SDK and CLI
Clawifi for the Vercel AI SDK
@clawifi/ai-sdk gives an AI SDK agent three tools: webSearch, webFetch and extract. Search and fetch work without an API key, so you can try them before you sign up.
Install#
npm install @clawifi/ai-sdk ai zod
Works with AI SDK 6 and 7, which both need zod 3.25.76 or 4.1.8 and newer. @clawifi/ai-sdk needs Node.js 20.3 or later; AI SDK 7 itself needs Node.js 22 or later. The source is on GitHub, under the MIT license.
Give the tools to a model#
import { generateText, isStepCount } from 'ai';
import { clawifiTools } from '@clawifi/ai-sdk';
const { text } = await generateText({
model: 'openai/gpt-5-mini',
prompt: 'What changed in the latest Node.js release? Cite the pages you used.',
tools: clawifiTools(),
stopWhen: isStepCount(5),
});
console.log(text);
On AI SDK 6, use stepCountIs(5) in place of isStepCount(5). A model string such as openai/gpt-5-mini goes through the Vercel AI Gateway (set AI_GATEWAY_API_KEY); to call a provider directly, pass its model instead, such as openai('gpt-5-mini') from @ai-sdk/openai. To pick the tools one by one, and name them yourself:
import { extract, webFetch, webSearch } from '@clawifi/ai-sdk';
const tools = {
webSearch: webSearch({ maxResults: 8 }),
webFetch: webFetch({ maxCharacters: 10_000 }),
extract: extract(),
};
The three tools#
| Tool | What the model gets | Input | Output |
|---|---|---|---|
webSearch | Ranked web results with title, URL and snippet (no page text). | query, maxResults?, includeDomains?, timeRange? (day, week, month, year) | { query, results: [{ title, url, snippet, publishedAt? }], keyless? } |
webFetch | One page or PDF as markdown, or only the passages that answer query. | url, query? | { url, title?, markdown, contentStatus, publishedAt?, truncated } |
extract | Structured fields from a page, with a confidence score. Deterministic: no language model runs. | url, and preset (article, product, person, company) or fields ([{ name, type }]) or both | { url, data, confidence, valid } |
contentStatus is ok, thin, blocked, needs_javascript or not_found, so the model can tell an empty page from a failed one. Fetch and scrape has the fields behind webFetch; Search has the search options.
API key and costs#
export CLAWIFI_API_KEY=clawifi_live_...
A free account has 1,000 credits a month, no card needed: get a key. The tools read CLAWIFI_API_KEY; without it they use the keyless trial.
| With a key | Without a key | |
|---|---|---|
webSearch | 1 credit; a search that finds nothing costs 0. Up to 20 results, domain and time filters. | At most 3 results, no domain or time filters. |
webFetch | 1 credit, 3 when plain HTTP gets no page and Clawifi reads it in a browser; a PDF costs 2 per started 50 pages instead. A page with nothing to read costs 0. | Pages are cut at 20,000 characters; with query, up to 3 passages. |
extract | 1 credit, 3 when plain HTTP gets no page and Clawifi reads it in a browser; a PDF costs 2 per started 50 pages instead. A page with nothing to read costs 0. | Needs a key. |
| Limits | Your plan's; see Rate limits. | 12 calls a minute, 50 a day per address; a busy minute can refuse a call sooner. |
The trial counts calls per address. On a serverless host that is usually an outbound address many apps share, so set CLAWIFI_API_KEY in production. Without a key, webSearch and webFetch call the trial tools of the hosted MCP server. A keyless search result carries a keyless.note field, so the model knows the filters were not applied. Every price is on Pricing and credits.
Options#
Every tool, and clawifiTools(), takes these:
| Option | Default | What it does |
|---|---|---|
apiKey | CLAWIFI_API_KEY | Your Clawifi API key. |
baseUrl | CLAWIFI_API_BASE or https://api.clawifi.dev | The API to call. |
timeoutMs | 30000 | Request timeout in milliseconds. |
fetch | the global fetch | A custom fetch, for tests or proxies. |
webSearch also takes maxResults (default 5, used when the model does not ask for a number; keep it between 1 and 20, the range the model may ask for). webFetch also takes maxCharacters (default 20,000; longer pages are cut and marked truncated: true). clawifiTools() takes both.
Errors#
A call that fails on the Clawifi side throws a ClawifiError, with status, code and retryAfter (seconds, on a rate limit) when Clawifi sent them; a timeout may come as a ClawifiError with only the message, or as the timeout error itself. Without a key, the day's limit usually comes as status 401 ("keyless limit reached": add a key or wait for the next day) and a refusal that says how long to wait, usually the minute's limit, as 429 with retryAfter; check the message too. A call you cancel with an abortSignal throws the abort error instead. Inside generateText the AI SDK hands its message to the model as a tool error, so the model can retry or tell the user what is missing. The status codes are on Errors.
Was this page helpful? Tell us · Last updated 2026-11-23