#!/usr/bin/env bash # Extended (manual) thinking on Haiku 4.5: thinking.type enabled + budget_tokens 1024, max_tokens 1200. # Prints the thinking block (summary + signature prefix) and usage.output_tokens_details.thinking_tokens. # STATUS: LIVE_VERIFIED 2026-09-18 — 200, [thinking, text "4"], thinking_tokens 30 (~$0.0003). # Run: bash examples/anthropic/thinking/extended_thinking.sh set -eo pipefail cd "$(dirname "$0")/../../.." && source scripts/lib.sh OUTF="$(mktemp)"; trap 'rm -f "$OUTF"' EXIT # `ant` sets ANT_STATUS; calling it inside $(...) would lose it, so write the body to a file instead. call() { ant "$@" > "$OUTF"; OUT="$(cat "$OUTF")"; } MODEL="${ANTHROPIC_MODEL:-claude-haiku-4-5-20251001}" call POST /v1/messages -d "$(jq -n --arg m "$MODEL" '{model:$m, max_tokens:1200, thinking:{type:"enabled", budget_tokens:1024}, messages:[{role:"user", content:"What is 2+2? Reply with the number."}]}')" echo "HTTP $ANT_STATUS" echo "$OUT" | jq -c '.content[] | {type, thinking: (.thinking // null | if . then .[0:80] else null end), signature: (.signature // null | if . then .[0:24] else null end), text}' echo "$OUT" | jq -c '.usage | {output_tokens, output_tokens_details}' log_request anthropic POST /v1/messages "$ANT_STATUS" 0.0003 "example thinking/extended_thinking.sh $MODEL"