#!/usr/bin/env bash # Citations on a plain-text document block (citations.enabled true) → char_location citations on the text blocks. # STATUS: LIVE_VERIFIED 2026-09-18 (claude-haiku-4-5-20251001): citation {char_location, cited_text "Grass is green.", 17-32} (~$0.0007). # Run: bash examples/anthropic/citations/citations_text_document.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:100, messages:[{role:"user", content:[ {type:"document", source:{type:"text", media_type:"text/plain", data:"The sky is blue. Grass is green."}, title:"Colors", citations:{enabled:true}}, {type:"text", text:"What color is grass? Answer in one sentence and cite."}]}]}')" echo "HTTP $ANT_STATUS" echo "$OUT" | jq -c '.content[] | {text, citations}' log_request anthropic POST /v1/messages "$ANT_STATUS" 0.0007 "example citations/citations_text_document.sh $MODEL"