Dyno Phi
ContentsErrors and retriesShow

Errors and retries

Handle a failed request, retry it safely, and find out why a run stopped.

Failed requests

When a request fails, the client raises an error that carries the HTTP status and the response body. The body names the field or ID that caused the problem, so read it before you try again.

A 422 body is a detail list with one entry for each problem: loc says where the field is, msg says what is wrong with it, and type names the kind of error.

StatusPython errorWhat to do
400PhiErrorCheck the request format.
401PhiAuthErrorSign in again or check your API key.
402PhiInsufficientCreditsErrorAdd credits, then submit again.
403PhiAuthErrorCheck your organization and permissions.
404PhiNotFoundErrorCheck the ID and which organization owns it.
409PhiConflictErrorResolve the conflict named in the response.
422PhiValidationErrorFix the field named in the response.
429PhiRateLimitErrorWait for the time in Retry-After, then try again.
500PhiServerErrorTry again later.
502PhiServerErrorTry again later.
503PhiServerErrorTry again later.
504PhiServerErrorTry again later.
python
from phi import PhiClient, PhiInsufficientCreditsError, PhiRateLimitError

with PhiClient() as phi:
    try:
        job = phi.jobs.submit("ESMFOLD", inputs={"sequences": [sequence]})
    except PhiInsufficientCreditsError:
        print("add credits, then submit again")
    except PhiRateLimitError as err:
        print("wait", err.retry_after, "seconds")

Retries

The client retries a read (GET, HEAD, or OPTIONS) on its own after a 429, 500, 502, 503, or 504, up to 3 more times. It waits 0.5 seconds before the first retry and doubles the wait each time. If the response has a Retry-After header, it waits that long instead, up to 30 seconds.

The client does not automatically retry a submit. Save an explicit idempotency key and the returned job ID. If the response never arrived, inspect Work or recent jobs before replaying the request. When Phi already has a run for the key, it normally returns that run, with the exceptions below.

The key prevents a duplicate, not a rerun of work that failed. If the job for that key ended as FAILED, Phi releases the key, so the next submit with it starts a new job. If that job was deleted, Phi refuses the submit with 409; restore the run or submit without the key.

bash
KEY=$(uuidgen)
phi jobs submit ESMFOLD \
  --input sequences=@peptide.fasta \
  --idempotency-key $KEY
python
from uuid import uuid4
from phi import PhiClient

key = str(uuid4())  # Keep this key when retrying the same submission.
with PhiClient() as phi:
    job = phi.jobs.submit("ESMFOLD", inputs={"sequences": ["NLYIQWLKDGGPSSGRPPPS"]}, idempotency_key=key)

Safe automation

Failed runs

A run that stops early carries an error_code that says why and a recommended_action that says what to do. To see both from the command line, run phi --json jobs status with the run's ID.

The table lists the codes you can act on. A run can also stop with a code that is not listed here.

CodeWhat it meansWhat to do
OOMThe model ran out of memory.Try a smaller input.
VALIDATIONPhi rejected the input.Fix the input named in the error, then submit again.
QUOTAThe organization ran out of credits.Add credits, then submit again.
TIMEOUTThe run took longer than Phi allows.Try a smaller request.
CANCELLEDThe run was cancelled.Submit again if you still need the result.