Determine if a Request is for an API/Panel Call

Is there a built-in, stable way to detect if a request is being used to fulfill an API or Panel call?

I currently do something like

$path = Url::path();
if (Str::startsWith($path, 'api', true) || Str::startsWith($path, 'panel', true)) {
}

but was wondering if Kirby has a built-in function to determine what kind of request this is.

I don’t think so. Such a method would probably do nothing else but check if the path contains the api string.