Connect a scoring endpoint
Let Kaimei explain a model it cannot run itself by calling an HTTPS endpoint you host.
When Kaimei cannot execute your model, give it an HTTPS endpoint that can. Kaimei POSTs rows in batches and reads predictions back, so explanations, analyses and predict all work, and your weights never leave your infrastructure.
- Expose an endpoint that accepts
{"instances": [row, …]}and returns{"predictions": [...]}, one entry per row (the contract). Any framework and language will do. - Register the model with
inference.type = "remote", the URL, and any header the endpoint needs. Headers are stored and never returned. - Upload reference rows so explanations have a population to compare against.
- Check the wiring with POST /v1/models/{model}/predict; a failing endpoint shows up as
502 upstream_errorwith the first bytes of its response indetails.
The endpoint must be reachable from the internet. For a model on your laptop, a tunnel such as cloudflared tunnel --url http://127.0.0.1:8765 gives you a public URL for the session.
# scoring.py: a minimal endpoint for an XGBoost classifier
from fastapi import FastAPI
import pandas as pd
app = FastAPI()
FEATURES = ["income", "credit_score", "utilization", "debt_to_income"]
@app.post("/predict")
def predict(body: dict):
frame = pd.DataFrame(body["instances"])[FEATURES]
p = booster.predict_proba(frame)[:, 1] # P(decline)
return {"predictions": p.tolist()}model = client.models.create(
name="Credit risk (XGBoost)",
task="binary_classification",
framework="xgboost",
features=[{"name": "income", "type": "numeric"}, {"name": "credit_score", "type": "integer"},
{"name": "utilization", "type": "numeric"}, {"name": "debt_to_income", "type": "numeric"}],
outputs={"labels": ["approve", "decline"], "positive_label": "decline"},
inference={"type": "remote", "url": "https://scoring.example.com/predict",
"headers": {"Authorization": "Bearer s3cr3t"}, "timeout_s": 10, "batch_size": 500},
)
client.models.upload_reference_data(model.id, rows=X_valid.to_dict("records"), labels=y_valid.tolist())
# smoke test: Kaimei calls your endpoint and logs the result
prediction = client.models.predict(model.id, input={"income": 72000, "credit_score": 681,
"utilization": 0.41, "debt_to_income": 0.38})
print(prediction.output) # {'label': 'decline', 'probability': 0.81, ...}