Menu: Endpoint API

API builder

Endpoint API

Reference for calling published endpoints at www.scalaix.com/<project>/<collection>/<endpoint>.

Calling an endpoint

POST https://www.scalaix.com/<project>/<collection>/<endpoint>[?version=<n>]
Authorization: Bearer sx_...
Content-Type: application/json

version is optional; the latest published version answers by default. The key must allow the endpoints mode and, if it lists collections, this collection.

Request body

{
  "inputs": { "ticket": { "subject": "Charged twice", "body": "..." } },
  "options": { "model": null, "cache": true }
}
FieldNotes
inputsRequired. The endpoint's variables. See Variables and templates.
options.modelOptional. Run with another catalog model (subject to the key's allowed models). null uses the endpoint's model.
options.cacheOptional. false skips the cache for this call.

The body can be up to 1 MB.

Response 200

{
  "data": { "category": "bug", "priority": 4, "tags": ["login"] },
  "model": "gpt-4o-mini",
  "version": 3,
  "cached": false,
  "usage": { "input_tokens": 312, "output_tokens": 41, "cost_usd": 0.00012 },
  "request_id": "req_8f2c41d07a"
}
FieldNotes
dataParsed JSON (format json), a string (text, xml) or {"columns", "rows"} (csv). An array of those when the endpoint has variations above 1.
modelThe model that answered, after fallback.
versionThe version that ran.
cachedtrue when the answer came from cache.
usageTokens and cost of this call.
request_idSame as the X-Scalaix-Request-Id header.

The response also carries the X-Scalaix-Model, X-Scalaix-Cache and X-Scalaix-Fallbacks headers described in the Gateway API.

Errors

StatustypeWhen
400invalid_requestThe body isn't JSON or has no inputs.
401invalid_api_keyMissing, unknown, revoked or expired key.
402insufficient_quotaOut of credits, or the key's budget is spent.
403forbiddenThe key doesn't allow endpoints, this collection, this origin or IP.
404not_foundUnknown project, collection, endpoint or version, or nothing published yet.
413invalid_requestThe body is over 1 MB.
422invalid_inputsInputs don't match the variables. The message has the path: inputs.ticket.subject: required.
429rate_limitedOver the key's requests per minute. See Retry-After.
501not_implementedThe endpoint uses a file variable (not available yet).
502upstream_errorThe model failed and no fallback succeeded.
502invalid_model_outputThe answer didn't match the output schema after one repair attempt.
504timeoutThe model didn't answer in time.

Examples

import os, requests

resp = requests.post(
    "https://www.scalaix.com/acme/support/classify-ticket",
    headers={"Authorization": f"Bearer {os.environ['SCALAIX_API_KEY']}"},
    json={"inputs": {"ticket": {"subject": "Charged twice", "body": "Billed two times in March."}}},
    timeout=60,
)
if resp.status_code == 422:
    print("Fix the inputs:", resp.json()["error"]["message"])
resp.raise_for_status()
print(resp.json()["data"])
const res = await fetch("https://www.scalaix.com/acme/support/classify-ticket?version=3", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.SCALAIX_API_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({ inputs: { ticket: { subject: "Charged twice", body: "Billed two times in March." } } }),
});
const body = await res.json();
if (!res.ok) throw new Error(`${body.error.code}: ${body.error.message}`);
console.log(body.data.category, body.data.priority);

Every published collection also has generated docs with examples built from its own variables: https://www.scalaix.com/<project>/<collection>.