/** * Asking the provider to cache the part of the prompt that never changes. * * A long run re-sends the whole conversation on every request. Measured on a real session: 152 * requests, 10,028,873 tokens, about 66k a request — and one or two per cent of that total is text * that had not been sent before. Everything else is the same prefix, read again, and charged again. * * Some providers cache prefixes on their own and report how much they served that way; nothing has * to be asked of them, and KONECK reads the figure back so the saving is visible. Others cache only * what you mark, in Anthropic's style: a `cache_control` note on a content block says "this and * everything before it is worth keeping". * * ## Only where it is documented to work, and dropped the moment it is refused * * An unknown field can be ignored, or it can fail the request. So the marks go only to providers * that document accepting them in an OpenAI-shaped body, and if one rejects the request anyway the * marks are dropped for the rest of the run and the turn is taken again. There is no live provider * to test this against on the machine it was written on, which is exactly why it is arranged to * fail into the old behaviour rather than out of it. */ import type { Message } from './types.js'; export declare function supportsCacheHints(provider: string): boolean; /** Below this there is nothing worth caching and the marks are pure overhead. */ export declare const MIN_CACHEABLE_CHARS = 8000; /** * The same messages, with up to two cache marks. * * The system message, because it holds the instructions and never changes; and the last message * before the newest, because everything up to it is settled while the newest is what this turn is * about. Two marks rather than one because a conversation has two stable regions, and rather than * four because each is a separate thing for the provider to keep. * * Nothing is mutated: a copy is returned. The marks describe this request only, and a mark left on * a message in the session's own history would travel into every later request and into the saved * transcript. */ export declare function withCacheHints(messages: readonly Message[]): Message[]; /** * Whether a failure is the provider objecting to the marks themselves. * * Matched on the field name, not on the status: a 400 that says nothing about caching is a * different problem and must not be answered by turning caching off and retrying, which would * hide it behind an unrelated change. */ export declare function looksLikeCacheRejection(err: unknown): boolean; /** What the reader is told once, when it is working. */ export declare function cacheSavingNotice(cached: number, prompt: number): string; //# sourceMappingURL=prompt-cache.d.ts.map