Skip to content

Errors

How the TwinCell REST API reports failures and how the deeplife SDK maps them to Python exceptions.

Authentication

Every request authenticates with the X-API-Key header. Authorization: Bearer … is not accepted and returns 401 (AuthenticationError). The SDK sets the header from api_key= / DEEPLIFE_API_KEY; you only supply it yourself when calling the REST routes directly.

curl -H "X-API-Key: $DEEPLIFE_API_KEY" \
  https://open-deeplife-api.deeplife.co/v1/predictions

REST error shape

Every non-2xx response includes a stable error_code in both the JSON body and the X-Deeplife-Error-Code header:

{"detail": "Human-readable message", "error_code": "rate_limited"}

Validation failures (422) may return structured detail arrays (Pydantic field errors) with error_code: validation_error (or dataset_validation_failed for TwinCell dataset checks).

Header Meaning
X-Deeplife-Error-Code Same value as body error_code
Retry-After Seconds to wait before retry (rate limits)
x-request-id / x-correlation-id Request id for support

The SDK builds typed exceptions from error_code alone. Server prose stays on message / detail for debugging — there is no client-side message-string table.

All SDK HTTP exceptions inherit from ApiError and expose:

  • error_code — from header or body
  • message / user_message — API detail text
  • status_code — HTTP status when available
  • retry_after_seconds — from Retry-After when present
  • debug_message — full diagnostic string for logs
from deeplife.twincell import (
    ForbiddenError,
    NotFoundError,
    QuotaExceededError,
    RateLimitError,
)

Enumerated error_code values

Generated from deeplife.twincell.http.error_codes. Every non-2xx API response includes the same value in the JSON body (error_code) and the X-Deeplife-Error-Code header.

error_code HTTP SDK exception Billable? Meaning
unauthorized 401 AuthenticationError No Missing or invalid credentials (API key or bearer token).
forbidden 403 ForbiddenError No Authenticated but not allowed for this action.
not_found 404 NotFoundError No Resource does not exist or is not visible to this caller.
invalid_request 400 ApiError No Malformed request (bad fields, mutually exclusive inputs).
invalid_dataset 400 ApiError No Uploaded dataset file is not a usable AnnData/h5ad payload.
validation_error 422 ValidationError No Request schema validation failed (Pydantic / FastAPI 422).
dataset_validation_failed 422 ValidationError No Dataset content failed TwinCell validation rules.
rate_limited 429 RateLimitError No Application rate limiter rejected the request (JSON 429). Distinct from edge/WAF HTML 403.
inflight_limit 429 InflightLimitError No Another prediction for this account is already in flight.
quota_exceeded 429 QuotaExceededError No Per-period prediction quota exhausted.
external_prediction_quota_exceeded 429 QuotaExceededError No Lifetime external prediction cap reached.
external_prediction_quota_disabled 429 QuotaExceededError No External prediction creates are disabled (cap is 0).
prediction_external_target_validation_only 403 ForbiddenError No External keys may only run target_validation jobs.
prediction_external_split_required 403 ForbiddenError No External accounts must submit split control/pert/degs uploads.
prediction_get_job_type_forbidden 403 ForbiddenError No This job type is not exposed on external GET.
causal_analysis_internal_only 403 ForbiddenError No Causal-analysis endpoint is restricted to internal accounts.
internal_error 500 ServerError No Unexpected server or worker failure.

Prediction / job outcome codes

Returned on GET /v1/predictions/{id} when status: failed (HTTP 200). Raise via status.raise_if_failed() → PredictionFailedError. Biological outcomes (degs_not_in_interactome, target_not_in_interactome, target_not_reachable) also surface as NoCausalPathError from study helpers.

error_code Billable? SDK exception Meaning
target_not_in_interactome No PredictionFailedError Target absent from the interactome (biological outcome).
degs_not_in_interactome No PredictionFailedError None of the submitted DEGs mapped onto the interactome.
target_not_reachable Yes PredictionFailedError Target is on the interactome but no causal path reaches it (billable biological outcome).
stale_job_timeout No PredictionFailedError Pending/processing job expired by the stale-job sweeper.

Regenerate the tables with:

uv run python scripts/generate_errors_md.py

Fallback when error_code is absent

Older responses or non-API layers may omit the code. The SDK then maps by HTTP status (401 → AuthenticationError, 404 → NotFoundError, 422 → ValidationError, 429 → RateLimitError, 5xx → ServerError, else ApiError).

Two kinds of 403

Not every 403 comes from the API. Check the body and the X-Deeplife-Error-Code header before acting:

Source Body error_code What it means
API policy JSON {"detail": …, "error_code": …} one of the policy codes above Your account or key tier may not do this. The request will never succeed as written — change the request (see Limits & quotas). Raised as ForbiddenError.
Edge / WAF HTML page None The request was blocked before reaching the API (per-IP edge rate limit). Nothing about your key, account, or payload is wrong.

The API's own rate limiter returns JSON 429 with error_code: rate_limited and optional Retry-After. An HTML 403 with no error_code comes from a layer in front of the API, not from the API itself; its cause has not been established.

Because an edge 403 is transient, the SDK retries it on GET-style calls (polling included) using the standard RetryConfig backoff. POST uploads are never retried, and a labelled policy 403 (ForbiddenError) fails immediately — it would never succeed. You therefore only see an edge 403 raised after the retries are exhausted.

At that point there is no JSON to parse, so the SDK raises a bare ApiError with status_code=403, error_code=None, and the generic message "API request failed"; the HTML is preserved on response_text.

from deeplife.twincell import ApiError

try:
    final = client.wait_for_prediction(prediction_id=prediction_id)
except ApiError as exc:
    if exc.status_code == 403 and exc.error_code is None:
        print(exc.debug_message)  # includes x-request-id for support

The observed pattern is an edge 403 on GET polling — the multipart upload POST succeeds and returns a prediction_id, then status polls start returning HTML 403 partway through the run. The prediction itself keeps running server-side; only your view of it is blocked.

If you hit this:

  • Do not treat it as an auth problem. The same key authenticates fine; the request was blocked at the edge before it reached the API.
  • Check your poll rate. The edge allows 30 requests per 60 s per IP, so the SDK's default poll_interval_seconds of 5 s uses about 40% of the budget. If you lowered it, or you have several waiters (or colleagues) sharing one IP, raise it — see Limits & quotas.
  • Re-read the result later with client.get_prediction(prediction_id=…) — the run completes regardless of the blocked polls. Reaching this error means the automatic retries were exhausted, which points at sustained pressure on the IP rather than a brief spike; the default budget (RetryConfig: 3 attempts, up to 8 s apart) covers a short block, not a full 60 s window.
  • Report it with the x-request-id from debug_message and the timestamp via Access & Support.

Failed predictions (status: failed)

wait_for_prediction() and watch_prediction() return a failed status rather than raising; call status.raise_if_failed() if you want a PredictionFailedError. The API body includes:

  • error_message — user-facing text (PredictionFailedError.message)
  • error_code — stable worker/API code when available (including stale_job_timeout for sweeper expirations)

status: failed covers two very different situations, and the error_code is what separates them.

Biological outcomes, not faults

Three worker codes mean TwinCell ran correctly and concluded that no causal result exists for your target and DEGs. Nothing is broken, and re-running the same inputs cannot produce a result. See the generated outcome table above (target_not_in_interactome, degs_not_in_interactome, target_not_reachable).

target_not_reachable is billable because the model did the work to reach that conclusion.

The API reports these as failed and then 404s every result route (mapped-degs, degs-impacted, causal-paths, causal-graph, intermediary-proteins), which at the HTTP layer is indistinguishable from an unknown prediction id. The SDK resolves that ambiguity for you: TwinCell.get_target_score(), get_all_degs(), get_degs_impacted_by_target(), get_causal_paths(), get_intermediary_nodes(), and plot_causal_graph() all raise NoCausalPathError, which states the conclusion in plain language.

from deeplife.twincell import NoCausalPathError

try:
    score = tc.get_target_score(prediction_id=prediction_id)
except NoCausalPathError as outcome:
    print(outcome.reason)       # why no result exists
    print(outcome.error_code)   # e.g. "target_not_reachable"
    print(outcome.target)       # e.g. "TYK2|PROTEIN"

NoCausalPathError is deliberately not an ApiError subclass, so a broad except ApiError around your workflow will not swallow a biological finding as though it were an infrastructure problem. To branch without catching, inspect the status directly:

status = client.get_prediction(prediction_id=prediction_id)
if status.is_biological_outcome:
    print(status.outcome_reason)

Genuine failures

A failed run with error_code: internal_error, stale_job_timeout, or an unrecognised code is a real fault — a worker crash, sweeper timeout, or internal error. These keep their original behaviour: result routes raise NotFoundError, and get_target_score() raises ValueError. error_detail carries the traceback for internal accounts.

Constants: ErrorCode, ERROR_TARGET_NOT_IN_INTERACTOME, ERROR_TARGET_NOT_REACHABLE, ERROR_DEGS_NOT_IN_INTERACTOME, BIOLOGICAL_PREDICTION_ERROR_CODES, NON_BILLABLE_PREDICTION_ERROR_CODES, is_billable().

Local (non-HTTP) errors

These are raised before or after HTTP and are not in the REST table above:

Exception When
NoCausalPathError The run reached a biological conclusion; no causal result exists (see above)
ValueError Missing target on create_prediction_split; missing session state (no prediction id, unknown target row, etc.)
TypeError Wrong argument types or missing required study inputs
FileNotFoundError Local .h5ad path missing (read_h5ad)
deeplife.twincell.validation.ValidationError Local split AnnData checks failed before upload
botocore.exceptions.ClientError S3 download errors when loading remote h5ad