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

SDKException

Codes worth handling

Factory methods

The companion object builds typed exceptions, which is what the SDK itself throws and what you can throw from your own tool executors:
unsupportedCapability is the one you will meet in practice: it is what generateStructured(mode = CONSTRAINED) throws.

Reacting to specific codes

Errors from a Flow

Failures surface at the collector, so wrap the collection:
catch from the Flow API works too:

Cancellation

Cancelling the coroutine cancels the generation. That arrives as CancellationException, which you must not swallow: rethrow it, or use catch from the Flow API, which already lets it through.

Reporting

telemetryProperties is already shaped for a reporting call, with the code, category, and context attached.