Skip to main content

Inference API Overview

Every deployed model gets a REST endpoint for real-time scoring. Deployments of v2 (XGM) models additionally expose a suite of prescriptive endpoints — optimization, counterfactuals, and portfolio budget allocation — that answer "what should we change?" rather than just "what will happen?".

Base URL​

https://inference.xplainable.io/v1

Authentication​

All requests are authenticated with a deploy key passed in the api_key header:

api_key: <your-deploy-key>

Deploy keys are scoped to a single deployment and have an expiry date. Create one from the Python SDK:

# One-shot: deploy + activate + key in a single call
result = client.workflow.deploy_model(model_id)
deploy_key = result["deploy_key"]

# Or step by step
deployment = client.deployments.deploy(model_version_id=version_id)
client.deployments.activate_deployment(deployment.deployment_id)
deploy_key = client.deployments.generate_deploy_key(
deployment_id=deployment.deployment_id,
description="production scoring",
days_until_expiry=90,
)

Keys can be revoked at any time with client.deployments.revoke_deploy_key(deployment_id, key_id).

Endpoints​

EndpointMethodModelsPurpose
/predictPOSTv1 + v2Score rows, with additive explanation breakdowns
/optimizePOSTv2 onlyBudget-constrained optimization for a single row
/optimize/batchPOSTv2 onlyBatch optimization over many rows
/counterfactualPOSTv2 onlyMinimal-cost changes to reach a desired outcome
/portfolioPOSTv2 onlyAllocate one shared budget across many rows

v1 vs v2: /predict serves every deployment. The four prescriptive endpoints require a v2 (XGM) deployment and return 400 Bad Request when called against a v1 model.

Preprocessing​

If a preprocessing pipeline is attached to the deployment, it is applied automatically to /predict requests before scoring — send raw rows in the same shape as your source data. Preprocessing is not applied on the prescriptive endpoints; they expect rows in the model's fitted feature space.

IP allowlisting​

Deployments can optionally restrict access to an IP allowlist (managed in the platform UI). Requests from other addresses receive 403 Forbidden.

Error responses​

Transport and validation errors use standard HTTP status codes with a detail message:

StatusMeaning
401Invalid or malformed deploy key
403IP not allowed, or the deployment is not active
404Deployment no longer exists
400Prescriptive endpoint called on a non-v2 deployment
422Input doesn't match the model signature, or a required field is missing
500Internal server error

The prescriptive endpoints additionally return a result envelope — a solver failure (e.g. an intractable constraint combination) comes back as HTTP 200 with "status": "error" in the body. Always branch on the envelope's status field. See Optimization — the result envelope.