v1.0.3
What's Changed
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:
- String format:
"system": "text here" - 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
MarshalJSONto output SystemBlocks as "system" array - Add
UnmarshalJSONto 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