Retries

Some responses mean “not yet, try again” rather than success or failure. The SDK handles two of them for you, so a single call returns the result you asked for without bespoke retry code:

  • 429 Too Many Requests — you have exceeded the rate limit.
  • 202 Accepted — the output you requested is still being computed.

Both carry the server’s Retry-After header, and the SDK waits for it before trying again.

Rate limits

The pd4castr API rate limits requests per client. When you exceed the limit, the API returns HTTP 429 Too Many Requests with a Retry-After header.

ScopeLimit
Most endpoints60 requests / min
get_model_run_output120 requests / min

Limits are keyed to your API credentials, so they apply across every process using the same client ID. get_model_run_output has a higher allowance because ingestion loops call it once per run.

By default the SDK retries a 429 automatically, waiting for the Retry-After duration before retrying, up to three times. The max_retries client option changes the retry count, or set it to 0 to disable automatic retries:

from pd4castr_api_sdk import Client
 
client = Client(
    client_id="your-client-id",
    client_secret="your-client-secret",
    max_retries=0,
)

With retries disabled or exhausted, the SDK raises RateLimitError. It subclasses ApiError, and its retry_after attribute is the number of seconds to wait before retrying.

Computing output

If a model run has just finished executing, its output might still be processing. Requesting it then returns 202 Accepted with a Retry-After header until it is ready.

get_model_run_output and get_latest_model_run_output poll this for you, waiting for the Retry-After duration between attempts until the output is ready. No intermediate 202 reaches your code; you get the ModelRunOutputResult once it is available.

Polling is bounded by the poll_timeout client option (default 300 seconds). Raise it for runs you expect to take longer to materialise:

from pd4castr_api_sdk import Client
 
client = Client(
    client_id="your-client-id",
    client_secret="your-client-secret",
    poll_timeout=600,
)

If the output is still not ready when poll_timeout elapses, the SDK raises ApiError with a status_code of 202.

Next Steps

  • ReferenceClient options and exceptions