API conventions
Errors, retries, idempotency and pagination for API integrations.
API environment
The API is served at https://api.spavik.co, which both SDKs use by default.
The request builder on each endpoint page calls the server declared in the
OpenAPI contract, with an API key sent in X-Spavik-Api-Key; see Authentication.
The engine and plan catalogues are public.
Each endpoint page includes request fields, response schemas and examples. Download the OpenAPI specification to import the contract into your own tools.
The error envelope
Errors from the API's routes share this shape.
{
"status": "error",
"message": "CREDITS_EXHAUSTED",
"messageDetail": "Not enough credits."
}message carries an uppercase machine code, to read in your code.
messageDetail carries a readable sentence, to show or to log. Never branch
your logic on messageDetail: it is prose, it can change.
The full list is on the Error codes page.
A path the API does not define is the exception: it answers 404 with
{"code":404,"message":"The current request is not defined by this API."}
and no X-Spavik-Request-Id. Check the method and the path.
The request_id
Every response from a route the API defines carries an X-Spavik-Request-Id
header. It is the only thing worth quoting if you open a ticket: it locates the
exact call in the logs.
Use the configured client and prediction inputs from Get started.
SDK exceptions expose the response identifier. For REST, save the headers
alongside the response body; MODEL_ID identifies your model and rows.json
contains the array of prediction rows. These examples make a billable call.
from spavik import SpavikError
try:
result = model.predict(rows)
print(result.request_id)
except SpavikError as error:
print(error.code, error.request_id)Idempotency
The engine mutations that support Idempotency-Key are POST /v1/models,
/predict, /outcomes, /refresh and POST /v1/forecast. Archive and
restore reach the same state however often they run, so they need no key.
A key is any string of up to 255 characters; a UUID is a good choice. A longer
key is refused with 400 IDEMPOTENCY_KEY_TOO_LONG.
A stored successful response is replayed without another computation or charge when you reuse the original endpoint, key and payload within the retention window (24 hours by default, starting with the original request). The key must be present on the original call. After a completed record expires, the same key can execute and charge again.
The same behavior applies to every data policy, including Zero Data Retention.
Successful responses are kept in a 24-hour technical cache for replay. Zero Data
Retention only disables the archiving of the inputs and outputs of evaluate,
backtest, forecast and predict; it does not change API bodies, parameters,
responses, outcome feedback or model refresh.
# The SDK creates a key and preserves it during this call's automatic retries.
result = model.predict(rows)
print(result.predictions)Use a unique key per logical call and preserve it across attempts. The SDKs
do this for automatic retries; a fresh SDK call generates a new key unless you
pass the original one (idempotency_key in Python, idempotencyKey in
JavaScript) to train, predict, forecast, outcome submission or refresh.
| Response | What to do |
|---|---|
REQUEST_IN_PROGRESS | The original call is still active. Wait as directed by Retry-After; retain the original key and payload. |
IDEMPOTENCY_KEY_REUSED | The key was used with different input. Check the original request. |
REQUEST_INTERRUPTED | The outcome is uncertain. Stop automatic retries, keep X-Spavik-Request-Id, inspect the request log or contact support. |
IDEMPOTENCY_RESPONSE_UNAVAILABLE | The operation may have completed but its response could not be saved. Contact support with X-Spavik-Request-Id. |
After an uncertain outcome, do not force execution with a new key: an error or lost response does not prove that no charge occurred. Unresolved records remain protected rather than expiring like stored successes. See Costs and credits for the billing implications.
Pagination
Lists use one of two styles.
| Route | Style | Default limit | Maximum |
|---|---|---|---|
GET /v1/models | limit and offset | 50 | 200 |
GET /v1/requests | limit and cursor | 100 | 500 |
GET /v1/models returns its page in data and a pagination object:
{
"data": [],
"pagination": { "total": 0, "limit": 50, "offset": 0, "has_more": false }
}GET /v1/requests returns its calls in requests, most recent first, with a
next_cursor. Pass that value as cursor, with the same from, to and
status, to read the next, older page. next_cursor is null on the last page.
The libraries cover only models: models() is an iterator that fetches pages as
it goes. Its limit sets the page size, capped at 200, and the iterator walks
every page whatever its value.
for model in spavik.models(limit=50):
print(model.id)Time windows
Routes that read history take one of two kinds of window.
| Route | Window |
|---|---|
GET /v1/usage | from and to, ISO 8601 dates |
GET /v1/requests | from and to, ISO 8601 dates; 7 days by default, 30 at most |
GET /v1/models/{id}/performance | days, a rolling window: 30 by default, 365 at most |
GET /v1/requests additionally accepts status=error, which keeps only
failures: enough to track down a rejection that happened in production without
reproducing it.
Retries
Read the error code and the contract's x-retry-policies. Retry-After, when
present, supplies a delay; it does not by itself make a mutation safe to replay.
Retain the original Idempotency-Key and payload for retries, and handle
uncertain outcomes as described in Idempotency.
CREDITS_EXHAUSTED requires credits or a plan change before retrying. See
Error codes.
Rate limits
The /v1 engine routes apply no per-key request rate today; the
plan limits still apply.
Identifiers
They are opaque and prefixed. Do not parse them, do not rebuild them.
| Prefix | Object |
|---|---|
mdl_ | model |
ver_ | model version |
req_ | request: a prediction's request_id, or the X-Spavik-Request-Id header |
ws_ | workspace |
whk_ | webhook |
evt_ | webhook event |
API keys start with sk-spv-api-. They are secrets, not identifiers: never log them.
Dates
Use ISO 8601 timestamps and normalize time zones consistently. Evaluation protocol timestamps are UTC; engine protocol v2 can omit the timezone suffix.
How is this guide?
Last updated on