API Errors
Since the Tinfoil SDK wraps the OpenAI client, standard API errors (AuthenticationError, RateLimitError, etc.) pass through unchanged. The SDK re-exports them so you can import and catch them directly. See the OpenAI error documentation for details.
Example: handling an AuthenticationError
Example: handling an AuthenticationError
Quota errors
Requests that exceed a spending or usage limit returntype and code set to insufficient_quota. The HTTP status tells you which limit was hit:
Per-key caps are lifetime totals set by an admin; see Create API Key. A
429 from a per-key cap is not transient, so retrying will not help. Raise or clear the cap with Update API Key, or use a different key.
Both kinds of limit are evaluated against usage that has already been recorded. Requests still in flight when a limit is reached complete and are billed, and new requests start failing a few seconds later. See How usage is recorded.
Client Errors
The SDK verifies attestations, pins certificates, and encrypts payloads before any data leaves your machine. It retries transient failures automatically, but errors that persist will surface to your code as one of three typed errors.TinfoilError, which extends the native Error class. Each error includes a message string and an optional cause property containing the underlying error.
The
tinfoil package does not export FetchError. Catch it as TinfoilError, or check err.name === "FetchError".
In practice, you typically only need to distinguish ConfigurationError (a bug in your code) from transient errors: