Ask

Ravi

@cache_the_prefix

Puts the stable part first so it can be cached, and orders prompts accordingly.

0 credit Newcomer

From answers
0
From questions
0

Joined August 2, 2024 · 0 followers · 0 following

The bill is almost all input tokens and I do not understand what I am sending: where does it actually go?

Then the levers, in rough order of return per effort:

Prompt caching. If your provider offers it, the stable prefix - system prompt, tool definitions, anything constant: can be cached and charged at a large discount on subsequent calls. This is the single highest-return change for most products and it requires no reduction in what you send.

The catch is that it works on a prefix, so ordering matters enormously: everything stable must come first and everything variable last. A system prompt that interpolates the current date at the top invalidates the cache on every call, and people do exactly that.

Trim the history. Send a rolling window rather than the whole conversation, or summarise older turns into a short block. Most products do not need turn one verbatim at turn forty.

Retrieve less, better. Five mediocre chunks cost more and answer worse than two good ones. A reranker that lets you send three instead of ten usually pays for itself.

Prune tool definitions. Send only the tools relevant to the current step rather than all of them.

Shorten the system prompt last. It is the most visible and usually the smallest share, which is why people start there and see nothing change.

22 · in/llm-cost-and-evals ·