Skip to main content
Everything the SDK throws is an SDKException. It carries a proto-backed error underneath, so the same code and category cross every language binding.

SDKException

It conforms to LocalizedError, so errorDescription and failureReason work with standard SwiftUI error presentation.

Codes worth handling

Reacting to specific codes

isExpected

Some failures are routine rather than bugs: a cancelled generation, a permission the user declined. isExpected separates the two, which is what you want before deciding whether to log something as an error.
log() writes the exception through the SDK logger with the call site attached.

Where errors arrive in streams

For streaming calls, the try await on the call itself covers preflight: no model available, bad options. A failure during generation is thrown into the stream. Both need catching, and a single do around the whole loop does it:

Cancellation

Cancelling the enclosing Task stops a stream. That surfaces as .cancelled, which is expected rather than a failure.

Presenting to a user