diegosouzapw/OmniRoute · error

[KeyRotator] Skipping invalid primary key for connection

Error message

[KeyRotator] Skipping invalid primary key for connection ${connectionId.slice(0, 8)}

What it means

Key-rotator notice in getValidApiKey: the connection's primary API key is present but its health entry (or a freshly created one) is marked status "invalid", so it is excluded from the candidate list and an extra key (or none) is used instead. Fires whenever a key previously failed validation and has not been rehabilitated.

Solutions

  1. Replace the primary key in the connection settings with a valid credential.
  2. Reset the key's health status after verifying it works (e.g. after fixing quota/billing) so the rotator stops skipping it.
  3. Ensure extraKeys are populated so traffic continues while the primary is invalid.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at open-sse/services/apiKeyRotator.ts:117 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/6dfe293761cf3c34. Report an issue: GitHub.

Appendix: source

Thrown at open-sse/services/apiKeyRotator.ts:117

 */
export function getValidApiKey(
  connectionId: string,
  primaryKey: string,
  extraKeys: string[] = [],
  health?: Record<string, KeyHealth>
): { key: string; keyId: string } | null {
  const validExtras = extraKeys.filter((k) => typeof k === "string" && k.trim().length > 0);

  // Build list of all keys with their IDs
  const allKeys: Array<{ key: string; keyId: string }> = [];

  // Add primary key if valid
  if (primaryKey) {
    const primaryHealth = health?.["primary"] || getOrCreateHealth(connectionId, "primary");
    if (primaryHealth.status !== "invalid") {
      allKeys.push({ key: primaryKey, keyId: "primary" });
    } else {
      console.warn(
        `[KeyRotator] Skipping invalid primary key for connection ${connectionId.slice(0, 8)}`
      );
    }
  }

  // Add extra keys if valid
  for (let i = 0; i < validExtras.length; i++) {
    const keyId = `extra_${i}`;
    const keyHealth = health?.[keyId] || getOrCreateHealth(connectionId, keyId);
    if (keyHealth.status !== "invalid") {
      allKeys.push({ key: validExtras[i], keyId });
    }
  }

  if (allKeys.length === 0) return null;
  if (allKeys.length === 1) {
    return { key: allKeys[0].key, keyId: allKeys[0].keyId };
  }

View on GitHub (pinned to a179ffed5b)