Skip to content

SDK SSE client ignores custom fetch - blocks containerized/sandboxed environments #10077

Closed

Description

@kalepail

Description

The @opencode-ai/sdk SSE client in serverSentEvents.gen.js calls the global fetch() instead of options.fetch, which means custom fetch implementations are ignored for SSE subscriptions. This blocks usage in containerized environments (like Cloudflare Sandbox) that require custom fetch adapters.

Bug Location:

  • File: node_modules/@opencode-ai/sdk/dist/gen/core/serverSentEvents.gen.js
  • Line 20:
const response = await fetch(url, { ...options, headers, signal });

This calls the global fetch() directly instead of using options.fetch.

Expected Behavior:
The SSE client should use the custom fetch if provided:

const _fetch = options.fetch ?? globalThis.fetch;
const response = await _fetch(request);

Root Cause: The SDK's client architecture correctly supports custom fetch (client.gen.js:16 merges it, client.gen.js:137-146 passes it to createSseClient), but serverSentEvents.gen.js:20 ignores it.

Upstream Fix Available: This is fixed in @hey-api/openapi-ts:
https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@hey-api/client-core/bundle/serverSentEvents.ts#L111-L113

Request: Please regenerate the SDK with the latest @hey-api/openapi-ts version.

Related: hey-api/hey-api#772

Plugins

N/A - using SDK programmatically in Cloudflare Workers

OpenCode version

@opencode-ai/sdk: 1.1.31

Steps to reproduce

  1. Create OpenCode client with custom fetch: createOpencodeClient({ fetch: customFetch })
  2. Call client.event.subscribe()
  3. Observe that customFetch is never called - global fetch() is used instead

Screenshot and/or share link

N/A - SDK bug, not UI issue

Operating System

Cloudflare Workers + Sandbox runtime

Terminal

N/A - headless/programmatic usage

Activity

  1. github-actions commented on Jan 22, 2026

    @github-actions
    Contributor

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

    Feel free to ignore if none of these address your specific case.

  2. mrlubos commented on Jan 24, 2026

    @mrlubos
    Contributor

    @kalepail I'm pretty sure OpenCode is using the version with the code you shared, are you sure that's where the issue is? You could also open an issue upstream if it's broken in https://github.com/hey-api/openapi-ts

  3. kalepail commented on Jan 26, 2026

    @kalepail
    Author

    Any time I've tried to use the events streaming at least with Cloudflare Workers it doesn't work. When I set to consuming events myself with my own interpreter it does. I don't know much about the project but whenever I point any LLM at it they all agree and can confirm by looking at the underlying compiled code that it's using the wrong fetch for event streaming

  4. mrlubos commented on Jan 26, 2026

    @mrlubos
    Contributor

    Do let me know if this is an issue in Hey API, I'd look into it

  5. goleary commented on Feb 5, 2026

    @goleary

    Same here. We can't subscribe to events through the sdk (from a cloudflare worker/DO) when we are running opencode on a cloudflare sandbox (because @cloudflare/sandbox passes containerFetch which is not honored when using client.event.subscribe)

    For now we're working around it by using sandbox.containerFetch directly for the SSE /event endpoint and parsing the stream manually.

  6. github-actions commented on Apr 7, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

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