flightrisk.serving¶
- class flightrisk.serving.schemas.ScoreRequest(*, customer_id=None, features)[source]¶
Bases:
BaseModelPer-customer feature payload submitted for scoring.
- Parameters:
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class flightrisk.serving.schemas.BatchScoreRequest(*, track, run_id=None, horizon_days=None, items)[source]¶
Bases:
BaseModelBatch payload of multiple
ScoreRequestitems.- Parameters:
track (Literal['risk', 'survival', 'uplift']) – Which track to score with.
run_id (str | None) – Optional run id to pin a specific model version.
horizon_days (int | None) – Required when
track == "survival".items (list[ScoreRequest]) – Per-customer feature payloads.
- track: Literal['risk', 'survival', 'uplift']¶
- items: list[ScoreRequest]¶
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class flightrisk.serving.schemas.ScoreResponseItem(*, customer_id, score)[source]¶
Bases:
BaseModelOne row of the scoring response.
- Parameters:
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class flightrisk.serving.schemas.BatchScoreResponse(*, track, run_id, score_meaning, scores)[source]¶
Bases:
BaseModelBatch scoring response.
- Parameters:
track (Literal['risk', 'survival', 'uplift']) – Track that produced the scores.
run_id (str) – Run id of the model that served the request.
score_meaning (str) – Human-readable description of what
scoremeans.scores (list[ScoreResponseItem]) – One
ScoreResponseItemper request item.
- track: Literal['risk', 'survival', 'uplift']¶
- scores: list[ScoreResponseItem]¶
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class flightrisk.serving.schemas.HealthResponse(*, status='ok', loaded)[source]¶
Bases:
BaseModelLiveness check response.
- Parameters:
- status: Literal['ok']¶
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class flightrisk.serving.registry.LoadedModel(track, run_id, model, feature_names)[source]¶
Bases:
objectMetadata for a model loaded into the in-process registry.
- Parameters:
- class flightrisk.serving.registry.ModelRegistry[source]¶
Bases:
objectThread-safe in-memory registry that lazily loads track artifacts.
The registry resolves paths under
reports/<track>/and caches the most recently loaded artifact for each track. Concurrent requests reuse the same instance so reloads only happen when the chosen run id changes.- get(track, run_id=None)[source]¶
Return a loaded model for
track, loading from disk on first use.- Parameters:
- Returns:
A
LoadedModelready for inference.- Raises:
FileNotFoundError – If the artifact is missing.
- Return type:
- flightrisk.serving.registry.get_registry()[source]¶
Return the process-wide
ModelRegistryinstance.- Returns:
The shared registry singleton.
- Return type:
- flightrisk.serving.api.health(request)[source]¶
Return liveness information and the currently cached models.
Excluded from rate-limiting so liveness checks always succeed.
- Parameters:
request (Request) – The incoming request, required by slowapi’s signature.
- Returns:
A
HealthResponsepayload.- Return type:
- flightrisk.serving.api.score(request, payload, api_key=Depends(dependency=<function require_api_key>, use_cache=True, scope=None))[source]¶
Score a batch of customers with the requested track.
Protected by the
X-API-Keyheader (whenFLIGHTRISK_API_KEY/FLIGHTRISK_API_KEYSis set) and rate-limited per client IP.- Parameters:
request (Request) – The incoming request, required by slowapi.
payload (BatchScoreRequest) – A
BatchScoreRequestpayload.api_key (str) – The validated API key (or sentinel when auth is disabled).
- Returns:
A
BatchScoreResponsewith per-customer scores.- Raises:
HTTPException – When the model artifact is missing or invalid.
- Return type: