Getting "Unauthorized: token expired" during conversation #3260

Open
opened 2026-02-16 17:39:22 -05:00 by yindo · 15 comments
Owner

Originally created by @grahamcropley on GitHub (Dec 2, 2025).

Originally assigned to: @rekram1-node on GitHub.

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.

Image

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

Image

Operating System

Windows 11 > WSL 2 > Ubuntu 24.04

Terminal

Windows Terminal WSL

Originally created by @grahamcropley on GitHub (Dec 2, 2025). Originally assigned to: @rekram1-node on GitHub. ### 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. <img width="1326" height="811" alt="Image" src="https://github.com/user-attachments/assets/e52fa8ed-ce8b-4b85-98e6-4d57ca177cc2" /> 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 <img width="1326" height="193" alt="Image" src="https://github.com/user-attachments/assets/be453bdf-f894-49dc-80cd-d0fe7784f3bd" /> ### Operating System Windows 11 > WSL 2 > Ubuntu 24.04 ### Terminal Windows Terminal WSL
yindo added the bug label 2026-02-16 17:39:22 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Dec 2, 2025):

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.

@github-actions[bot] commented on GitHub (Dec 2, 2025): 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.
Author
Owner

@rekram1-node commented on GitHub (Dec 2, 2025):

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

@rekram1-node commented on GitHub (Dec 2, 2025): 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
Author
Owner

@rekram1-node commented on GitHub (Dec 2, 2025):

@grahamcropley have you tried opencode auth login and then doing copilot again?

@rekram1-node commented on GitHub (Dec 2, 2025): @grahamcropley have you tried opencode auth login and then doing copilot again?
Author
Owner

@rekram1-node commented on GitHub (Dec 2, 2025):

does it automatically recover? Or how did you resolve it

@rekram1-node commented on GitHub (Dec 2, 2025): does it automatically recover? Or how did you resolve it
Author
Owner

@moddi3 commented on GitHub (Dec 3, 2025):

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.

@moddi3 commented on GitHub (Dec 3, 2025): 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.
Author
Owner

@rekram1-node commented on GitHub (Dec 3, 2025):

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

@rekram1-node commented on GitHub (Dec 3, 2025): 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
Author
Owner

@moddi3 commented on GitHub (Dec 3, 2025):

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.

@moddi3 commented on GitHub (Dec 3, 2025): 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.
Author
Owner

@moddi3 commented on GitHub (Dec 3, 2025):

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

@moddi3 commented on GitHub (Dec 3, 2025): 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
Author
Owner

@rekram1-node commented on GitHub (Dec 3, 2025):

Hm this is very strange, I use copilot exclusively in opencode and haven't had to login since the first time I did

@rekram1-node commented on GitHub (Dec 3, 2025): Hm this is very strange, I use copilot exclusively in opencode and haven't had to login since the first time I did
Author
Owner

@rekram1-node commented on GitHub (Dec 3, 2025):

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

@rekram1-node commented on GitHub (Dec 3, 2025): 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
Author
Owner

@moddi3 commented on GitHub (Dec 3, 2025):

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

@moddi3 commented on GitHub (Dec 3, 2025): 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
Author
Owner

@moddi3 commented on GitHub (Dec 3, 2025):

i cant send follow ups when this issue happens

Image
@moddi3 commented on GitHub (Dec 3, 2025): i cant send follow ups when this issue happens <img width="965" height="778" alt="Image" src="https://github.com/user-attachments/assets/a8062efb-9abc-4173-9876-955073aeac48" />
Author
Owner

@moddi3 commented on GitHub (Dec 5, 2025):

It no longer logs me out, since yesterday evening, maybe it is github's issue?
i did not update opencode all this time

@moddi3 commented on GitHub (Dec 5, 2025): It no longer logs me out, since yesterday evening, maybe it is github's issue? i did not update opencode all this time
Author
Owner

@grahamcropley commented on GitHub (Dec 5, 2025):

@rekram1-node thank you for the followups.

  1. Not actively using github copilot in multiple places, but Visual Studio was open, I wasn't interacting with Github Copilot there.
  2. yes, I tried that, it did happen again afterwards (not straight away)
  3. 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.

@grahamcropley commented on GitHub (Dec 5, 2025): @rekram1-node thank you for the followups. 1) Not actively using github copilot in multiple places, but Visual Studio was open, I wasn't interacting with Github Copilot there. 2) yes, I tried that, it did happen again afterwards (not straight away) 3) 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.
Author
Owner

@grahamcropley commented on GitHub (Dec 5, 2025):

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.

Image

And simply prompting it again, continues without missing a beat. (other that that 'token expired' one)

Image
@grahamcropley commented on GitHub (Dec 5, 2025): 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. <img width="1926" height="1086" alt="Image" src="https://github.com/user-attachments/assets/1e982076-fc20-4e49-8e37-7d8848fc9571" /> And simply prompting it again, continues without missing a beat. (other that that 'token expired' one) <img width="1878" height="1018" alt="Image" src="https://github.com/user-attachments/assets/d6d2ccef-7949-43bf-8b05-49c3678d702f" />
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3260