Skip to content

provider: api.responses.write scope error after upgrade #61342

Open

Description

@zenixls2

Summary

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

  1. Upgrade OpenCode (exact previous and new versions not recorded).
  2. Open or resume a session in a project directory.
  3. 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.

Activity

  1. opencodejr commented on Nov 3, 2026

    @opencodejr
    Contributor

    Thanks for the report! To work out where this comes from, could you add a few details?

    1. 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?
    2. 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?
    3. Plugins: does it still happen with the third-party plugins (oh-my-openagent, opencode-dcp, opencode-elf, opencode-scheduler) disabled?
    4. Versions: the version you upgraded from, if you can find it.
    5. 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:

  2. zenixls2 commented on Nov 3, 2026

    @zenixls2
    Author

    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:

    timestamp=2026-11-03T05:36:17.029Z level=WARN run=18349acc message="session websocket connect failed; using http" sessionTransport=websocket phase=connect delivery=not-sent code=undefined role=server
    
    timestamp=2026-11-03T05:36:17.740Z level=ERROR run=18349acc message="Failed to drain Session"
    

    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.

  3. zenixls2 commented on Nov 3, 2026

    @zenixls2
    Author

    Additional opencode api delete '/api/debug/location?location%5Bdirectory%5D={path_encoded}' could solve the issue.

  4. opencodejr commented on Nov 6, 2026

    @opencodejr
    Contributor

    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!

  5. zenixls2 commented on Nov 18, 2026

    @zenixls2
    Author

    @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?

  6. added
    area/providers
    type/bug
    version/v2
    and removed on Nov 18, 2026
  7. opencodejr commented on Nov 18, 2026

    @opencodejr
    Contributor

    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):

    1. The background service loads directory A before a ChatGPT OAuth login (method chatgpt-browser) exists.
    2. A separate opencode --standalone process adds the ChatGPT OAuth credential.
    3. 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.
    4. 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 export 2>/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"

    Run it: bash repro.sh

  8. added
    status/repro-simulated
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/providersplatform/macosstatus/repro-simulatedtype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions