LLM cache
llmcache.LlmCacheMode
How CachingTransport treats each request against the store.
Usage
llmcache.LlmCacheMode()llmcache.LlmCacheSettings
The [llmcache] section: default cache mode and key schema version.
Usage
llmcache.LlmCacheSettings()llmcache.CachingTransport
Record/replay layer keyed on sha256(schema_version, method, scheme, host, port, path, sorted-query, body).
Usage
llmcache.CachingTransport(
inner,
mode,
schema_version,
db_path,
lock=anyio.Lock(),
stack=AsyncExitStack(),
store=None
)Headers are excluded from the key by design (auth and session noise never perturb replay), and only 2xx responses are recorded. Streaming responses are fully buffered: the body is read into memory before it is stored. The sqlite store lives under load(AthomeSettings).cache_root / "llmcache" / "llmcache.db" and opens lazily on the first request, closing when the transport does.
Parameter Attributes
inner: httpx.AsyncBaseTransportmode: LlmCacheModeschema_version: intdb_path: Pathlock: anyio.Lock = anyio.Lock()stack: AsyncExitStack = AsyncExitStack()store: Store | None = None
llmcache.RetryTransport
Retries 429/5xx/transport errors with capped exponential backoff (default 3 tries).
Usage
llmcache.RetryTransport(inner)Parameter Attributes
inner: httpx.AsyncBaseTransport
llmcache.transport()
Build the record-replay transport stack for an httpx.AsyncClient.
Usage
llmcache.transport(*, mode=None)Parameters
mode: LlmCacheMode | None = None-
The cache mode;
NonereadsLlmCacheSettings.mode.
Returns
httpx.AsyncBaseTransport-
RetryTransport when the mode isCachingTransport(RetryTransport(httpx.AsyncHTTPTransport())), or a bareLlmCacheMode.BYPASS.
Example
>>> AsyncOpenAI(http_client=httpx.AsyncClient(transport=transport()))llmcache.LlmCacheMiss
Raised in LlmCacheMode.REPLAY when a request has no recorded response.
Usage
llmcache.LlmCacheMiss()