Skip to content

API reference

Client

polyjev.Polyjev

Typed, probabilistic decisions from any model.

model is the default model for calls that do not name one: a provider/model id ("anthropic/claude-opus-5", "vllm/Qwen/Qwen3-8B") or a name from config. config is a polyjev.yaml path, a dict or a :class:~polyjev.config.Config; $POLYJEV_CONFIG is read when omitted.

resolve(model=None)

The configuration that serves model (or the client's default).

jev-latest means the config's default_model, or the client's own model when the config has none.

backend(cfg)

The backend for cfg on the running event loop (created once per loop).

adecide(state, questions, *, model=None, images=(), instructions=None, samples='auto', auto_max=4, auto_threshold=0.1, think=0, ask=None, sequential=False, seed=42, strategy=None) async

Answer questions about state.

state is any JSON-able value or a string. images are :class:~polyjev.Image objects or file paths. The keyword options are Jev's request extensions (see the docs); strategy forces a read strategy for this call.

arun(spec, state, images=None, *, model=None, strategy=None) async

Run an already-validated :class:~polyjev.spec.DecisionSpec.

decide(state, questions, **kw)

Blocking :meth:adecide.

adecide_jev(body, images=()) async

Answer a Jev POST /v1/systemone request body (plus multipart images).

adecide_many(states, questions, *, concurrency=8, on_result=None, return_exceptions=False, **kw) async

Decide the same questions for many states, concurrency at a time.

on_result(index, decision_or_error) is called as each finishes (for progress bars). With return_exceptions=True a failed state yields its exception instead of aborting the batch.

aprobe(model=None) async

What the model supports and which strategy auto picks.

models()

Configured models and aliases (for GET /v1/models).

aclose() async

Close the backends created on the running loop.

close()

Close the sync API's loop thread and its backends.

polyjev.Remote

Decide through a remote /v1/systemone endpoint.

base_url is the server root (http://gpu-node:8011); the API key is sent as a bearer token.

adecide(state, questions, *, model=None, images=(), **extensions) async

Same arguments as :meth:polyjev.Polyjev.adecide (strategy is sent as an extension).

amodels() async

The server's GET /v1/models list.

aclose() async

Close the connection pool of the running event loop.

close()

Close the sync API's loop thread and its connections.

Questions

polyjev.Noul dataclass

Bases: _QuestionBase

A yes/no question. The answer is the probability of yes.

true and false optionally describe what yes and no mean.

polyjev.Choice dataclass

Bases: _QuestionBase

Pick one of several options.

options may be an Enum class (answers come back as its members), a list of strings or Enum members, or a mapping of option -> description.

polyjev.Score dataclass

Bases: _QuestionBase

A level on an ordered scale, listed from lowest to highest.

levels may be an Enum class (definition order is the scale order) or a list of names. The answer's expected is the probability-weighted level index (Jev's score).

polyjev.Span dataclass

Bases: _SpanBase

Extract one value from the state, copied exactly (an invoice id, a date, a name).

The answer's text is always a substring of the state's text; when the value is not there, found is false. start/end are character offsets into the state (a string state, or its "text" field, or else the JSON the model reads).

polyjev.Spans dataclass

Bases: _SpanBase

Extract every value of a kind from the state (all dates, all product names), in order.

polyjev.Image dataclass

An image attached to a decision. Images go ahead of the state in the prompt.

from_jev(value, index=0) classmethod

One entry of Jev's images array: a data URL or {content_type, base64}.

Answers

polyjev.Decision dataclass

Bases: Mapping[str, Answer | None]

The answers to one decision, keyed by question id.

A question skipped by ask_if (or left out by ask) maps to None.

to_jev()

The response body of POST /v1/systemone.

polyjev.NoulAnswer dataclass

p is the probability of yes; value is p >= 0.5.

polyjev.ChoiceAnswer dataclass

value is the most likely option (an Enum member when the question used one).

polyjev.ScoreAnswer dataclass

expected is the probability-weighted 0-based level index (Jev's score).

index/level/value describe the single most likely level.

polyjev.SpanAnswer dataclass

text is a substring of the state (state_text[start:end]), or None when not found.

polyjev.SpansAnswer dataclass

Every extracted value, in the order they appear in the state.

polyjev.Usage dataclass

Configuration

polyjev.config.load_config(source=None)

A :class:Config from a YAML path, a dict, an existing config, or $POLYJEV_CONFIG when nothing is given (an empty config otherwise).

polyjev.config.ModelConfig dataclass

How to reach one model.

Calibration

polyjev.calibration.CalibrationProfile dataclass

Per-question-type temperatures for one model.

polyjev.calibration.fit_profile(model, records, *, min_records=20)

Fit one temperature per question type.

A type keeps T = 1 when it has fewer than min_records records or no wrong answers; stats[type]["reason"] says which.

polyjev.calibration.metrics(records, t=1.0)

Extending

polyjev.register_backend(provider, factory)

Make provider/<model> ids resolve through factory.

polyjev.backends.base.Backend

Bases: ABC

Base class for model backends. Subclasses implement :meth:complete.

key property

Identity for capability caches: provider, endpoint and model.

complete(req) abstractmethod async

Run one chat completion.

label_logprobs(messages, labels, case_insensitive) async

Exact next-token log probabilities of each label, the probability mass on the labels, and the prompt token count. Only in-process backends.

probe() async

Find out whether top logprobs are available (sets capabilities.logprobs).

aclose() async

Release network clients.

polyjev.backends.base.Capabilities dataclass

What a backend can do. logprobs=None means unknown until probed.

Errors

polyjev.errors

Exceptions raised by polyjev.

The server maps them onto the same HTTP errors djev uses: SchemaError -> 422 validation_error, BackendError -> 502 server_error.

PolyjevError

Bases: Exception

Base class for every polyjev error.

SchemaError

Bases: PolyjevError, ValueError

The request or question schema is invalid.

ConfigError

Bases: PolyjevError

A model, alias or provider could not be resolved or configured.

UnsupportedFeature

Bases: PolyjevError

The backend cannot do what the request needs (e.g. images on a text-only model).

UnsupportedStrategy

Bases: UnsupportedFeature

The backend cannot run the requested read strategy (e.g. logprobs on Claude).

BackendError

Bases: PolyjevError

The model provider failed or returned something unusable.

RefusalError

Bases: BackendError

The model declined to answer (for example Claude's stop_reason == "refusal").