Skip to main content
Version: v1.4.1

Quickstart

End-to-end: deploy a trained model, score rows, and get a prescription.

1. Deploy and get a key

from xplainable_client import XplainableClient

client = XplainableClient(api_key="YOUR_API_KEY")

result = client.workflow.deploy_model(model_id)

deploy_key = result["deploy_key"]
endpoint = result["endpoint_url"] # https://inference.xplainable.io/v1/predict
sample = result["sample_payload"] # a template row in the model's expected shape

deploy_model deploys the version, activates it, and issues a deploy key in one call. The sample_payload shows exactly which fields the endpoint expects.

2. Predict

import requests

rows = [dict(sample[0], tenure_days=420, avg_order_value=86.5)]

resp = requests.post(
"https://inference.xplainable.io/v1/predict",
headers={"api_key": deploy_key},
json=rows,
)
for r in resp.json():
print(r["pred"], r.get("proba"), r["breakdown"][:3])

Every result carries an additive explanation breakdownbase_value plus one contribution per feature, summing exactly to the score.

3. Prescribe (v2 models)

Ask the model what to change — here, the best use of a 150-unit budget for one customer:

resp = requests.post(
"https://inference.xplainable.io/v1/optimize",
headers={"api_key": deploy_key},
json={
"row": rows[0],
"budget": 150,
"mutable_features": ["discount_applied", "avg_order_value"],
"cost_structure": {"discount_applied": 500, "avg_order_value": 2},
},
)
envelope = resp.json()
if envelope["status"] == "success":
res = envelope["results"]
print(res["optimal_features"], res["prediction"], res["total_cost"])
else:
print(envelope["error"]["code"], envelope["error"]["message"])

Always branch on the envelope's statussolver errors return HTTP 200.

4. Where to next