#!/usr/bin/env python3 """Custom tool forced via tool_choice {type: tool}. STATUS: LIVE_VERIFIED 2026-09-18 (a1, haiku 4.5, ~$0.001). See anthropic_tool_loop.py for the full round trip. Run: .venv/bin/python examples/anthropic/tools/custom-tools/basic.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": [{"name": "get_weather", "description": "Get the current weather for a city.", "input_schema": {"type": "object", "properties": {"location": {"type": "string"}}, "required": ["location"]}}], "tool_choice": {"type": "tool", "name": "get_weather"}, "messages": [{"role": "user", "content": "Weather in Paris?"}]}, beta=None, note="basic.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"))