Skip to content

SSE event subscription ignores custom fetch (Basic Auth broken) #28180

Closed as not planned

Description

@antronic

Description

createOpencodeClient({ fetch }) allows passing a custom fetch implementation for authentication (e.g., Basic Auth, Bearer tokens, or custom headers). While the standard API endpoints honor this setting, the SSE client used for events (client.event.subscribe()) was hard-coded to use the global fetch.

This causes SSE connections to fail with 401 Unauthorized errors when the server is protected, leading to a silent reconnection loop.

OpenCode version

1.14.41

Steps to reproduce

  1. Start an OpenCode server behind Basic Auth.
  2. Initialize the client with a custom fetch:
    const client = createOpencodeClient({
      baseUrl: "...",
      fetch: (req) => {
        const headers = new Headers(req.headers);
        headers.set("Authorization", "Basic ...");
        return globalThis.fetch(new Request(req, { headers }));
      }
    });
  3. Call client.session.list() (works).
  4. Call client.event.subscribe() (fails with 401, retries forever).

Screenshot and/or share link

N/A

Operating System

macOS / Linux

Terminal

zsh / bash

Activity

  1. github-actions commented on May 18, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of an existing issue. Please check:

  2. nexxeln commented on May 18, 2026

    @nexxeln
    Contributor

    you can use @opencode-ai/sdk/v2 for now as a workaround, that path already respects custom fetch.

  3. rekram1-node commented on Jun 24, 2026

    @rekram1-node
    Contributor

    Closing as duplicate of #10077. This concerns the legacy OpenCode JavaScript SDK event SSE client rather than authentication to an MCP server. The generated SDK v2 path respects the configured custom fetch, which is the recommended workaround/current path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions