fromEnv

fun fromEnv(customName: String = "AI_API_KEY", onNotFound: (KeyNotFoundException) -> String? = null): ApiKey

Creates an ApiKey from an environment variable.

Return

An ApiKey instance.

Parameters

customName

The name of the environment variable to read. Defaults to "AI_API_KEY".

onNotFound

Optional fallback callback invoked when the environment variable is not set or empty. Receives the KeyNotFoundException and should return a fallback key. If null, the exception is thrown.

Throws

if the environment variable is not set or empty and onNotFound is null.