Skip to content

query_anthropic resends tools + full history uncached every turn — cache_control cuts repeat input cost up to ~90% #1

Description

@r-lattice

Hi — api.py's client.messages.create(...) sends tools and the whole message list with no cache_control, so each agent turn re-buys the entire prefix (tool schemas + conversation so far) at full input rate. Marking the last tool and the latest message content block with {"cache_control": {"type": "ephemeral"}} lets subsequent turns read that shared prefix at ~10% of base input price — in an agentic coding loop that prefix is most of the input bill. Happy to open a PR if useful.

(Context: I build a cost-analysis tool for agent workloads — https://lens.r-lattice.com — and this repo came up when scanning public Claude agents for uncached call sites. No affiliation needed to take the fix.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions