Skip to main content

IMAGE_TOKEN_ESTIMATE

Constant IMAGE_TOKEN_ESTIMATE 

Source
pub const IMAGE_TOKEN_ESTIMATE: usize = 1600;
Expand description

Token cost to charge a ModelContentBlock::Image in context-budget estimates.

Anthropic bills images at roughly width * height / 750 tokens, capped near 1600 for an image at the ~1.15 MP resize ceiling. We do not have pixel dimensions at this layer, so we charge the ceiling — deliberately pessimistic, because under-counting context is what causes a request to be rejected for length.

The trap this constant exists to avoid: estimating an image the same way as text (data.len() / 4) reads a 1 MB screenshot as ~250_000 tokens, which would trip compaction immediately on the first image the user pastes. The base64 payload length says almost nothing about the token cost.