10

We’re adjusting how authentication is handled in Stack Exchange API v2. For those unaware, Stack Exchange maintains an API that users can authenticate with to execute commands or request data on the site. Many veteran users utilize the API to perform automated actions on the site through userscripts, or to recreate certain tooling themselves to improve their personal site experience.

Currently, the key query parameter can be utilized to confer additional requests per day with registered applications, and the access_token parameter can be utilized to confer authenticated access for certain endpoints. Starting in June 2026, we’ll be removing the ability to pass authentication/API keys via query parameters. Once this change is live, all requests that require authentication will require either the API key or the access token to be passed via the Authorization request header using the Bearer scheme, which would appear as follows: Authorization: Bearer {KEY OR ACCESS TOKEN}. If you are authenticating with the SDK, please ensure you remove the key parameter. It will no longer be required to pass a key along with an access token if the intent is to make an authorized request. You need only pass an access token if you are intending on performing an action that requires authentication, and an API key if you wish to utilize additional requests per day.

Once this change is live, requests that are made with the old authentication scheme will not be accepted and we will reject them with an explanatory error message.

This change affects any script, bot, or application that performs any authenticated action on behalf of a user, such as commenting, voting, flagging, editing, etc. or otherwise requires authentication to be passed along. This will affect projects such as the Charcoal project’s Metasmoke application as it casts flags on behalf of users. It will also affect tooling that accesses the API and benefits from additional requests for day via an API key. As an example, the “View Vote totals” userscript userscript (code preview) will need to be updated to move the key parameter’s value to an Authorization header instead.

The reason for this change is to bring our API up to the industry’s best practices and ensure that your API keys are being handled securely. The API has already been changed to accept this new form of authentication, so if you maintain any applications or userscripts that authenticate with the API, you can start updating their approach to authentication now. We’ve updated all of our API documentation’s examples to demonstrate the new method of authentication so that you can see real-world examples if you’re having trouble navigating this change. You can double-check how the headers look using your browser’s dev tools if you feel unsure.

We’re announcing the deprecation as early as we can so that tool and app maintainers can update their projects over the next several months. We’re aware of just how reliant our core user base is on the tools they maintain, and we hope that adjusting for this deprecation is easily done. We're also aware that this affects a large amount of outstanding tooling. If there are any projects that are struggling to come into compliance with the new authentication scheme as June approaches, we can push the deadline a bit further into the future.

If you need any assistance updating your tools and apps to use the new method of authentication, please post an answer below, and we’ll do our best to work with you on this. We understand that the tooling you’ve built is central to you, and it’s our job to ensure you’re as supported as possible when we change the underlying mechanisms that support that tooling.

12
  • 8
    The key is not used for authentication. The key is used to identify the script/app/etc. that is making the request. key values are, typically, stored in public repositories. They are, thus, public for almost all applications. An access_token value, which is actually the secret value, is what is used for authentication (actually, it's the combination of both the public key and the secret access_token). As such, this change does little or nothing to improve security and is guaranteed to break almost everything, because nearly everything uses a key value. Commented Feb 17 at 15:53
  • 1
    Note that the only things that don't use a key value are some things under the beginnings of test/development. Without a key value, an application is limited to a shared 300 requests/day/IP address. However, even that's not actually available, because the quota on the SE API has been broken for many years, resulting in that 300 requests/day/IP address quota being shared with the 10k request/day/IP address which is available to requests with a key. This results in the 300 non-key quota commonly not actually being available, so everything uses a key value. Commented Feb 17 at 15:59
  • 2
    @Makyen What? The current version of the API is v2.3 and there's a beta for v3 of the API. I think a more important question is when the v3 Beta API is going to get this, since if I understand, this solve a problem with my inability to use the beta API. Commented Feb 17 at 16:14
  • I haven't used v2 of the API, but the documentation says to "use API keys for read-only operations as an anyonymous user". It seems like the purpose of the API key is for rate limiting (a user's set of API keys gets 10k requests per day). But this question talks about authenticated actions. Can we now use API keys to authenticate as a person? And when will this be added to the beta v3 API, since the lack of API keys is preventing me from implementing what I'd like to implement. Commented Feb 17 at 16:18
  • 6
    Hey folks, I'm working on editing this to clarify a bit more about what's changing. I'm bouncing some language off of some others to ensure I'm crystal clear here. Commented Feb 17 at 16:22
  • 3
    @ThomasOwens Yep. My bad. Sorry about that. I, clearly, haven't had enough caffeine today (and only got 4 hours of sleep). I mixed up versions and subversions. However, version 2.4 is available, and has been in use, at least by SmokeDetector for more than three years now (merged 2022-12-08). Commented Feb 17 at 16:52
  • 5
    @Makyen Apologies for the initial lack of clarity; I've edited the announcement to address this. We'll no longer be accepting access_token as a query parameter when this change goes live, and either the API key or the token can be passed as an Authorization header. To the point about the key not really being authentication, you're right, but it effectively acts as a (publicly available) key to permit additional requests per day, and this change brings it into consistency with auth'd requests. Use the API key for requests that don't require authentication, and the access token where needed. Commented Feb 17 at 17:00
  • 6
    @Makyen Additionally, to be very clear, this affects all versions of the API v2. I've specified 2.X in the title to try and make that clear. Commented Feb 17 at 17:02
  • 1
    Are there some actual examples available somewhere where one can see what changes are actually required? What do I need to change if I'm currently using curl -s --compressed "https://api.stackexchange.com/2.4/inbox/unread?key=$SE_KEY&access_token=$SE_ACCESS_TOKEN"? Commented Feb 17 at 22:14
  • 6
    @samcarter_is_at_topanswers.xyz For curl, you'll want to pass your access_token as a header. You can drop the key. In your example, it'd be curl -s --compressed -H "Authorization: Bearer $SE_ACCESS_TOKEN" "https://api.stackexchange.com/2.4/inbox/unread" - I'll see if I can make some examples as an answer below. Commented Feb 17 at 22:18
  • Will this affect Stack Overflow Extras (SOX)? Commented Feb 20 at 22:04
  • @galacticninja Yes. Anywhere you call the API and supply either a key or a key and an access_token, you will need to shift the needed one of the two (access_token for authenticated calls, just the key for increased quota) in an Authorization header. I can see you build query params with at least a key in cdn.jsdelivr.net/gh/soscripted/sox@dev/sox.common.js , which SOX takes a dependency on. Commented Feb 20 at 22:12

1 Answer 1

8

Just to round out the edge case: will you be rejecting requests that have both the query parameter set and the header?

1
  • 7
    Yes. Any request made that uses one of the two query parameters (key or access_token) will be rejected, regardless of whether a key or auth was appropriately provided with an auth header. Commented Feb 17 at 17:05

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.