It should be put in the HTTP Authorization header. The spec is here https://www.rfc-editor.org/rfc/rfc7235

Answer from Darrel Miller on Stack Overflow
🌐
Stoplight
blog.stoplight.io › home › api keys: api authentication methods & examples
API Keys: API Authentication Methods & Examples | Stoplight
November 10, 2023 - GET / HTTP/1.1 Host: example.com ... but most request libraries do this for you. Some APIs use the `Authorization` header to handle the API key, usually with the Bearer keyword....
Top answer
1 of 1
24

Be consistent

Some may say this is unnecessary (and not too long ago I would have agreed) but these days, with so many auth protocols, if we use the Authorization header to pass an API key, it is worth informing the type too because API keys are not self-descriptive per se 1.

Why do I think it is worth it? Because nowadays supporting different authentication or/and authorization protocols has become a must-have. If we plan to use the Authorization header for all these protocols, we have to make our auth service consistent. The way to communicate what kind of token we send and what authorization protocol should be applied should go in the header too.

Authorization: Basic XXXX
Authorization: Digest XXXX
Authorization: Bearer XXXX
Authorization: ApiKey-v1 XXXX
Authorization: ApiKey-v2 XXXX

I used to don't care about this, but after working with mobile clients or sensors, in which updates were not guaranteed, I started to. I started to be more consistent in the way I implement security so that I can keep backwards compatibility. With the token's type informed I can invalidate requests from a specific set of clients (the outdated ones), add new schemes and differentiate old clients from new ones and change auth validations for one or another scheme without causing breaking changes. I also can apply specific rules in the API Gateways based on the authorization scheme. For example, I can redirect old schemes to specific versions of my web APIs which are deployed apart from the main ones.

Concerns

The problems I faced implementing my own schemes have been similar to the one commented.

On the other hand, I found a consideration that a custom Authorization scheme can be unexpected and unsupported by some clients and leads to custom code anyway

Say clients, say libraries, frameworks, reverse proxies. A custom header can be rejected or ignored. In the worse of the cases, it can also collide.

Collisions can be problematic, but all other issues are likely to be solved by tackling configurations.

Advantages

One important advantage is cache. Shared caches won't cache the header (and that's good of course) unless you say otherwise.

So Authorization or custom header?

In my experience, both take me almost the same work and time to implement, with a slight difference. I had more room for design when I implemented custom headers. However, more room for design also meant more chances to overcomplicate things or reinvent the wheel.

Technically, there could be very little or no difference between the two, but I have found the consistency to be a good feature. It provides me with clearness and understanding. In my case, adding new schemes was reduced to adding 2 new abstractions (implemented by the same concrete class): TokenHandler and TokenValidator. The Handler only checks whether the request header Authorization informs the supported scheme. The Validator is anything I need to validate the token. Altogether working from a single request filter instead of a chain of filters or a big ball of mud.


1: I find this answer to be very clear regarding API Keys

🌐
Apidog
apidog.com › blog › pass-x-api-key-header
How to Pass x-API-key in Header?
July 31, 2025 - Step 4: On the header parameters, enter "x-API-key" as the name.
🌐
WPGetAPI
wpgetapi.com › home › api key in headers
API Key in Headers - WPGetAPI
March 11, 2024 - A lot of APIs will use an API key that is sent in the request header. The API key could be called anything, depending on the API you are using.
🌐
Swagger
swagger.io › docs › specification › v2_0 › authentication › api-keys
API Keys | Swagger Docs
Specify whether the API key will be passed in: header or in: query. Specify a name for that parameter or header.
Find elsewhere
🌐
Maurodatamapper
maurodatamapper.github.io › rest-api › apikeys
API Keys - Documentation
If you use API keys to authenticate, the session cookies are not used to persist identity and so the key should be passed with every call. The header key should be apiKey and the value should be the UUID value of the API key itself.
🌐
Infobip
infobip.com › docs › essentials › api-authentication
API authentication
The examples below show how to prepare the HTTP request. Note that this is almost identical to API Key authentication, but instead of App, you will use IBBSOin the header.
🌐
Reddit
reddit.com › r/dotnet › api key in request header is safe?
r/dotnet on Reddit: API key in request header is safe?
August 22, 2024 -

Hello 👋, need your expert opinions.

We were working on implementing API key based authentication to prevent our API from being called anonymously.

We approached it in the same way as everyone does commonly.

It felt good for server to server communication.

Then we realized we have few pages in mvc that calls the api directly through Jquery. ( basically client side ).

As soon as I pass API-KEY in request header, I could see them exposed in the network tab and that started train of thoughts in my mind. ( PS : at this point, I was testing on my local through http)

I talked to other people in company and they said if communication is happening over HTTPS then you are safe, API won't be exposed.

Then I setup both my web and api app over HTTPS, but I could still the key in the network tab.

Luckily in order to call the API, you need to first login into the web as a authorize user, so I feel it's not a problem for us.

Because if user can just interact with API with UI elements then it does not matter if he wants to go extra mile to call api through a hacky way.

But does that means, your keys are not secured even over HTTPS if it's exposed via front-end?

Thanks.

🌐
Apigee
docs.apigee.com › api-platform › tutorials › secure-calls-your-api-through-api-key-validation
Secure an API by requiring API keys | Apigee Edge | Apigee Docs
Make the following API call using cURL to pass the API key as a header called x-apikey. Don't forget to substitute your organization name.
🌐
Factorial
apidoc.factorialhr.com › docs › api-keys
API Keys
API Keys are a single string of symbols that must be added as a custom header on the request. The header name must be x-api-key and the key must be the value without any prefixes. API keys have TOTAL ACCESS to everything and never expire.
🌐
Imply
docs.imply.io › developer guide
Authenticate with API keys | Imply
The following example shows how to create an API key named Polaris test key: ... curl --location --request POST "https://ORGANIZATION_NAME.api.imply.io/v1/apikeys" \ --header "Authorization: Basic $POLARIS_API_KEY" \ --header "Content-Type: application/json" \ --data-raw '{ "name":"Polaris test key", "description":"", "permissions":[ { "name":"AccessAlerts", "resources":[ "projects/45c024f4-1254-4b58-8207-4111d2f80669", "projects/c3b5e09a-b337-4107-8e28-25e23f246f73", "projects/2745b3b5-7635-48f6-bbc8-25faae4ffc12"] }, { "name":"AccessReports", "resources":[ "projects/45c024f4-1254-4b58-8207-4
🌐
Microsoft Fabric Community
community.fabric.microsoft.com › t5 › Desktop › Connect-API-with-Header-ApiKeyName-not-going-through › m-p › 437253
Solved: Connect API with Header ApiKeyName not going throu... - Microsoft Fabric Community
April 12, 2022 - So I was like: Problably I need to talk with them because may be my key. But using Curl worked, so I was like, .... may be a synthax problem hehehehe. Ty for your time and support. ... I am not an expert, but my quick research suggests that the header name should be "X-API-KEY" and its value being API-KEY.
🌐
Google Cloud
cloud.google.com › application development › apigee › secure an api by requiring api keys
Secure an API by requiring API keys | Apigee | Google Cloud
Make the following API call using cURL to pass the API key as a header called x-apikey. Don't forget to substitute your organization name.
🌐
forcePanda
forcepanda.wordpress.com › 2022 › 11 › 15 › how-to-set-up-header-based-api-key-authentication-in-external-services
How to set up Header based API Key authentication in External Services? | forcePanda
November 15, 2022 - Pass the accesstoken in the header to make API calls. An example using the command-line client curl is shown below: curl -H “Authorization: Bearer YOUR_API_KEY” https://www.huduser.gov/hudapi/public/fmr/data/0801499999 · I’m using ‘Bearer’ as the name of the Principal and the Value is the long key
🌐
GitHub
github.com › OAI › OpenAPI-Specification › issues › 3225
`api_key` is not a good example for an HTTP header, because of the underscore · Issue #3225 · OAI/OpenAPI-Specification
April 1, 2023 - Several HTTP servers strip HTTP headers when they contain _ for security reasons. Using something like api-key instead of api_key in the examples would be a more realistic example. For references, ...
Published   Apr 01, 2023
🌐
IBM
ibm.com › docs › en › zos-connect › zos-connect › 3.0
Configuring an API key
To call an API protected by an API key, your z/OS application must include the API key as an authentication or authorization credential in the request. The API key credentials are propagated by the z/OS Connect Server to the API in either a query string, request header or cookie.