When a request fails the body is always:
Branch on code, not on message; the message can change.

Codes

The key is checked before the query parameters, so a request with a bad key and a bad limit gets 401, not 400. Query parameters an endpoint does not know are ignored rather than rejected.

Paths outside the API

The error body above belongs to the documented endpoints. A request to a path that does not exist, such as a misspelled /v1/event, is answered 404 with a different body. Check the path first if a 404 does not carry an error object.