#!/usr/bin/env python3 """web_search_20250305, max_uses 1, user_location. STATUS: LIVE_VERIFIED 2026-09-18 (c4: 1 search = $0.01 + tokens; c1 soft prompt -> no search). Run: .venv/bin/python examples/anthropic/web-search/web_search.py """ import json, sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[3])) from scripts.live import anthropic_request MODEL = "claude-haiku-4-5-20251001" st, r, _ = anthropic_request("POST", "/v1/messages", {"model": MODEL, "max_tokens": 300, "tools": [{"type": "web_search_20250305", "name": "web_search", "max_uses": 1, "user_location": {"type": "approximate", "city": "Toronto", "country": "CA", "timezone": "America/Toronto"}}], "messages": [{"role": "user", "content": "You MUST call the web_search tool once: search for the current Bank of Canada policy interest rate. Answer in 5 words with a citation."}]}, beta=None, note="web_search.py") print("HTTP", st, "stop_reason:", r.get("stop_reason")) for b in r.get("content", []): print(json.dumps({k: v for k, v in b.items() if k in ("type", "name", "toolset_name", "input", "caller", "text", "content", "tool_use_id", "server_name", "is_error")}, ensure_ascii=False)[:600]) print("usage:", json.dumps(r.get("usage")), "container:", r.get("container"))