Invalid API key

invalid_api_key HTTP 401

The key presented is not one we hold. Keys are stored only as a hash, so this cannot mean "close enough" — check for a truncated copy/paste, a trailing newline from a shell variable, or a key issued for a different environment.

How to react to this in code

Switch on the code member — invalid_api_key — which is stable. Do not parse the type URI: it points here, and where "here" is may change.