Harden: Big Screenshots Cost Tokens

image size and token cost

Part of: Screenshot Describer

A screenshot from a modern laptop can be 3000 pixels wide. Send that straight to the model and the request gets slow and the bill for that one call jumps. Images aren't free. They're billed in tokens, just like text. Images cost tokens too Anthropic's models estimate an image's token cost from its pixel area. A rule of thumb: tokens are about (width x height) / 750. A 1024x1024 screenshot costs roughly 1,400 tokens before you've sent a single word of prompt. A full-resolution 4K screenshot can cost tens of thousands of tokens for one image, more than most entire text prompts. Downscale before you send The model doesn't need every pixel to read a button label. Capping the longest side to something like 1024 or 1568 pixels keeps the image sharp enough to describe a UI while cutting the token bill sharply: This keeps the aspect ratio. Both sides shrink by the same factor, computed with integer math so the result is exact rather than drifting from floating-point rounding. In a real tool you'd hand these dimensions to an image library (Pillow's Image.resize) before base64-encoding the result. The order of operations matters Resize before you base64-encode, not after. Base64 only re-enco

Challenge: Resize and Estimate Token Cost