trpc/trpc · error · Error

Unsupported version: ${version}

Error message

Unsupported version: ${version}

What it means

`getPlanner(event)` selects a processor based on the API Gateway payload format version. `determinePayloadFormat` returns `'1.0'` when `event.version` is undefined (REST APIs, implied 1.0) and otherwise returns `event.version` verbatim. The switch handles `'1.0'` and `'2.0'` (HTTP APIs); any other value falls through to `default` and throws.

Source

Thrown at packages/server/src/adapters/aws-lambda/getPlanner.ts:228

      await pipeline(Readable.fromWeb(response.body as any), responseStream);
    } else {
      responseStream.end();
    }
  },
};

export function getPlanner<TEvent extends LambdaEvent>(event: TEvent) {
  const version = determinePayloadFormat(event);
  let processor: Processor<TEvent>;
  switch (version) {
    case '1.0':
      processor = v1Processor as Processor<TEvent>;
      break;
    case '2.0':
      processor = v2Processor as Processor<TEvent>;
      break;
    default:
      throw new Error(`Unsupported version: ${version}`);
  }

  const urlParts = processor.url(event);
  const url = `https://${urlParts.hostname}${urlParts.pathname}${urlParts.search}`;

  const init: RequestInit = {
    headers: processor.getHeaders(event),
    method: processor.getMethod(event),
    // @ts-expect-error this is fine
    duplex: 'half',
  };
  if (event.body) {
    init.body = event.isBase64Encoded
      ? Buffer.from(event.body, 'base64')
      : event.body;
  }

  const request = new Request(url, init);

View on GitHub (pinned to acff82332d)

Solutions

  1. Confirm the Lambda is fronted by API Gateway (REST = 1.0, HTTP = 2.0) and the event reaches the adapter unmodified.
  2. If `version` is a non-string, normalize it before calling the adapter (the check is strict string equality).
  3. For ALB or Function URL, use the appropriate adapter rather than the API Gateway one.

Example fix

// before
const event = { version: 2, ... }; // number, not '2.0'
awsLambdaRequestHandler({ event, ... }); // throws Unsupported version: 2

// after
const event = { ...orig, version: String(orig.version) === '2' ? '2.0' : '1.0' };
Defensive patterns

Strategy: validation

Validate before calling

const supported = new Set(['1.0', '2.0']);
const version = event.version === undefined ? '1.0' : String(event.version);
if (!supported.has(version)) {
  throw new Error('Unsupported API Gateway payload version: ' + version);
}

Type guard

const isSupportedVersion = (v: unknown): v is '1.0' | '2.0' =>
  v === '1.0' || v === '2.0';

Try / catch

try {
  awsLambdaRequestHandler({ event, ... });
} catch (e) {
  if (e instanceof Error && /Unsupported version/.test(e.message)) {
    // normalize event.version and retry, or switch adapter
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing a non-API-Gateway event (ALB invocation, direct Lambda invoke, Function URL with a future/custom format), or an event whose `version` field is something other than `'1.0'`/`'2.0'` (e.g., a typo'd string or a number like `2`).

Common situations: Wiring the Lambda adapter to the wrong trigger, future API Gateway versions, or events transformed by a proxy.

Related errors


AI-assisted analysis of trpc/trpc@acff82332d (2026-08-12). Data as JSON: /api/errors/557ecd247e71132b. Report an issue: GitHub.