API command for general Edit Mode toggling (TAB press)?
Keymap sets a toggle.
The operator has two properties, mode and toggle
&gt;&gt;&gt; bpy.ops.object.mode_set(
mode_set()
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
Sets the object interaction mode


Mesh object active
The TAB Shortcut The toggle property is set to True.
which correlates to
bpy.ops.object.mode_set(mode='EDIT', toggle=True)


GPencil object active
Why is it blank when GP is active, the keymap uses  'EDIT' as the setting, which is not available as an enum item. (See below)  Appears to be some dodgy fix in place behind the scenes, replacing 'EDIT' with a startswith 'EDIT' option.
The shortcut can be emulated by emulating this.
import bpy
ob = bpy.context.object

bpy.ops.object.mode_set(
        mode = 'EDIT_GPENCIL' if ob.type == 'GPENCIL' else 'EDIT',
        toggle=True,
        )

use this in your scripts to emulate tab.
Dynamic Enum
On the &quot;Non Matching&quot;. An enum property can be dynamic, ie items added / removed based on context.  If a grease pencil object is active the options are different for if a mesh object is active, etc.
The documentation shows all possible items, of which only a subset will be valid, based on context.
EDIT
On further investigation, the shortcut is using
bpy.ops.gpencil.editmode_toggle()

this can be confirmed by pressing TAB with GP object active and in python console
&gt;&gt;&gt; C.active_operator
&lt;bpy_struct, Operator(&quot;GPENCIL_OT_editmode_toggle&quot;) at 0x7f3221be1988&gt;

&gt;&gt;&gt; C.window_manager.operator_properties_last('gpencil.editmode_toggle').back
False

when the context object is a gpencil, so without any knowledge of context, could use a try catch clause
import bpy

try:
    bpy.ops.object.mode_set(
            mode = 'EDIT',
            toggle=True,
            )
except TypeError:
    bpy.ops.gpencil.editmode_toggle()

which will still throw a runtime error if the context object is None for example.