Catalogs and token counts¶
- protoverta.fetch_catalog(base_url, headers, policy=None, *, upstream_open=None)[source]¶
Fetch and validate a provider’s complete model catalog.
Redirects are refused so credentials never reach another host. Pages, models and bytes are bounded by
policy; returns aCatalog(models sorted by ID) or raisesCatalogError.
- class protoverta.Catalog(models=(), skipped=0, dropped_fields=0)[source]¶
-
Models from
fetch_catalog(), sorted by ID.A plain tuple of
ModelInfothat also reports what"skip"mode left out:skippedentries anddropped_fieldsof kept models.
- class protoverta.CatalogPolicy(pagination='none', max_pages=100, max_models=10000, max_bytes=8388608, timeout=30.0, path='/models', name_field='display_name', context_field=None, output_field=None, modalities_field=None, collection_field='data', id_field='id', query_params=(), page_param='page', total_pages_field='pagination.total_pages', first_page=1, current_page_field=None, invalid_entries='reject')[source]¶
Bases:
objectHow to read one provider’s model catalog: path, pagination, field names and size limits.
Defaults match the OpenAI-style
GET /modelslist. Token limits are only read whencontext_field/output_fieldname the provider’s fields.- Parameters:
pagination (str)
max_pages (int)
max_models (int)
max_bytes (int)
timeout (float)
path (str)
name_field (str)
context_field (str | None)
output_field (str | None)
modalities_field (str | None)
collection_field (str | None)
id_field (str)
page_param (str)
total_pages_field (str)
first_page (int)
current_page_field (str | None)
invalid_entries (str)
- class protoverta.ModelInfo(id, display_name, context_window_tokens=None, max_output_tokens=None, input_modalities=(), capability_status='unknown')[source]¶
Bases:
objectOne model from a provider catalog, with the limits and input modalities the provider itself reported.
- exception protoverta.CatalogError[source]¶
Bases:
ValueErrorA provider model catalog could not be fetched or failed validation.
- protoverta.count_input(config, body, source, *, upstream_open=None, budget=None)[source]¶
Return explicit count and provenance; unsupported media is never guessed.
- class protoverta.NativeTokenCounter(config, *, upstream_open=None)[source]¶
Bases:
objectCount input tokens with the provider’s own endpoint (Messages
count_tokensor Responsesinput_tokens); never an estimate.- Parameters:
config (GatewayConfig)
upstream_open (Callable[..., Any] | None)
- class protoverta.ModelTokenCounter(model, protocol, *, render_request, encode, exact=False)[source]¶
Bases:
objectExplicit local tokenizer/template plugin bound to one exact model/protocol.
The operator supplies a complete input renderer and encoder, including tool templates. Nothing is downloaded/imported dynamically. Exactness is asserted by that operator, never inferred from a tokenizer family or model spelling.
- protoverta.assess_context(body, protocol, limit, *, policy='estimate', counter=None)[source]¶
Byte-count heuristic is a labelled proxy, NOT a guaranteed upper bound.
Exact operator callbacks must cover the complete model-specific input, including tools/system/history/multimodal overhead. They are trusted code; this library never calls a count endpoint or downloads a tokenizer by default.
- class protoverta.ContextAssessment(input_tokens, reserved_output_tokens, context_window_tokens, exact, verdict, count_kind='utf8-json-byte-estimate')[source]¶
Bases:
objectThe result of a context-window preflight: counted input, reserved output, the model’s window and a verdict.
headers()renders it asX-Protoverta-Context-*response headers.