How Prompt Caching Works
Anthropic's prompt caching stores the KV cache of previously processed tokens. On subsequent requests with the same prefix, cached tokens are billed at 10% of the normal input price. This is powerful for repetitive system prompts or static context that does not change between queries.
How Visual Encoding Works
Visual encoding reduces the raw number of input tokens by converting text to images. Instead of 28,000 text tokens, you send 3,300 image tokens. The savings come from reducing the token count itself, not from discounting the per-token price.
Head-to-Head Comparison
For a 100,000-character static codebase queried 50 times: Prompt caching costs 28,500 tokens × $3/M for the first request, then 28,500 × $0.30/M for the remaining 49 requests. Total: approximately $0.50. Visual encoding costs 3,350 image tokens × $3/M for all 50 requests. Total: approximately $0.50. They converge at roughly 50 repeated queries on the same content.
The Combination Play
The real power is using both together. Render your codebase as images, then cache those image tokens. The first request costs 3,350 image tokens. Subsequent requests cost 3,350 × $0.30/M. For 50 queries, the combined total drops to approximately $0.06 — a 90% reduction versus caching alone.
Decision Framework
Use prompt caching alone when your context is under 10,000 characters and changes rarely. Use visual encoding alone for one-off large payload analyses. Combine both for production systems that repeatedly query large, stable codebases.
Combining Prompt Caching With Visual Encoding
import anthropic, base64
client = anthropic.Anthropic()
# Load pre-rendered codebase images
images = []
for i in range(6):
with open(f"codebase_page_{i}.png", "rb") as f:
images.append(base64.b64encode(f.read()).decode())
# First request: full cost, establishes cache
# Subsequent requests: cached at 90% discount
system_content = [{"type": "text", "text": "You are a senior code reviewer."}]
for img in images:
system_content.append({
"type": "image",
"source": {"type": "base64", "media_type": "image/png", "data": img}
})
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=2048,
system=system_content, # This gets cached
messages=[{"role": "user", "content": "Find all potential null pointer exceptions."}]
)
Frequently Asked Questions
Conclusion
Visual token encoding is a practical, immediately deployable optimization that works with your existing AI stack. Whether you are a developer building pipelines or a founder managing API budgets, the ~88% input cost reduction compounds into real savings that improve your margins and extend your runway.
Ready to try it? Open PXINK and drop a file to see your savings instantly.