Prompt caching with files API in Sonnet 4.5, Where am I going wrong?

I have a workflow in where I recently switched to claude and the model sonnet 4.5 with prompt caching, I am using anthropic API via a http node in n8n with 5 records those need to be processed against a static instructions file that I already uploaded to anthropic files and using that asset id as you see in the 2nd picture and I also set a cache policy with default 5 minutes.

I am just testing this setup with 5 example records, hoping that the file data will cache only for the first record but actually getting cached for all the 5 records as you see in the results picture. Do i need to put all those subsequent records into the same message array? any help or suggestions appreciated. Thanks!



In your current example you are making 5 independent calls to Claude. Each call consists of a reference file + a single message.

If you can’t to pass all 5 items as messages inside a single dialogue, then you need to create an array and pass it only once.

Thanks for your reply. Figured out the problem actually n8n performing all 5 requests at once and they all hitting the claude’s server in similar times, and claude treating each request along with cache instruction as an individual call!

I initially thought the requests go in sequence! The solutions I tried including a code node with http request, but it didn’t perfectly worked for my case!

My current solution involved using a dedicated webserver with this POST message and I am using that API in n8n!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.