Skip to main content

Module capability_check

Module capability_check 

Source
Expand description

Capability and context-window guard for the routing / failover path.

RequiredCapabilities is derived from a ChatCompletionRequest and checked against a candidate model’s ModelInfo before a route rewrite or failover dispatch is committed. The check is intentionally permissive:

  • When ModelInfo is unknown for a candidate (not in the registry catalog) we allow it through — we only skip when we positively know a capability is missing.
  • A capability that the request needs but the model info does not list causes the candidate to be skipped (the caller emits a tracing event and tries the next candidate or falls back to the original model).

§Token counting

[estimate_input_tokens] concatenates all message text and delegates to [tt_tokenize::estimate_tokens], keyed on provider_id so tiktoken is used for OpenAI/Anthropic and the char/4 heuristic is used elsewhere. Image/audio bytes are not measured — the guard is a best-effort floor, not an exact window-packing count.

Structs§

RequiredCapabilities
The set of capabilities a ChatCompletionRequest requires.

Functions§

message_text_for_estimation
Concatenate all message text parts from a request for token estimation.
request_has_audio
True when any message carries an audio (ContentPart::InputAudio) content part.
request_has_images
True when any message carries an image (ContentPart::ImageUrl) content part.
request_input_text
Concatenated text of the user + system messages — the caller-controlled input, used for content/topic routing. Assistant/tool turns are excluded so a model’s own output can’t spuriously trigger a topic route.