Front door¶
Four names. If you are publishing a model, this is the whole
API — Adapter declares it, @adapter.on_image is the model,
and InferCall is what each request arrives as. Everything
else on this site is for the adapter that outgrows them.
opennvr_adapter_sdk.Adapter
¶
Adapter(
adapter_id: str,
*,
version: str = "1.0.0",
vendor: str = "",
license: str = "",
tasks: Sequence[str] = (),
framework: str = "custom",
weights: str | PathLike[str] | None = None,
model_version: str | None = None,
model_card_url: str | None = None,
modalities_in: Sequence[str] | None = None,
modalities_out: Sequence[str] | None = None,
gpu: bool = False,
network_egress: Sequence[str] = (),
max_inflight: int = 1,
max_body_bytes: int = 8 * 1024 * 1024,
cost: Cost | None = None,
)
A whole AI adapter: identity, model, inference, lifecycle.
Construct one at module scope, decorate the model loader and the
inference handler, and expose :attr:app to your server. The six
contract endpoints, auth, correlation ids, Prometheus metrics, body
parsing, the failure envelope, the OpenAPI and AsyncAPI documents
and the lifespan are inherited from :class:~.adapter_app.AdapterApp.
Source code in opennvr_adapter_sdk/facade.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
fingerprint
property
¶
fingerprint: str
sha256 of the weights file, or a deterministic value derived from the adapter's identity when there is no file.
Never None: KAI-C's drift detection skips a null fingerprint,
so an adapter with one is silently exempt from the tamper check
that protects the operator.
service
property
¶
service: AdapterService
The :class:~.service.AdapterService this adapter compiles
to — anything that accepts one accepts this.
load
¶
load() -> Callable[[Callable[[], Any]], Callable[[], Any]]
Register the model loader, called once at startup.
Whatever it returns becomes call.model. Import heavy ML
libraries inside it, not at module top: a broken dependency then
shows up as a red /health with the real error message rather
than as a container that will not import.
Source code in opennvr_adapter_sdk/facade.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
on_image
¶
on_image(*tasks: str) -> Callable[..., Any]
The inference handler for an adapter that takes a frame.
call.image is the JPEG/PNG bytes, call.params the
caller's knobs, call.model what load() returned. Return
a list of :meth:InferCall.detection items, a result dict, or an
:class:~.contract.InferResponse for full control.
Source code in opennvr_adapter_sdk/facade.py
364 365 366 367 368 369 370 371 | |
on_audio
¶
on_audio(*tasks: str) -> Callable[..., Any]
The inference handler for an adapter that takes an audio clip
(call.audio).
Source code in opennvr_adapter_sdk/facade.py
373 374 375 376 | |
on_text
¶
on_text(*tasks: str) -> Callable[..., Any]
The inference handler for a text-in adapter (call.text);
no binary upload is parsed.
Source code in opennvr_adapter_sdk/facade.py
378 379 380 381 | |
on_data
¶
on_data(*tasks: str) -> Callable[..., Any]
The inference handler for any other binary payload
(call.data).
Source code in opennvr_adapter_sdk/facade.py
383 384 385 386 | |
check_hardware
¶
check_hardware() -> Callable[..., Any]
Override the derived hardware verdict.
Called with the loaded model; return a
:class:~.contract.HardwareEvaluationResponse, a
:class:~.contract.HardwareVerdict, a bool, or a
(verdict, reasoning) pair. Use it when the model has a real
requirement to test — a CUDA device, an NPU, enough RAM.
Source code in opennvr_adapter_sdk/facade.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
on_shutdown
¶
on_shutdown() -> Callable[..., Any]
Run on the way out, with the loaded model — release a device, close a session.
Source code in opennvr_adapter_sdk/facade.py
421 422 423 424 425 426 427 428 429 430 431 | |
on_stream
¶
on_stream() -> Callable[..., Any]
Implement the §6 WebSocket protocol yourself.
Declaring it advertises streaming in /capabilities and
publishes the protocol in the adapter's AsyncAPI document. The
handler is called with the raw WebSocket.
Source code in opennvr_adapter_sdk/facade.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
model_info
¶
model_info() -> ModelInfo
The /capabilities model block, derived from the
declaration and the handler that was registered.
Source code in opennvr_adapter_sdk/facade.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
run
¶
run(host: str = '0.0.0.0', port: int = 9000) -> None
Serve with uvicorn. Convenience for local runs; in a
container, point uvicorn at :attr:app directly.
Source code in opennvr_adapter_sdk/facade.py
551 552 553 554 555 556 | |
opennvr_adapter_sdk.InferCall
¶
InferCall(
payload: dict[str, Any], model: Any, adapter: "Adapter"
)
One inference request — what a handler is called with.
Flat on purpose: the binary payload is an attribute, the caller's
params are a dict, and the loaded model is right there. Anything the
facade does not model stays available as :attr:payload, which is
exactly what :meth:AdapterService.infer would have received.
Source code in opennvr_adapter_sdk/facade.py
135 136 137 138 139 140 141 | |
params
property
¶
params: dict[str, Any]
Everything the caller sent besides the binary body — the
adapter's own knobs, plus task and camera_id.
text
property
¶
text: str
The prompt or utterance, for a text adapter. Looks at the conventional keys before giving up.
param
¶
param(name: str, default: Any = None) -> Any
One caller param, with a default.
Source code in opennvr_adapter_sdk/facade.py
184 185 186 | |
detection
staticmethod
¶
detection(
label: str,
confidence: float,
x: float,
y: float,
w: float,
h: float,
*,
track_id: str | int | None = None,
**attributes: Any,
) -> dict[str, Any]
One §5.1 detection, in the shape every consumer expects.
Coordinates are NORMALIZED (0–1 of the frame) — the single most common thing to get wrong, and the reason a detection that looks right on the adapter shows up in the wrong place on the operator's screen. Divide pixel coordinates by the frame size.
Source code in opennvr_adapter_sdk/facade.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
opennvr_adapter_sdk.Overloaded
¶
Overloaded(
message: str = "Adapter is at capacity.",
*,
retry_after_ms: int = 1000,
)
Bases: Exception
Raise from a handler to shed load: a 503 with retry_after_ms.
The honest way to apply backpressure. KAI-C backs off and retries rather than treating the call as a model failure.
Source code in opennvr_adapter_sdk/facade.py
118 119 120 121 | |
opennvr_adapter_sdk.ServiceError
¶
ServiceError(
category: ErrorCategory,
*,
code: str,
message: str,
transient: bool,
http_status: int,
retry_after_ms: int | None = None,
)
Bases: Exception
Carries enough information to construct a §7 FailureEnvelope
without re-parsing exception strings in the FastAPI route.
Use prefix-namespaced codes (<adapter>.<code>) for adapter-
specific failure modes that aren't in §7.1's canonical set.
Source code in opennvr_adapter_sdk/service.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |