Transform orientation doesn't rotate correctly?

I am trying to rotate a simple object but it doesn’t work correctly when I animate it. I would like to rotate it 90 degrees on the Y axis. I set up the transformation and it rotates okay manually when I set my key frames. When it is animated it rotates in several directions. Where am I going wrong?

The process should be:

1.) set keyframe

2.) move forward some amount of frames

3.) transform object

4.) set keyframe

So plane_pivot is a plane you have on the top of the cube and you are trying to rotate the cube 90 degrees around that plane’s center, this will use the local orientation of the object (see below). If you want to see that orientation select the plane, press r, and press y twice. You will see the lines indicating the axes for local rotation and if you look in the top left you will see that you are rotating in the local as opposed to the global axes.

If you are trying to use a custom transform orientation try looking at this:
https://docs.blender.org/manual/en/latest/scene_layout/object/editing/transform/control/orientations.html#custom-orientations

I have followed those steps but still get the same rotation. Rather than rotating on the Y axis it rotates in a circular direction. I still must be missing something.

Found the solution. Add the rotation and keyframes in the edit mode.