Expand description
Dynamic credentials for model providers.
A static API key is fine on a server, but an app running on a user’s device
must not ship a provider key inside its binary. Providers therefore accept a
CredentialSource, asked for a credential right before each request:
- bring-your-own-key: the host app reads the user’s key from the platform keychain / keystore;
- token broker: a backend issues short-lived, per-user tokens;
- static keys for servers and tests (
StaticCredential).
Sources are consulted per request. Wrap slow or rate-limited sources in
CachedCredentials, which caches until shortly before expiry and shares
one refresh between concurrent requests.
| Source | Use |
|---|---|
StaticCredential | Servers, tests. |
EnvCredentials | Servers: read the key from an environment variable at request time. |
FnCredentials | Hosts: any async closure (keychain lookup, custom auth). |
TokenBroker (feature http) | Apps: short-lived tokens from your backend. |
See docs/credentials.md for the threat model and the proxy pattern.
Structs§
- Cached
Credentials - Caches credentials per provider until shortly before they expire.
- Credential
- A credential to authenticate one request.
- EnvCredentials
- Reads keys from environment variables at request time (servers), so rotating the variable in a supervisor takes effect without rebuilding the registry.
- FnCredentials
- A
CredentialSourcebacked by an async closure, e.g. a keychain lookup. - Static
Credential - A fixed secret.
- Token
Broker - Fetches short-lived provider credentials from a broker endpoint.
- Token
Broker Config - Token broker settings.
Enums§
- Broker
Auth - How the app authenticates to the broker.
Constants§
- DEFAULT_
REFRESH_ SKEW_ MS - Credentials are refreshed this long before they expire (60 s).
Traits§
- Credential
Source - Supplies credentials on demand.
Functions§
- is_
secure_ endpoint - Whether
urlmay receive credentials:https://, orhttp://to a loopback / Android-emulator-host address (local development and tests only). - require_
secure_ endpoint - Validate an endpoint that will receive credentials.
- unix_
now_ ms - Current Unix time in milliseconds. On
wasm32-unknown-unknown, where there is no system clock, returns 0: credentials then never expire by time and are refreshed only throughCredentialSource::invalidate.