import base64 import logging import anthropic logger = logging.getLogger(__name__) PROMPT = ( "Briefly describe what's happening in this security camera image in 1-2 sentences. " "Focus on the people, vehicles, or animals and their activity. Be concise." ) def analyze_snapshot(client: anthropic.Anthropic, image_bytes: bytes) -> str | None: """Send a snapshot to Claude Haiku for description. Returns None on failure.""" try: b64 = base64.standard_b64encode(image_bytes).decode("utf-8") response = client.messages.create( model="claude-haiku-4-5-20251001", max_tokens=150, messages=[ { "role": "user", "content": [ { "type": "image", "source": { "type": "base64", "media_type": "image/jpeg", "data": b64, }, }, {"type": "text", "text": PROMPT}, ], } ], ) description = response.content[0].text.strip() logger.info("Vision analysis complete: %d chars", len(description)) return description except Exception: logger.exception("Claude Vision API failed") return None