DocsAPI Reference
Endpoints

Web search and fetch

Search the web and read pages through one API, answered by Serper, Exa or DeepSeek, billed per call.


POST /v1/web_search searches the web and POST /v1/web_fetch reads one page. Both are answered by a web search provider your deployment has set up (Serper, Exa or DeepSeek), and the request and response look the same whichever provider answers. To change provider, change provider and nothing else.

These are calls your code makes on purpose, for example from an agent's own web_search tool. They do not change model requests: Anthropic's web_search and web_fetch server tools on /v1/messages are still sent to the model's provider as you declared them.

curl -sS https://api.tokamak.sh/v1/web_search \
  -H "Authorization: Bearer $TOKAMAK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query": "open source llm router", "max_results": 5}'
{
  "id": "ws_3f0c9a51e1b24f6c9d2e7b8a1c4d5e6f",
  "object": "web_search",
  "provider": "prov_8x2k4m9q1w7e3r5t",
  "results": [
    {
      "title": "An open source LLM router",
      "url": "https://example.com/router",
      "snippet": "Routes each request to the model that fits it…",
      "content": null,
      "published_at": "2026-03-01T00:00:00Z",
      "site_name": "example.com"
    }
  ],
  "usage": { "requests": 1 }
}
FieldMeaning
queryRequired. What to search for, up to 2,000 characters (DeepSeek allows 128 including filters).
max_results1 up to the provider's limit (at most 50; 10 for Exa). Default 10, or the provider's limit if lower. Above the limit is refused with 422 max_results_exceeded.
include_domains, exclude_domainsUp to 20 domains each, such as github.com or docs.example.com/guides.
published_after, published_beforeA date (2026-01-31) or an RFC 3339 time.
include_contentAlso return each result's page text in content. Exa and DeepSeek support it; Serper refuses it with 400 invalid_request (fetch the pages instead).
providerWhich provider answers: a provider id, or serper, exa or deepseek when your deployment has exactly one of that kind. Without it, your deployment's default search provider answers.
provider_optionsPassed to that provider only. Serper: gl, hl, location, autocorrect, page. Exa: category. DeepSeek: ori_question. Any other key is refused with 400 invalid_request.

An unknown field anywhere in the body is refused with 400 invalid_request, so a misspelt option is never ignored. A filter the chosen provider cannot apply is refused rather than dropped.

Fetch

curl -sS https://api.tokamak.sh/v1/web_fetch \
  -H "Authorization: Bearer $TOKAMAK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com"}'
{
  "id": "wf_9b1d2c3e4f5a6b7c8d9e0f1a2b3c4d5e",
  "object": "web_fetch",
  "provider": "prov_8x2k4m9q1w7e3r5t",
  "url": "https://example.com",
  "title": "Example Domain",
  "content": "Example Domain\n\nThis domain is for use in documentation examples…",
  "truncated": false,
  "usage": { "requests": 1 }
}
FieldMeaning
urlRequired. An http or https URL on a public host, with no user name or password and the default port. Private, loopback and internal addresses are refused with 400 url_not_allowed.
max_charactersCut the content to this many characters, up to the provider's limit (default: that limit, 100,000 unless your deployment changed it). truncated says whether it was cut.
providerAs for search, with your deployment's default fetch provider.

content is Markdown (DeepSeek, Serper) or plain text (Exa). A page the provider cannot read is refused with 422 fetch_failed.

Fetched pages are untrusted text. A page can contain instructions aimed at a model, so treat its content as data, not as instructions.

Billing

  • One successful call is one charge, at the price your deployment set for that provider: per search for /v1/web_search, per page for /v1/web_fetch.
  • No results, a page that cannot be fetched, a provider error or a timeout cost nothing. The response is still recorded in usage analytics, with its finish reason.
  • In usage analytics the rows have source web_search or web_fetch and a model such as exa/web_search or deepseek/web_fetch.
  • The settled execution id is in the X-Tokamak-Execution-Id header; look it up with GET /v1/generation.
  • Calls count toward your organization's rate limits and budgets like any other request. An organization that cannot afford a call gets 402 before the provider is contacted.
  • Organizations with a guardrail policy have the query and the URL screened like a prompt.

Errors

StatuscodeMeaning
400invalid_requestThe body is not valid, or the provider cannot honour a filter or option.
400invalid_providerprovider names no active provider that supports this call, or matches more than one (the message lists their ids).
400url_not_allowedThe fetch URL is not a public http/https address.
422max_results_exceeded, max_characters_exceededAbove the provider's limit.
422fetch_failedThe page could not be fetched or had no readable content.
429rate_limitedThe provider is rate limiting. Your own rate limits answer 429 too.
502upstream_errorThe provider failed or did not answer in time.
503web_search_unavailable, web_fetch_unavailableNo default provider is set for this call.

For administrators

Providers are added on the platform console's Providers page: choose the category Web search, then the type (Serper, Exa or DeepSeek), and enter the base URL and API key. On the same form, choose:

  • whether the provider serves search, fetch or both;
  • for Exa, the search mode (auto, lite, deep-lite or deep). The mode is part of the provider, not the request, because it changes the price. To offer two modes, add Exa twice;
  • the price per 1,000 searches and per 1,000 fetches (0 for free);
  • the most results and the most characters one call may return;
  • whether it is the default for search, for fetch, or both. Only one provider is the default for each; saving a new default clears the old one.

Nothing about web search is read from environment variables.

On this page