ApiKeyRing class final
A rotating view over one provider's API-key stack.
Not synchronized: the harness drives agents single-threaded per run, and backoff timestamps make cross-run sharing benign.
Constructors
-
ApiKeyRing({required String baseName, required List<
ApiKeyCredential> credentials, int? startIndex, DateTime now()?}) -
Creates a ring over
credentials(must be non-empty), starting at a round-robin offset forbaseNameunlessstartIndexpins one (tests).
Properties
- availableCredential → ApiKeyCredential?
-
The affinity credential: the current position unless it is in backoff,
in which case the next non-benched credential (round-robin order).
nullwhen every credential is benched.no setter - baseName → String
-
The secrets-store base name this ring rotates (e.g.
OPENAI_API_KEY).final - currentCredential → ApiKeyCredential
-
The credential at the current position, ignoring backoff.
no setter
- earliestBackoffEnd → DateTime?
-
The earliest moment any benched credential frees up, or
nullwhen no credential is in backoff. Used to wait out a fully benched stack (omp's sibling-credential wait).no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- length → int
-
The number of credentials in the stack.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
isInBackoff(
String name) → bool -
Whether
nameis benched right now. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reportRateLimited(
String name, Duration backoff) → void -
Benches the credential
nameforbackofffrom now. -
rotate(
String from) → ApiKeyCredential? -
Advances the affinity position past
fromto the next non-benched credential (round-robin), returning it;nullwhen all are benched. -
stickTo(
ApiKeyCredential credential) → void -
Advances the affinity position to
credential(session affinity: a switched key stays current until it fails). -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
fromSecrets(
Map< String, String> secrets, String baseName, {int? startIndex, DateTime now()?}) → ApiKeyRing? -
Builds a ring from
secretsforbaseName; returnsnullwhen the stack is empty (no key configured).