VaultApiKeyProvider

org.llm4s.llmconnect.auth.vault.VaultApiKeyProvider
See theVaultApiKeyProvider companion object
@Experimental

An ApiKeyProvider that reads the API key from HashiCorp Vault's key/value secrets engine over Vault's HTTP API (#2479), for a deployment that cannot run Vault Agent or a CSI driver to write the key to a file (apiKeyFile).

The key is read on the first current(), then reused for VaultSettings.refreshInterval, then read again, so a key rotated in Vault is sent from the first request after the interval. Concurrent callers share one read. A read that fails is a Left and is tried again on the next call; the last key is not served after its interval, since a rotated-out key may already be revoked.

for
 keys   <- VaultApiKeyProvider(VaultSettings(vaultAddress, Secret(vaultToken), "llm4s/openai", "apiKey"))
 config <- Llm4sConfig.provider("openai-main").map(_.withApiKeyProvider(keys))
 client <- LLMConnect.getClient(config)
yield client

Errors never hold the key or the Vault token: an AuthenticationError when Vault refuses the token (401, 403), a NotFoundError when there is no secret at the path, a ConfigurationError when the secret has no usable string field, a ServiceError for any other status, and the HTTP client's own error when Vault cannot be reached.

It depends on no Vault SDK: one GET with llm4s's own HTTP client. Close it to close the HTTP client it created; one passed to VaultApiKeyProvider(settings, httpClient) stays the caller's to close.

Attributes

Companion
object
Source
VaultApiKeyProvider.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def close(): Unit

Closes the HTTP client this provider created; one the caller passed in is left open.

Closes the HTTP client this provider created; one the caller passed in is left open.

Attributes

Definition Classes
Source
VaultApiKeyProvider.scala
override def current(): Result[ApiKey]

The key to send with the next request.

The key to send with the next request.

Attributes

Definition Classes
Source
VaultApiKeyProvider.scala
override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any
Source
VaultApiKeyProvider.scala