facts

package
v0.0.0-...-53bd38a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package facts classifies which LLM provider a request went to, and gives the cache facts (accountant.EntryFacts) that provider's prompt cache has for a model. It is Cortex's own table, the host part of accountant/docs/cortex-wiring.md W6 (cortex-wiring.md's cached-prefix.md companion document is cited on each row). It matches the context-guru proxy's entryFacts (proxy/accountant_wire.go:229-246) exactly, minus the ping facts, which the caller in core/accounting applies on top.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func For

func For(p Provider, model string, allMarksAsk1h bool) accountant.EntryFacts

For returns the accountant.EntryFacts for provider p and model, given allMarksAsk1h — whether EVERY raw cache_control mark in the forwarded body asked for the 1h tier. It does not know about keep-alive pings; the caller in core/accounting applies those on top, as entryFacts' PingStore lookup does in the proxy.

The 1h tier needs every raw mark to ask 1h, which a merged accountant.Breakpoint cannot express: a position can merge a 5m mark and a 1h mark into one Breakpoint{TTL:"1h"}. So callers pass wire.AllMarksAsk1h(raw) over the raw forwarded body, and must not derive this bool from the Breakpoint slice wire.Parse returns.

Types

type Provider

type Provider int

Provider is the LLM provider a request went to, as far as Cortex's cache-facts table distinguishes them. It is Cortex's own enum: the proxy uses bifrost's bschemas.ModelProvider, which core/accounting does not import: Cortex does not depend on context-guru, and bschemas is a context-guru dependency, not a Cortex one.

const (
	ProviderUnknown   Provider = iota
	ProviderAnthropic          // Claude Messages API: explicit cache_control breakpoints, exact TTL
	ProviderOpenAI             // Chat Completions / Responses API: no breakpoints, provider-managed cache
)

func Classify

func Classify(path string) Provider

Classify says which provider's cache rules apply to a request, from its path alone. It uses wire.FormatOf, so this package and wire share one path table and cannot disagree. Like the proxy (explicitBreakpointProvider / modelinfo.HonoursCacheControl), it goes by the wire dialect, never by the hostname: a gateway that fronts several providers (LiteLLM, OpenRouter, Azure) still speaks one dialect, and the dialect decides the cache rules.

An unrecognized path is ProviderUnknown whatever the request's destination, even a host whose name contains "anthropic" or "openai", because a host name does not say which wire dialect the request uses.

A Chat or Responses body that carries cache_control marks (which Cortex's chat decoder, LiteLLM and OpenRouter accept for Claude models) still gets OpenAI cache facts (LifetimeUnknown), although wire.Parse finds its breakpoints. The proxy has the same gap.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL