copilot-sdk icon indicating copy to clipboard operation
copilot-sdk copied to clipboard

Expose prompt caching stats in metrics telemetry

Open LeoX91 opened this issue 5 months ago • 8 comments

Context

The Copilot SDK currently does not support prompt caching natively, unlike other LLM solutions (such as the Anthropic or OpenAI APIs). This leads to increased costs and latency when the same prompts are sent multiple times (system prompt, etc...), since every request is always processed as new by the backend.

Request I am requesting the introduction of a prompt caching feature at the SDK level, even if only as an optional capability.

Rationale

Reduced costs and latency for repetitive prompts Alignment with LLM best practices and the example set by other SDKs The ability to develop systems that make heavy reuse of requests in an efficient way

This is so much needed with the new usage-based billing.

Thank you!

LeoX91 avatar Jun 04 '26 09:06 LeoX91

The SDK does already enable prompt caching internally, but does not expose fine-grained APIs to SDK users; doing that would be a bit tricky, as how prompt caching works exactly differs significantly across providers. For example, OpenAI largely implements prompt caching internally on the server side, without fine-grained APIs allowing clients to determine what should get cached (Anthropic does).

Is there something specific you're looking for in terms of prompt caching, which model(s) are you using, etc.?

roji avatar Jun 04 '26 15:06 roji

The SDK does already enable prompt caching internally, but does not expose fine-grained APIs to SDK users; doing that would be a bit tricky, as how prompt caching works exactly differs significantly across providers. For example, OpenAI largely implements prompt caching internally on the server side, without fine-grained APIs allowing clients to determine what should get cached (Anthropic does).

Is there something specific you're looking for in terms of prompt caching, which model(s) are you using, etc.?

Hello @roji and thank you for your answer. So the thing is that we cannot control if prompt caching is working or not. I mean, with this new usage based billing, how are we supposed to optimize our prompt and agentic flows without knowing if a prompt is going to hit or miss the cache?

This is also an environmental issue, BIG ISSUE. An agentic app that does everything to hit the cache will be much more nvironment friendly than another one that does not do anything to hit the cache.

As Github Copilot SDK user, I want to know if my app is optimized to hit the cache, and actually this SDK just abstract this aspect without giving us the context to know how to optimize prompt caching.

LeoX91 avatar Jun 05 '26 07:06 LeoX91

So the thing is that we cannot control if prompt caching is working or not. I mean, with this new usage based billing, how are we supposed to optimize our prompt and agentic flows without knowing if a prompt is going to hit or miss the cache?

My point above was that low-level prompt caching controls is something that OpenAI itself does not allow (in contrast to Anthropic). The cache operates largely automatically, providing you follow certain guidelines (see the docs). Beyond some very coarse controls which are exposed to the client, that's just how OpenAI works - it's not something that the Copilot SDK can control (we just expose access).

roji avatar Jun 07 '26 21:06 roji

So the thing is that we cannot control if prompt caching is working or not. I mean, with this new usage based billing, how are we supposed to optimize our prompt and agentic flows without knowing if a prompt is going to hit or miss the cache?

My point above was that low-level prompt caching controls is something that OpenAI itself does not allow (in contrast to Anthropic). The cache operates largely automatically, providing you follow certain guidelines (see the docs). Beyond some very coarse controls which are exposed to the client, that's just how OpenAI works - it's not something that the Copilot SDK can control (we just expose access).

I totally undesrtand what your are saying. Sorry for my English I'm not native.

What I expect is at least some informations regarding if the cache was hitted or missed, the official OpanAI API exposes it. At least we could know if we're effectively using the cache or not, allowing us to tweak our agentic flows.

LeoX91 avatar Jun 08 '26 06:06 LeoX91

I've changed the issue title to reflect that this is about metrics/telemetry.

roji avatar Jun 11 '26 10:06 roji

Do you think this will be ever implemented?

LeoX91 avatar Jul 07 '26 10:07 LeoX91

@LeoX91 I think so, but we have a huge amount of work on our hands, and for now you're the only one requesting it.

roji avatar Jul 07 '26 12:07 roji

Closing as fixed after verification against the current public SDK sources and bundled behavior.

Public evidence

The reported behavior/request is implemented at the current SDK baseline, so this issue is being closed as completed.

Public SDK baseline: github/copilot-sdk d5c9d06d8c41.

patniko avatar Sep 08 '26 03:09 patniko