vercel/ai · error · CodeModeError

CODE_MODE_SERIALIZATION_ERROR

CODE_MODE_SERIALIZATION_ERROR

Error message

${label} is not JSON-serializable: ${getErrorMessage(error)}

What it means

Error "${label} is not JSON-serializable: ${getErrorMessage(error)}" thrown in vercel/ai.

Source

Thrown at packages/code-mode/src/utils/serialization.ts:36

  }

  return toStrictJsonPayload(value, maxBytes, label);
}

export function fromJsonPayload(valueJson: string): unknown {
  return valueJson === '' ? undefined : JSON.parse(valueJson);
}

export function toStrictJsonPayload(
  value: unknown,
  maxBytes: number,
  label: string,
): string {
  let encoded: string | undefined;
  try {
    encoded = JSON.stringify(value);
  } catch (error) {
    throw new CodeModeError(
      `${label} is not JSON-serializable: ${getErrorMessage(error)}`,
      'CODE_MODE_SERIALIZATION_ERROR',
    );
  }

  if (encoded === undefined) {
    throw new CodeModeError(
      `${label} is not JSON-serializable.`,
      'CODE_MODE_SERIALIZATION_ERROR',
    );
  }

  assertJsonPayloadSize(encoded, maxBytes, label);
  return encoded;
}

export function assertJsonPayloadSize(
  valueJson: string,

View on GitHub (pinned to 69428b1f8b)

When it happens

Trigger: Thrown at packages/code-mode/src/utils/serialization.ts:36 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/fd39c0301b785f64. Report an issue: GitHub.