juspay/hyperswitch · error · Error

Unsupported keyIdType: ${keyIdType}

Error message

Unsupported keyIdType: ${keyIdType}

What it means

Thrown by validateEnv in RequestBodyUtils when the baseUrl matched an environment but keyPrefixes[environment][keyIdType] is undefined. Only two keyIdType values are supported per environment: 'publishable_key' and 'key_id'; anything else (or a typo) throws with the offending value in the message.

Source

Thrown at cypress-tests-v2/cypress/utils/RequestBodyUtils.js:44

}

export function validateEnv(baseUrl, keyIdType) {
  if (!baseUrl) {
    throw new Error("Please provide a baseUrl");
  }

  const environment = Object.keys(keyPrefixes).find((env) =>
    baseUrl.includes(env)
  );

  if (!environment) {
    throw new Error("Unsupported baseUrl");
  }

  const prefix = keyPrefixes[environment][keyIdType];

  if (!prefix) {
    throw new Error(`Unsupported keyIdType: ${keyIdType}`);
  }

  return prefix;
}

View on GitHub (pinned to 9b8b89dc37)

Solutions

  1. Pass exactly 'publishable_key' or 'key_id' as keyIdType
  2. Check the value at the call site: log keyIdType before validateEnv to spot undefined/typo'd values
  3. If a new key type is genuinely needed, add it under each environment in keyPrefixes

Example fix

// before
const prefix = validateEnv(baseUrl, keyType); // keyType === 'publishable'

// after
const KEY_ID_TYPES = ['publishable_key', 'key_id'];
if (!KEY_ID_TYPES.includes(keyType)) {
  throw new Error(`keyIdType must be one of ${KEY_ID_TYPES.join(', ')} (got ${keyType})`);
}
const prefix = validateEnv(baseUrl, keyType);
Defensive patterns

Strategy: validation

Validate before calling

const KEY_ID_TYPES = ['publishable_key', 'key_id'];
if (!KEY_ID_TYPES.includes(keyIdType)) {
  throw new Error(`keyIdType must be one of: ${KEY_ID_TYPES.join(', ')} (got: ${keyIdType})`);
}
const prefix = validateEnv(baseUrl, keyIdType);

Type guard

/** @param {unknown} t @returns {t is 'publishable_key' | 'key_id'} */
function isKeyIdType(t) {
  return t === 'publishable_key' || t === 'key_id';
}

Prevention

When it happens

Trigger: Calling validateEnv(url, 'publishable') (truncated name), 'publishableKey' (camelCase), 'api_key', or undefined — the lookup returns undefined and the error names the exact input.

Common situations: Renaming the key id type on the app side without updating test utils; passing a config field that is optional and therefore undefined in some specs; copy-paste between suites that used different key types.

Related errors


AI-assisted analysis of juspay/hyperswitch@9b8b89dc37 (2026-08-16). Data as JSON: /api/errors/11ac21fee5c71668. Report an issue: GitHub.