Error: token expired or invalid: 401
Version: 1.88.1 Commit: e170252f762678dec6ca2cc69aba1570769a5d39 Date: 2024-04-10T17:34:12.840Z Electron: 28.2.8 ElectronBuildId: 27744544 Chromium: 120.0.6099.291 Node.js: 18.18.2 V8: 12.0.267.19-electron.0 OS: Linux x64 6.5.0-28-generic
2024-05-04 16:00:56.356 [info] [chat fetch] url https://api.githubcopilot.com/chat/completions
2024-05-04 16:00:56.356 [info] [chat fetch] modelMaxPromptTokens 3072
2024-05-04 16:00:56.356 [info] [chat fetch] modelMaxResponseTokens 2517
2024-05-04 16:00:56.356 [info] [chat fetch] chat model gpt-4
2024-05-04 16:00:56.363 [info] [auth] Logged in as virtuallyunknown
2024-05-04 16:00:56.363 [info] [chat] copilot token chat_enabled: true
2024-05-04 16:00:56.363 [info] [auth] Got Copilot token for virtuallyunknown
2024-05-04 16:00:56.483 [info] [chat fetch] request.response: [https://api.githubcopilot.com/chat/completions], took 119 ms
2024-05-04 16:00:56.483 [info] [chat fetch] Request ID for failed request: ,6471bc88-a50f-4faf-8325-c22354468d3f
I've seen many issues about the same error but with a different code 403, where I am getting code 401. The problem has been happening for a while, and I always assumed it will eventually get fixed with an update.
When this happens, I need to restart VSCode to get things working as normal again. This isn't that big of a deal with Copilot Chat since it will throw an error directly, but I don't always notice when the AI-assisted code completions/suggestions stop working.
I am not exactly sure what causes this, but I think it happens when I leave VSCode unattended for a while (30 minutes maybe?).
I have met the same problem...
I couldn't manage to include diagnostics in my original post because VSCode crashed (for unrelated reasons), but today I got the same issue so here is the output when Copilot and VSCode are in 401 state, so to speak:
Copilot
- Version: 1.186.0
- Build: prod
- Editor: vscode/1.89.0
Environment
- http_proxy: n/a
- https_proxy: n/a
- no_proxy: n/a
- SSL_CERT_FILE: n/a
- SSL_CERT_DIR: n/a
- OPENSSL_CONF: n/a
Feature Flags
- Send Restricted Telemetry: disabled
- Chat: enabled
Node setup
- Number of root certificates: 141
- Operating system: Linux
- Operating system version: 6.5.0-28-generic
- Operating system architecture: x64
- NODE_OPTIONS: n/a
- NODE_EXTRA_CA_CERTS: n/a
- NODE_TLS_REJECT_UNAUTHORIZED: n/a
- tls default min version: TLSv1.2
- tls default max version: TLSv1.3
Network Configuration
- Proxy host: n/a
- Proxy port: n/a
- Kerberos SPN: n/a
- Reject unauthorized: disabled
- Fetcher: HelixFetcher
Reachability
- github.com: HTTP 200 -
- copilot-proxy.githubusercontent.com: HTTP 200 -
- api.githubcopilot.com: HTTP 200 -
- default.exp-tas.com: HTTP 200 -
VS Code Configuration
- HTTP proxy:
- HTTP proxy authentication: n/a
- Proxy Strict SSL: true
- Extension HTTP proxy support: override
Extensions
- Is
win-cainstalled?: false - Is
mac-cainstalled?: false
Authentication
- GitHub username: virtuallyunknown
bumped into the same issue
Same issue here. Some times the chat section looks empty and other times the chat throws 401 error.
The section gets unresponsive.
This feature is not working
Looks like the autocompletion is working fine
This is happening despite authentication was successful
I was having this problem, and for me, I just enabled the "Copilot Chat in the IDE" option in the GitHub Copilot policies settings. It worked :)
I was having this problem, and for me, I just enabled the "Copilot Chat in the IDE" option in the GitHub Copilot policies settings. It worked :)
Oh, that was the problem! Thanks a lot for the suggestion!
I was having this problem, and for me, I just enabled the "Copilot Chat in the IDE" option in the GitHub Copilot policies settings. It worked :)
Do I need to have an organization in my github account to enable this setting? I am not exactly sure where this setting is enabled from.
I am using Copilot Individual, not business or enterprise, so I'm not sure this fix is applicable to me.
I was having this problem, and for me, I just enabled the "Copilot Chat in the IDE" option in the GitHub Copilot policies settings. It worked :)
Do I need to have an organization in my github account to enable this setting? I am not exactly sure where this setting is enabled from.
I am using Copilot Individual, not business or enterprise, so I'm not sure this fix is applicable to me.
You need to go to: Organization Settings -> Copilot->polices!
Appreciate your help @dezguell, but I am not a member of any organizations.
https://github.com/settings/organizations
On this page all I have is this, so I don't have the option to change any organization settings:
@TylerLeonhardt this is still happening, and it's still very annoying having to restart VSCode every time. Any chance someone can look into it?
I'm only tagging you because it says you were assigned for this issue, but we haven't heard any official response so far. Thanks.
Hi @virtuallyunknown sorry for the delay here. I have done some work recently to improve the experience. I'm curious if it fixes the issue you're seeing.
You can try out the changes in the Insiders build of VS Code and then get the GitHub Copilot Chat pre-release version. Just go to the Extension Pane and it should allow you to install the pre-release.
Can you grab those and let me know if that helps?
Hi @virtuallyunknown sorry for the delay here. I have done some work recently to improve the experience. I'm curious if it fixes the issue you're seeing.
You can try out the changes in the Insiders build of VS Code and then get the GitHub Copilot Chat pre-release version. Just go to the Extension Pane and it should allow you to install the pre-release.
Can you grab those and let me know if that helps?
Thanks for the response!
I have switched to the pre-release version of the extension and I will let you know if the issue occurs again.
As for the insiders build of VSCode itself, these updates are going to make it into the stable release next month, is that correct? I prefer to just wait until then to test, as switching from normal to insiders probably requires some setup and time investment, and I depend on my code editor for work.
Anyway, when I have some useful information I will let you know!
Greetings again @TylerLeonhardt. I thought this was finally fixed because I enjoyed a period without the issue happening, but unfortunately it happened again just now.
All the details provided below are taken while the extension is in this so called "bugged" state. Here is the diagnostics data:
## Copilot
- Version: 1.211.0
- Build: prod
- Editor: vscode/1.91.0
## Environment
- http_proxy: n/a
- https_proxy: n/a
- no_proxy: n/a
- SSL_CERT_FILE: n/a
- SSL_CERT_DIR: n/a
- OPENSSL_CONF: n/a
## Feature Flags
- Send Restricted Telemetry: disabled
- Chat: enabled
## Node setup
- Number of root certificates: 141
- Operating system: Linux
- Operating system version: 6.5.0-35-generic
- Operating system architecture: x64
- NODE_OPTIONS: n/a
- NODE_EXTRA_CA_CERTS: n/a
- NODE_TLS_REJECT_UNAUTHORIZED: n/a
- tls default min version: TLSv1.2
- tls default max version: TLSv1.3
## Network Configuration
- Proxy host: n/a
- Proxy port: n/a
- Kerberos SPN: n/a
- Reject unauthorized: disabled
- Fetcher: HelixFetcher
## Reachability
- github.com: HTTP 200
- api.github.com: HTTP 200
- copilot-proxy.githubusercontent.com: HTTP 200
- api.githubcopilot.com: HTTP 200
- default.exp-tas.com: HTTP 200
## VS Code Configuration
- HTTP proxy:
- HTTP proxy authentication: n/a
- Proxy Strict SSL: true
- Extension HTTP proxy support: override
## Extensions
- Is `win-ca` installed?: false
- Is `mac-ca` installed?: false
## Authentication
- GitHub username: virtuallyunknown
Github copilot chat output log:
2024-07-11 07:22:08.667 [info] [auth] Logged in as virtuallyunknown
2024-07-11 07:22:08.668 [info] [chat] copilot token chat_enabled: true
2024-07-11 07:22:08.668 [info] [auth] Got Copilot token for virtuallyunknown
2024-07-11 07:22:08.671 [info] [auth] Logged in as virtuallyunknown
2024-07-11 07:22:08.672 [info] [chat] copilot token chat_enabled: true
2024-07-11 07:22:08.672 [info] [auth] Got Copilot token for virtuallyunknown
2024-07-11 07:22:08.785 [info] [chat fetch] request.response: [https://api.githubcopilot.com/chat/completions], took 116 ms
2024-07-11 07:22:08.785 [info] [chat fetch] Request ID for failed request: , a9895a6f-5d50-40ba-ad2a-83c641cb9dfb
As seen, the chat is giving errors, and editor code suggestions stopped appearing as well. Highlighting a code block and pressing Ctrl+Enter also just gives 0 suggestions.
Additional details:
Extensions:
GitHub Copilot v1.211.0
GitHub Copilot Chat v0.17.2024062801 (pre-release)
VSCode:
Version: 1.91.0
Commit: ea1445cc7016315d0f5728f8e8b12a45dc0a7286
Date: 2024-07-01T18:52:41.959Z
Electron: 29.4.0
ElectronBuildId: 9728852
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Linux x64 6.5.0-35-generic
Having the same problem here, although I have already enabled the policies.
EDIT: I updated vscode version and it started working again.
We've just released VS Code 1.92 & Copilot Chat 0.18. (should be available in a moment if it's not already)
- Can you try with that? It has some auth related fixes that I made.
- If that doesn't work, can you grab the pre-release version of Copilot Chat (0.19.x)? I've pretty much re-wrote the whole auth stack in it...
This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.
Happy Coding!

