Skip to Content
Guides/Web search

Web search

swim-1.0 searches the web and reads pages as it answers, and returns every source used.

swim-1.0 looks things up on its own. Web search is on by default, with nothing to set up: when the question needs the web — a recent event, a fact that changes, a link the user gave — the model searches, the API runs the searches itself, and the answer comes back with every search and page it used, in Anthropic's format, so the SDKs parse it. When the question doesn't need the web, the model answers without it, and nothing is billed for search. With the OpenAI SDK, /v1/chat/completions searches the same way and returns the pages read as annotations.

The model can do two things on the web:

  • Search — one query at a time; it gets the most useful pages with their text and date.
  • Read a page by its address — a link the user gave, or a page a search found.

Turn it on or off

web_search in the request body switches it, on /v1/messages and /v1/chat/completions alike:

web_search
left outThe model's default: on for swim-1.0
trueOn
falseOff: the model answers from what it knows and the conversation, and nothing is billed for search
curl https://api.strokes.ink/v1/messages \
  -H "x-api-key: $STROKES_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "swim-1.0",
    "web_search": false,
    "messages": [
      {
        "role": "user",
        "content": "Rewrite this paragraph in a warmer voice: …"
      }
    ]
  }'

Turn it off when the task is only about the text in front of the model — editing, rewriting, translating — or when your product must not reach the web. Leave it on and a plain request is enough:

{
  "model": "swim-1.0",
  "messages": [
    {
      "role": "user",
      "content": "What changed in the latest AP Stylebook? Two sentences."
    }
  ]
}

The response

content holds the model's words, each search or read it made and each result, in order:

{
  "id": "msg_…",
  "type": "message",
  "role": "assistant",
  "model": "swim-1.0",
  "content": [
    {
      "type": "server_tool_use",
      "id": "srvtoolu_8Kq2LmN9xP4sTv1KcW8bYd3R",
      "name": "web_search",
      "input": { "query": "AP Stylebook 2026 changes" }
    },
    {
      "type": "web_search_tool_result",
      "tool_use_id": "srvtoolu_8Kq2LmN9xP4sTv1KcW8bYd3R",
      "content": [
        {
          "type": "web_search_result",
          "url": "https://example.com/ap-stylebook-2026",
          "title": "What's new in the 2026 AP Stylebook",
          "encrypted_content": "V2hhdCdzIG5ldyBpbi…",
          "page_age": "2026-05-28"
        }
      ]
    },
    { "type": "text", "text": "The 2026 edition …" }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 2310,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "output_tokens": 406,
    "server_tool_use": { "web_search_requests": 1, "web_fetch_requests": 0 }
  }
}
Block
server_tool_useA search or read the model made: name is web_search or web_fetch, input is { "query": "…" } or { "url": "…" }
web_search_tool_resultThe pages a search found, the most useful first: url, title, page_age (when the page was published or last updated, or null) and encrypted_content, the page's text the model read. Show url and title as sources
web_fetch_tool_resultThe page read: content.url (the page actually read), content.retrieved_at, and the text in content.content.source.data with the title in content.content.title

A page read comes back like this:

{
  "type": "web_fetch_tool_result",
  "tool_use_id": "srvtoolu_…",
  "content": {
    "type": "web_fetch_result",
    "url": "https://example.com/ap-stylebook-2026",
    "retrieved_at": "2026-11-24T10:02:11.000Z",
    "content": {
      "type": "document",
      "title": "What's new in the 2026 AP Stylebook",
      "source": {
        "type": "text",
        "media_type": "text/plain",
        "data": "The 2026 edition adds …"
      }
    }
  }
}

When there's no copy of the exact page, another page of the same site may be read instead; content.url says which.

In one request the model searches up to 5 times and reads up to 5 pages by default. To change max_uses (1 to 10) or restrict domains with allowed_domains or blocked_domains, declare Anthropic's web_search_20250305 or web_fetch_20250910 server tool in tools (not with "web_search": false).

How a turn runs

When the model searches or reads a page, the API runs it, hands the result back and asks the model to go on — a round. Rounds repeat until the model answers, calls one of your own tools, or runs out of tokens, in the one request:

  • max_tokens is shared by every round of the request; when it runs out, the reply ends with max_tokens.
  • usage adds up every round. Each round reads the conversation so far, the results included, so input_tokens grows with each search.
  • Your own tools stop the turn. When the model calls one of your tools, the reply ends with stop_reason: "tool_use" — any searches in the same round are already answered in content. Send back a tool_result as in Tool use.

pause_turn

A request stops after 12 rounds. If the model is still searching then, the reply ends with stop_reason: "pause_turn". To let it go on, send a new request with the reply's content as the last assistant message, unchanged.

Results that failed

A search or a read that fails doesn't fail the request: its result block holds an error, the model is told, and it answers with what it has.

{
  "type": "web_fetch_tool_result",
  "tool_use_id": "srvtoolu_…",
  "content": {
    "type": "web_fetch_tool_result_error",
    "error_code": "url_not_accessible"
  }
}
error_code
max_uses_exceededThe model searched or read more times than one request allows
invalid_tool_inputA search had no query
invalid_inputA read's url isn't a web address
url_not_allowedThe page's domain is blocked or not in allowed_domains
url_not_accessibleNothing of that page or site could be found
unavailableWeb search is unavailable right now

Later turns

Send the search blocks back in the conversation as they came, with the rest of the assistant message. They carry what the model read — encrypted_content holds a result's text — so the model can use it again without searching twice. Leave them out and the model only sees its own words.

To cache pages across conversations for a user, pass a stroke_id: a page read once under that stroke is answered from cache the next time, and not billed again.

Streaming

With "stream": true, each round's text streams as usual, and a server_tool_use block starts with an empty input, filled by input_json_delta pieces. Each result block arrives whole in its content_block_start, followed by content_block_stop, with no deltas. index keeps counting across rounds, ping events keep the connection alive while a search runs, and one message_delta at the end carries the request's total usage. See Streaming events.

Pricing

Every search and every page read that came back costs $2 per 1,000 ($0.002), on top of the tokens of every round. A read that found nothing (url_not_accessible) counts; one that was refused or unavailable doesn't. usage.server_tool_use counts what was billed:

"server_tool_use": { "web_search_requests": 2, "web_fetch_requests": 1 }

It's present whenever the model searched or read a page. The console's Activity page shows each request's web requests and cost.

Not supported

Citations. Answers don't carry citations; the sources are the result blocks.

On this page