You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
provider: api.responses.write scope error after upgrade #61342
After upgrading OpenCode, a session in a project directory failed with an insufficient-permissions error saying the api.responses.write scope is missing. In an earlier occurrence, clearing OpenCode’s cache for the affected directory made the error go away.
Environment
opencode version: v2.2.5 (current; version upgraded from not recorded)
OS: Darwin 25.5.0 (arm64)
Terminal: iTerm.app (xterm-256color)
Shell: /bin/zsh
Install/channel: latest release
Active plugins: @tarquinen/opencode-dcp@latest, oh-my-openagent@latest, opencode-elf@latest, opencode-scheduler
Reproduction
Upgrade OpenCode (exact previous and new versions not recorded).
Open or resume a session in a project directory.
Use the session; the specific action that first triggers the error is not yet known.
Expected Behavior
The session should be able to request model responses after the upgrade, or provide a clear and consistent indication if the configured credentials genuinely lack a required scope.
Actual Behavior
The session reports:
Error: You have insufficient permissions for this operation. Missing scopes: api.responses.write. Check that you have the correct role in your organization (Reader, Writer, Owner) and project (Member, Owner), and if you're using a restricted API key, that it has the necessary scopes.
Additional Context
Clearing OpenCode’s cache for the affected directory made the error disappear in an earlier occurrence. It is not yet known whether this workaround resolves the current occurrence, how consistently the error reproduces, or which exact action triggers it.
Thanks for the report! To work out where this comes from, could you add a few details?
Provider, model and login method: which provider and model was the session using, and how are you signed in: ChatGPT Plus/Pro subscription (OAuth), an OpenAI API key (restricted or not), or OpenCode Zen/Go/Console?
Scope of the problem: when it happens, do sessions in other directories work with the same model? Does logging out of the provider and back in (instead of clearing the cache) also fix it?
Plugins: does it still happen with the third-party plugins (oh-my-openagent, opencode-dcp, opencode-elf, opencode-scheduler) disabled?
Versions: the version you upgraded from, if you can find it.
If you can, the full error as shown, including any HTTP 401/403 prefix, and any relevant lines from the logs.
You can reply here with the details, or edit the issue. If you edit it, please also leave a comment saying you've updated it, so we know when you're done.
These existing issues look related, ordered from most to least likely to match:
fix(core): sync credentials across locations #42412: a proposed fix for directories keeping old OpenAI routing after credentials change, which leads to this same api.responses.write 401. It would explain why clearing that directory's cache helped.
Thanks for following up. I inspected the local session metadata, provider runtime state, and logs.
Provider, model, and login method
Provider: OpenAI
Model:gpt-6.1-sol
Variant:medium
Login: ChatGPT OAuth, with the saved method ID chatgpt-browser (“Codex browser (legacy)”).
The active OpenAI credential is OAuth, not an OpenAI API key or OpenCode Zen/Go/Console. The inspected metadata does not establish whether the subscription is Plus or Pro.
Scope of the problem
Yes—another session in a different directory works with the same provider/model while the affected directory fails. Both locations report the same OAuth credential connection.
There is a notable difference in their live provider state:
Provider setting
Affected directory
Working directory
baseURL
https://api.openai.com/v1
https://chatgpt.com/backend-api/codex
ChatGPT-specific headers
Absent
Present, including chatgpt-account-id
Transport
websocket
websocket
Both locations discover the same configuration sources. No project-local OpenCode config or explicit endpoint override was found.
The affected session also has successful responses using the same model before the failure.
Logging out and back in has not been tested. Clearing the affected directory’s cache resolved an earlier occurrence, but we have not established exactly which cached state caused it.
Plugins
The following third-party plugins were configured when the issue occurred:
oh-my-openagent@latest
@tarquinen/opencode-dcp@latest
opencode-elf@latest
opencode-scheduler
Reproduction with these plugins disabled has not been tested, so plugin involvement has not been ruled out.
Versions
The local startup logs show:
Previously installed:2.2.2, last observed starting on 2026-11-03 at 03:04:47 UTC
Current:2.2.5, first observed starting on 2026-11-03 at 03:12:34 UTC
This indicates the recent upgrade was 2.2.2 → 2.2.5.
Full error and relevant logs
The persisted assistant error records HTTP 401, classified as provider.auth:
You have insufficient permissions for this operation. Missing scopes: api.responses.write. Check that you have the correct role in your organization (Reader, Writer, Owner) and project (Member, Owner), and if you're using a restricted API key, that it has the necessary scopes.
The provider response body is:
{
"error": {
"message": "You have insufficient permissions for this operation. Missing scopes: api.responses.write. Check that you have the correct role in your organization (Reader, Writer, Owner) and project (Member, Owner), and if you're using a restricted API key, that it has the necessary scopes.",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
Relevant server-log excerpts, with the stack trace and session identifier omitted:
The second entry’s cause contains the exact scope error above.
Possible lead: the affected location’s provider runtime appears not to have applied the ChatGPT OAuth endpoint/header setup, despite reporting the same OAuth connection as the working location. This suggests a per-location provider initialization or invalidation issue, but it is not yet a confirmed root cause.
We're closing this for now because we haven't heard back. To narrow down the Missing scopes: api.responses.write error, we need to know which provider, model and login method you were using (ChatGPT subscription, OpenAI API key, or Zen/Go/Console). It would also help to know whether other directories were affected and whether it still happens with the third-party plugins disabled.
If it happens again on a current v2 release, please reply here with those details (or open a new issue) and we'll take another look. In the meantime, #42412 (directories keeping old OpenAI routing after credentials change) and #49847 (ChatGPT OAuth requests sent with the Zen API key) may be worth checking. Thanks for reporting!
@thdxr sorry for randomly pick you out.
It seems the opencodejr is not smart enough, or it simply failed to fetch all the user replies in the issue.
I think my report contains the method of "OAuth", which should be categorized to ChatGPT subscription.
I'm not sure who is in charge of the development of opencodejr, but we definitely need to fix it.
This issue seem to happen when people upgrade from opencode v1 to v2.
Could anyone from opencode to treat this issue with humanity?
Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.
Sorry for the earlier close. Your reply from 3 November had everything we needed, and I should have picked it up.
I was able to reproduce the routing problem you found on 2.2.5, and it still happens on the latest dev (63bfe62):
The background service loads directory A before a ChatGPT OAuth login (method chatgpt-browser) exists.
A separate opencode --standalone process adds the ChatGPT OAuth credential.
A's OpenAI provider stays on baseURL: https://api.openai.com/v1 and gets no chatgpt-account-id headers. A directory opened afterwards gets https://chatgpt.com/backend-api/codex with the ChatGPT headers. That is the same split you saw between your failing and working directories.
Evicting A's location (opencode api DELETE '/api/debug/location?…', as you found) fixes the routing.
I used a fake credential and sent no real request, so I didn't see the 401 itself. Sending a ChatGPT token to the public endpoint is what produced the same Missing scopes: api.responses.write error in #34765. I also haven't confirmed that a separate process wrote the credential in your case (for example during the 2.2.2 → 2.2.5 upgrade). That is one way into this state; there may be others. The script below shows the routing mismatch.
Until it's fixed, you can evict the affected directory's location, or restart the background service (opencode service restart), to get the right routing back.
Reproduction script (repro.sh)
#!/usr/bin/env bash# Repro for #61342: a directory already loaded in the background service keeps the public# OpenAI baseURL (no ChatGPT headers) after a ChatGPT OAuth credential is added by another# opencode process, while a newly opened directory gets the Codex routing.set -u
OC=${OC:-opencode}enc() { python3 -c 'import urllib.parse,sys;print(urllib.parse.quote(sys.argv[1],safe=""))'"$1"; }
q() { $OC api GET /api/provider/openai -H "x-opencode-directory:$(enc "$1")";echo; }
# start clean: remove any credential from a previous run$OC auth export2>/dev/null | grep -q cred_repro61342 &&$OC auth logout openai cred_repro61342 </dev/null >/dev/null 2>&1
A=$(mktemp -d /tmp/oc-A.XXXX); B=$(mktemp -d /tmp/oc-B.XXXX)echo"== A loaded in the service before login"; q "$A"
EXP=$(( ($(date +%s) +86400) *1000))
CRED="[{\"id\":\"cred_repro61342\",\"integrationID\":\"openai\",\"label\":\"ChatGPT\",\"active\":true,\"value\":{\"type\":\"oauth\",\"methodID\":\"chatgpt-browser\",\"refresh\":\"r\",\"access\":\"a\",\"expires\":$EXP,\"metadata\":{\"accountID\":\"acct_123\"}}}]"echo"== ChatGPT OAuth credential added by a separate (--standalone) opencode process"echo"$CRED"|$OC auth import --standalone
sleep 3
echo"== A (already loaded in service)"; q "$A"echo"== B (opened after login)"; q "$B"; sleep 2; q "$B"
Activity
opencodejr commentedon Nov 3, 2026
Thanks for the report! To work out where this comes from, could you add a few details?
HTTP 401/403prefix, and any relevant lines from the logs.You can reply here with the details, or edit the issue. If you edit it, please also leave a comment saying you've updated it, so we know when you're done.
These existing issues look related, ordered from most to least likely to match:
api.responses.write401. It would explain why clearing that directory's cache helped.zenixls2 commentedon Nov 3, 2026
Thanks for following up. I inspected the local session metadata, provider runtime state, and logs.
Provider, model, and login method
gpt-6.1-solmediumchatgpt-browser(“Codex browser (legacy)”).Scope of the problem
Yes—another session in a different directory works with the same provider/model while the affected directory fails. Both locations report the same OAuth credential connection.
There is a notable difference in their live provider state:
baseURLhttps://api.openai.com/v1https://chatgpt.com/backend-api/codexchatgpt-account-idwebsocketwebsocketBoth locations discover the same configuration sources. No project-local OpenCode config or explicit endpoint override was found.
The affected session also has successful responses using the same model before the failure.
Logging out and back in has not been tested. Clearing the affected directory’s cache resolved an earlier occurrence, but we have not established exactly which cached state caused it.
Plugins
The following third-party plugins were configured when the issue occurred:
oh-my-openagent@latest@tarquinen/opencode-dcp@latestopencode-elf@latestopencode-schedulerReproduction with these plugins disabled has not been tested, so plugin involvement has not been ruled out.
Versions
The local startup logs show:
2.2.2, last observed starting on 2026-11-03 at 03:04:47 UTC2.2.5, first observed starting on 2026-11-03 at 03:12:34 UTCThis indicates the recent upgrade was 2.2.2 → 2.2.5.
Full error and relevant logs
The persisted assistant error records HTTP 401, classified as
provider.auth:The provider response body is:
{ "error": { "message": "You have insufficient permissions for this operation. Missing scopes: api.responses.write. Check that you have the correct role in your organization (Reader, Writer, Owner) and project (Member, Owner), and if you're using a restricted API key, that it has the necessary scopes.", "type": "invalid_request_error", "param": null, "code": null } }Relevant server-log excerpts, with the stack trace and session identifier omitted:
The second entry’s cause contains the exact scope error above.
Possible lead: the affected location’s provider runtime appears not to have applied the ChatGPT OAuth endpoint/header setup, despite reporting the same OAuth connection as the working location. This suggests a per-location provider initialization or invalidation issue, but it is not yet a confirmed root cause.
zenixls2 commentedon Nov 3, 2026
Additional
opencode api delete '/api/debug/location?location%5Bdirectory%5D={path_encoded}'could solve the issue.opencodejr commentedon Nov 6, 2026
We're closing this for now because we haven't heard back. To narrow down the
Missing scopes: api.responses.writeerror, we need to know which provider, model and login method you were using (ChatGPT subscription, OpenAI API key, or Zen/Go/Console). It would also help to know whether other directories were affected and whether it still happens with the third-party plugins disabled.If it happens again on a current v2 release, please reply here with those details (or open a new issue) and we'll take another look. In the meantime, #42412 (directories keeping old OpenAI routing after credentials change) and #49847 (ChatGPT OAuth requests sent with the Zen API key) may be worth checking. Thanks for reporting!
zenixls2 commentedon Nov 18, 2026
@thdxr sorry for randomly pick you out.
It seems the opencodejr is not smart enough, or it simply failed to fetch all the user replies in the issue.
I think my report contains the method of "OAuth", which should be categorized to ChatGPT subscription.
I'm not sure who is in charge of the development of opencodejr, but we definitely need to fix it.
This issue seem to happen when people upgrade from opencode v1 to v2.
Could anyone from opencode to treat this issue with humanity?
opencodejr commentedon Nov 18, 2026
Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.
Sorry for the earlier close. Your reply from 3 November had everything we needed, and I should have picked it up.
I was able to reproduce the routing problem you found on 2.2.5, and it still happens on the latest
dev(63bfe62):chatgpt-browser) exists.opencode --standaloneprocess adds the ChatGPT OAuth credential.baseURL: https://api.openai.com/v1and gets nochatgpt-account-idheaders. A directory opened afterwards getshttps://chatgpt.com/backend-api/codexwith the ChatGPT headers. That is the same split you saw between your failing and working directories.opencode api DELETE '/api/debug/location?…', as you found) fixes the routing.I used a fake credential and sent no real request, so I didn't see the 401 itself. Sending a ChatGPT token to the public endpoint is what produced the same
Missing scopes: api.responses.writeerror in #34765. I also haven't confirmed that a separate process wrote the credential in your case (for example during the 2.2.2 → 2.2.5 upgrade). That is one way into this state; there may be others. The script below shows the routing mismatch.Until it's fixed, you can evict the affected directory's location, or restart the background service (
opencode service restart), to get the right routing back.Reproduction script (repro.sh)
Run it:
bash repro.sh