Element API throws 404 when not logged into CP My element API endpoint throws a 404 when I'm logged out of the CP, but works fine when I'm logged in. 

When logged out it throws a regular 404 with stack trace exactly as any other non-existing url, when logged in it spits out JSON as it should be. 

HTTP 404 – Not Found – yii\web\NotFoundHttpException
Template not found: news.json


Notably the front-end of the page works fine always..this just affects the element API.

I tried clearing craft caches + all cookies, still the same.
Found nothing suspicious in web.log, phperrors.log or web-404.log
I tried it with a very simple element-api.php and it still produces the same issue. 

For example, even this element-api.php does not work:

&lt;?php

use craft\elements\Entry;

return [
    'endpoints' =&gt; [
        'news.json' =&gt; function() {
            return [
                'elementType' =&gt; Entry::class,
                'criteria' =&gt; ['section' =&gt; 'news'],
                'transformer' =&gt; function(Entry $entry) {
                    return [
                        'title' =&gt; $entry-&gt;title,
                    ];
                },
            ];
        },
    ]
];


(copied straight from the docs. The section "news" exists in my DB and has valid entries.)

Any idea what could be the cause of this or where to further investigate?

This is on Craft 3.1.12.
The issue ended up being related to the yii debug toolbar failing to execute correctly. Disabling it in app.php fixed it.