Make your code production-ready
1from lynx import LYNX, LYNXAuthError, LYNXLicenseError, LYNXFormatError, LYNXIntegrityError2 3try:4 model = LYNX("lynx-basic", key="LICENSE_KEY")5 results = model("frame.jpg")6except LYNXAuthError:7 # Invalid / rejected key. (A missing key is NOT this — no key8 # activates demo mode automatically for 30 days.)9 print("Check your LYNX_API_KEY")10except LYNXLicenseError as e:11 # Demo expired (no key, 30 days up), license expired, or cert12 # outside validity window. str(e) is the spec verdict —13 # "LicenseExpired" / "CertFromFuture" / ...14 print(f"License problem: {e}")15except LYNXIntegrityError as e:16 # Tamper detection fired. Do NOT continue; treat as untrusted.17 print(f"Artifact has been modified: {e}")18except LYNXFormatError as e:19 # Re-download might fix; underlying file is corrupt or mid-version.20 print(f"Artifact unreadable: {e}")LYNX exceptions are typed for a reason: each maps to a different operator response. A wrong key needs the user to fix their config; an expired license needs a renewal flow; a corrupt artifact needs a re-download; tamper detection needs the file quarantined. Logging "something went wrong" with except Exception throws away the signal that tells you which is which.
str(e) returns the spec §5 verdict name — strings like "LicenseExpired", "BadCertSignature", "CertFromFuture". These are stable across SDK versions, regex-friendly, and grep-friendly when you're triaging logs. Log the string; alert on the class.
LYNXIntegrityError deserves special handling: it means the artifact bytes don't match the signed hash, which means somebody modified the file after signing. Don't catch-and-continue. Drop the file, refuse to load, alert.
Catch LYNXError at the top of your retry loop if you want a single "log everything" catch — every LYNX exception inherits from it.