Refresh Azure auth token / hook to run a script on 401 http error? Ref #2484

Resolved 💬 6 comments Opened Aug 20, 2025 by santiago-afonso Closed Mar 2, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

What feature would you like to see?

The same problem of expiring tokens leading to aborted sessions that was identified in issue #2484 and fixed in commit https://github.com/openai/codex/commit/d1f1e368368622055086d310c2bd78b74f992e0c occurs with Azure bearer tokens. Unlike the OpenAI tokens, in the case of Azure an external script is needed to obtain / refresh the token. If OpenAI / MSFT do not add first party support for Azure to Codex, then perhaps a hook to run a script when an http error 401 takes place would allow us to refresh the tokens. (This would apply to other providers with 1-hr tokens as well.) Otherwise, the 'fix' is quitting codex, refreshing, and reentering, loosing all the conversation history in the process. I am getting GPT-5 to work for close to an hour in general, so this issue is highly problematic.

Are you interested in implementing this feature?

_No response_

Additional information

_No response_

View original on GitHub ↗

6 Comments

felixakiragreen · 1 year ago

I just encountered this exact same issue. It all of sudden decided to:

🖐 unexpected status 401 Unauthorized: {"detail":{"code":"token_expired","message":"Provided authentication token is expired. Please try signing in again."}}

I've been coding in this conversation for 3 days, over 11M tokens, the context is invaluable. 😭

Not only did this ruin my session, set me back hours, now I get to comb through the history to rebuild the context, because we have no way to resume a conversation.

EDIT:

Possible solutions:

  • IDEAL don't make me sign in every X days, make my token a year or 99 years like claude does
  • GOOD let me /resume a conversation
  • OKAY tell me how much time I have left in my authorization token
santiago-afonso · 1 year ago
I've been coding in this conversation for 3 days, over 11M tokens, the context is invaluable. 😭

How did you get it to work for 3 days?

felixakiragreen · 1 year ago
How did you get it to work for 3 days?

I just kept my terminal window open and kept using it.

Byunk · 11 months ago

I really need this feature too

Manouchehri · 9 months ago

Likewise.

etraut-openai contributor · 5 months ago

This feature request hasn't received any upvotes in four months, so I'm going to close.