Getting "Unauthorized: token expired" during conversation
Description
During normal interaction while the agent is working / responding, it will occasionally abruptly stop with a red bordered message that just says "Unauthorized: unauthorised: token expired". I'm using Github Copilot as the provider, and seen it happen on Claude-Sonnet-4.5 for certain.
All I have to do is say "carry on" or similar, and it continues fine.
Only observed this in the last couple of days, I believe it only started since around the version that introduced support for GPT-5.1-codex via Githob Copilot (i.e., the API endpoint change)... nnot that I'm using that model at the moment.... hope that helps?!
I appreciate this is intermittent, perhaps only 2-3 times today of pretty much constant use. Is there any useful settings or command line parameters that I could use, to help catch some details when/if it happens again?
OpenCode version
1.0.126
Steps to reproduce
Talk to the agent. I can't say if there is any specific trigger, it has happened while delegating to a sub-agent as well as a straight forward single agent interaction.
Screenshot and/or share link
Operating System
Windows 11 > WSL 2 > Ubuntu 24.04
Terminal
Windows Terminal WSL
This issue might be a duplicate of existing issues. Please check:
- #2758: Copilot / gpt-5-codex 'model gpt-5-codex is not accessible via the /chat/completions endpoint' - Relates to the recent API endpoint changes mentioned as a potential cause
- #3287: Opencode Github Agent with GitHub Copilot provider Throw AI_APICallError: Bad Request - Similar API errors during Copilot provider operations
- #2764: Session turns keeps resulting in
AI_APICallError: Bad Request- Similar intermittent errors during agent conversation turns - #2617: AI_APICallError: Forbidden with Github Copilot - Related authentication/authorization errors with Copilot provider
Feel free to ignore if none of these address your specific case.
Hm any chance you are using copilot on multiple platforms at the same time (ex: vscode + opencode same time)? I heard some people say that the copilot api sometimes invalidates other refresh tokens or something
@grahamcropley have you tried opencode auth login and then doing copilot again?
does it automatically recover? Or how did you resolve it
i'm experiencing the same issue. it seems to have started around the 1.120–1.122 updates.
i'm using opencode and sometimes copilot in vscode for small fixes. however, i can't say there's a direct connection between using copilot in vscode and the opencode copilot session expiring. if there is a relation, it's not immediate — the opencode session does not expire right after i use copilot in vscode.
I don't know if it is related to any recent updates, I talked to several people in discord who seemed to say this has always been a thing, annoyingly no one opened issues recently lol
i can assure you this only started recently. I’ve been using the copilot provider the entire time I’ve used opencode, and until now it was fine.
at the moment, though, I have to log in again every 20–30 minutes. For example, just now I was waiting for copilot/opus 4.5 to respond, asked it one more question right after, and immediately got an “unauthorized” error.
when I first started using opencode, I logged in once and didn’t have to touch auth again until these recent issues started ☹️ and i also don't know if it related to some updates, maybe this is just a coincidence that i noticed it after 1.120
Hm this is very strange, I use copilot exclusively in opencode and haven't had to login since the first time I did
Are you sure you have to reauth everytime? You can't send followups? Other people said it would handle it after sending a followup automatically
i think i didn't try to send follow ups when this issue occurs, i just log in again strange that i didnt tried that, will try and write to you, thank yo
i cant send follow ups when this issue happens
It no longer logs me out, since yesterday evening, maybe it is github's issue? i did not update opencode all this time
@rekram1-node thank you for the followups.
- Not actively using github copilot in multiple places, but Visual Studio was open, I wasn't interacting with Github Copilot there.
- yes, I tried that, it did happen again afterwards (not straight away)
- it doesn't 'automatically' recover, but all I have to do is just send a message, I say something like 'carry on', and it does.
I can confirm as @moddi3 mentioned, this didn't occur to me until recently, and I've been working on this specific project for 2+ months, hours and hours a day inside opencode.
@moddi3 whereas I can send follow ups, and it immediately continues where it left off.
I've actually had a couple of days without touching it, but I'll keep an eye out for any more occurrences on the latest versions.
Happened again, v1.0.133 - only using Github Copilot Claude Opus 4.5 - no delegation happening, just a single agent. Not using any other instances of Github Copilot anywhere.
And simply prompting it again, continues without missing a beat. (other that that 'token expired' one)