#!/usr/bin/env python3 """web_fetch_20250910 with citations; URL supplied in the user message. STATUS: LIVE_VERIFIED 2026-09-18 (d1, ~$0.004). Run: .venv/bin/python examples/anthropic/web-fetch/web_fetch.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": 200, "tools": [{"type": "web_fetch_20250910", "name": "web_fetch", "max_uses": 1, "citations": {"enabled": True}, "max_content_tokens": 2000}], "messages": [{"role": "user", "content": "Fetch https://example.com and tell me the page title in 3 words."}]}, beta=None, note="web_fetch.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"))