@Override
        public LeaveGroupRequest build(short version) {
            final LeaveGroupRequestData data;
            // Starting from version 3, all the leave group request will be in batch.
            if (version >= 3) {
                data = new LeaveGroupRequestData()
                           .setGroupId(groupId)
                           .setMembers(members);
            } else {
                if (members.size() != 1) {
                    throw new UnsupportedVersionException("Version " + version + " leave group request only " +
                                                              "supports single member instance than " + members.size() + " members");
                }

                data = new LeaveGroupRequestData()
                           .setGroupId(groupId)
                           .setMemberId(members.get(0).memberId());
            }
            return new LeaveGroupRequest(data, version);
        }
Based on the request version to choose fields.
clients/src/main/java/org/apache/kafka/common/requests/LeaveGroupRequest.java