Reference
Errors
Every exception intura_ai raises, when each one happens, and what to do about it. A loaded model's predict raises none of them.
One base class
Everything this package raises descends from InturaError, so you can catch one class:
from intura_ai import Intura, InturaError
try:
model = Intura().models.load("chat-commerce-intent-id")
except InturaError as exc:
print(f"Could not get the model: {exc}")Only the API calls and the download raise these. Once a model is loaded, predict raises nothing from this list, because it runs in your process.
The ones you will meet
| Exception | When |
|---|---|
MissingAPIKey | A download was needed and no key is set |
AuthenticationError | The key is wrong or revoked |
NotFound | A model you don't own, or a version that doesn't exist |
RateLimited | Too many calls in a short time. Retried for you first, and retry_after says when to try again |
TransferError | Cloud Storage refused or dropped a file. Nothing was cached, so it's safe to retry |
APIConnectionError / APITimeoutError | The API could not be reached. A model already in the cache still loads |
Each message says what to do, not only what went wrong. MissingAPIKey, for example, shows both ways to set a key and links to your account page.
The rest of the family
Every error the API answered with a status code is an APIError. It carries status_code, message (the text the service wrote) and request_id, the string to quote when you ask for help.
| Exception | Status | When |
|---|---|---|
InvalidRequest | 400 | The request could not be read |
AuthenticationError | 401 | No key, an unknown key, or a revoked one |
PermissionDenied | 403 | A valid key that may not do this |
NotFound | 404 | A model you don't own, a version that doesn't exist, or a base_url with a path already on it |
InvalidParameters | 422 | A value is wrong; the message names the field |
RateLimited | 429 | Too many calls too quickly |
ServerError | 5xx | The service failed. Retried automatically before you see it |
APIConnectionError (and its subclass APITimeoutError) and TransferError are not APIErrors: the service never answered, or the file came from Cloud Storage rather than from Intura. TransferError has a status_code too, which is the bucket's.
Retries
The client retries connection errors, timeouts and 408, 429, 500, 502, 503 and 504 responses for you, up to max_retries times (2 by default), waiting between attempts (as long as the service's Retry-After asks, when it sends one). Seeing RateLimited or ServerError means those retries ran out. A request the service rejected for its content is never retried. See Configuration to change the count.
Errors outside the family
| Exception | When |
|---|---|
FileNotFoundError | LocalModel.load(path) was given a folder that isn't a downloaded model |
ValueError | load was given both version= and refresh=True, or a slug or version that isn't one |
TypeError | predict was given something other than a str, or predict_batch a single str |
Work offline when the API is down
A model already in the cache loads without the API. If asking for the newest version fails, fall back to the newest one you already have:
from intura_ai import APIConnectionError, Intura
client = Intura()
try:
model = client.models.load("chat-commerce-intent-id", refresh=True)
except APIConnectionError:
model = client.models.load("chat-commerce-intent-id") # the newest cached version