bpy.ops.object.align( align_mode='OPT_4' ) throws: keyword "align_mode" unrecognized
To track down the cause of  the error shown :.

Could be a version issue, the docs linked are for current,  matching
those available circa 2.91

If you are using an older version, consult the appropriate version
docs, or consult the python console.
 &gt;&gt;&gt; bpy.ops.object.align(

 align()
 bpy.ops.object.align(
         bb_quality=True,    
         align_mode='OPT_2',
         relative_to='OPT_4',
         align_axis=set()
         )
 Align Objects



and to quickly see the valid values of any argument, crunch in an invalid one as shown above with align_mode='FOO'.
&gt;&gt;&gt; bpy.ops.object.align(align_mode='OPT_4')
Traceback (most recent call last):
  File &quot;&lt;blender_console&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/home/batfinger/blender/vers/blender-2.91.2-linux64/2.91/scripts/modules/bpy/ops.py&quot;, line 132, in __call__
    ret = _op_call(self.idname_py(), None, kw)
TypeError: Converting py args to operator properties:  enum &quot;FOO&quot; not found in ('OPT_1', 'OPT_2', 'OPT_3')

    &gt;&gt;&gt; bpy.ops.object.align(align_mode='OPT_4')
    Traceback (most recent call last):
      File &quot;&lt;blender_console&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/home/batfinger/blender/vers/blender-2.91.2-linux64/2.91/scripts/modules/bpy/ops.py&quot;, line 132, in __call__
    ret = _op_call(self.idname_py(), None, kw)
TypeError: Converting py args to operator properties:  enum &quot;OPT_4&quot; not found in ('OPT_1', 'OPT_2', 'OPT_3')


It could be the case some addon you have enabled has overridden the
default operator.

As displayed above this will be evident by typing
bpy.ops.object.align( to autocomplete, into python console to
display the operator docstring


With API calls (ie no operators).
As is the case for most operators can be replaced with API calls.
eg Here I've simply placed a text object, each sharing the data (single letter &quot;T&quot;) at global location of each of the selected objects, before removing.  Changing transform  based on whatever the desired align operator properties would be little to no hassle.
import bpy
from bpy import context
# font
font = bpy.data.curves.new(&quot;Foo&quot;, 'FONT')
font.body = &quot;T&quot;

for ob in context.selected_objects:
    text = bpy.data.objects.new(&quot;Text&quot;, font)
    text.matrix_world = ob.matrix_world
    context.collection.objects.link(text)
    bpy.data.objects.remove(ob)