Skip to content

v1.0.3

Choose a tag to compare

@github-actions github-actions released this 25 Oct 09:56
29d2620

What's Changed

  • Fix system prompt caching for string format by @roblesjm in #4 #5

Changes

Bug Fixes

System Prompt Caching for String Format (#4, #5)

Fixed issue where system prompts using the string format were not being cached, even when exceeding the 1024-token minimum.

Root Cause:
The Anthropic API supports two formats for system prompts:

  1. String format: "system": "text here"
  2. Blocks format: "system": [{"type": "text", "text": "..."}]

Cache control can only be applied to the blocks format. Previously, autocache only handled prompts already in blocks format, so system strings were never cached regardless of size.

Solution:

  • Convert system strings to SystemBlocks when cacheable (>= min tokens)
  • Add cache_control to converted blocks
  • Serialize SystemBlocks as "system" array in JSON output

Technical Details:

  • Add MarshalJSON to output SystemBlocks as "system" array
  • Add UnmarshalJSON to accept both string and array formats
  • Ensures compatibility with all client formats

Testing

  • All 81 tests pass
  • End-to-end test confirms caching works with real API
  • First request: cache_creation_input_tokens = 1201
  • Second request: cache_read_input_tokens = 1201

Files Changed

  • internal/cache/injector.go: Convert system strings to blocks
  • internal/types/models.go: Add Marshal/UnmarshalJSON methods
  • internal/cache/cache_injector_test.go: Add conversion tests
  • internal/types/models_test.go: Add JSON handling tests
  • internal/server/handler_test.go: Update mock server

Full Changelog: v1.0.2...v1.0.3