The Problem
Without pinning, edit strategies are applied to all messages. As new messages arrive, older messages get edited differently:The Solution
Use thepin_editing_strategies_at_message parameter to “pin” where edit strategies are applied. Everything after the pin point remains unchanged:
How It Works
- The
get_messagesresponse includesedit_at_message_id- the message ID where strategies were applied up to - Pass this ID as
pin_editing_strategies_at_messagein subsequent requests - Strategies will only apply to messages up to (and including) that message
- Messages after the pin point remain unchanged, preserving your prompt cache
Usage
Best Practices
Store the Pin ID
Always store
edit_at_message_id from your first request and reuse it in subsequent calls.Monitor Token Count
Use
this_time_tokens from the response to track context size and decide when to reset.Reset Strategically
Reset the pin during natural breaks (e.g., between user turns) to minimize cache disruption.
Combine with Token Limit
When resetting, combine with
token_limit strategy to aggressively reduce context size.When to Reset the Pin
When your context grows too large, reset by omittingpin_editing_strategies_at_message. This applies strategies to all messages (breaking the cache once), giving you a new edit_at_message_id to pin going forward.