code: def _commands_to_api(
      commands: List[Dict[str, Union[Callable, ClientCommand]]],
      info: Optional[frontend.AppInfo] = None,
  ) -> List:
      """Convert user commands to API endpoint."""
      api = []
      for command in commands:
          for k, v in command.items():
              k = k.replace(" ", "_")
              api.append(
                  Post(
                      f"/command/{k}",
                      v.method if isinstance(v, ClientCommand) else v,
                      method_name=k,
                      tags=["app_client_command"]
                      if isinstance(v, ClientCommand)
                      else ["app_command"],
                      openapi_extra=_collect_open_api_extras(v, info),
                  )
              )
      return api
  
imports: import errno
  import inspect
  import os
  import os.path
  import shutil
  import sys
  import traceback
  from dataclasses import asdict
  from getpass import getuser
  from importlib.util import module_from_spec, spec_from_file_location
  from tempfile import gettempdir
  from typing import Any, Callable, Dict, List, Optional, Union
  import requests
  from fastapi import HTTPException
  from pydantic import BaseModel
  from lightning.app.api.http_methods import Post
  from lightning.app.api.request_types import _APIRequest, _CommandRequest, _RequestResponse
  from lightning.app.utilities import frontend
  from lightning.app.utilities.app_helpers import Logger, is_overridden
  from lightning.app.utilities.cloud import _get_project
  from lightning.app.utilities.network import LightningClient
  from lightning.app.utilities.state import AppState
label_desc: Use image node_id 11 for calling a global function with example usage: _commands_to_api(commands, info) and returns: api