xonecas.io
6312
Ga

go-opencode-ai-zen-sdk / commit 7bc66d7

fix: timeout canceling long streams

xonecas2026-02-19 7bc66d7327003b1ffe742e084916516532027e4d parent b006ac8

2 files changed

README.md+10−0
@@ -142,3 +142,13 @@ This project is not affiliated with opencode.ai.
142142 - `claude-*` -> `/messages`
143143 - `gemini-*` -> `/models/<model>`
144144 - fallback -> `/chat/completions`
145+- **Streaming and timeouts:** `Config.Timeout` defaults to `0` (no timeout). Do not
146+ set it for streaming calls — `http.Client.Timeout` is a total round-trip deadline
147+ that fires while the SSE body is still being read, causing spurious
148+ `context deadline exceeded (Client.Timeout ...)` errors. Use the request
149+ `context.Context` to enforce deadlines instead:
150+ ```go
151+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
152+ defer cancel()
153+ events, errs, err := client.UnifiedStream(ctx, req)
154+ ```
config.go+7−6
@@ -16,8 +16,13 @@ type RetryConfig struct {
1616 }
1717
1818 type Config struct {
19- APIKey string
20- BaseURL string
19+ APIKey string
20+ BaseURL string
21+ // Timeout sets http.Client.Timeout on the internal HTTP client.
22+ // Leave at 0 (the default) for streaming calls — http.Client.Timeout is a
23+ // total round-trip deadline that fires while the response body is still being
24+ // read, which breaks SSE streams that run longer than the timeout.
25+ // Use the request context to enforce deadlines on streaming calls instead.
2126 Timeout time.Duration
2227 UserAgent string
2328 HTTPClient *http.Client
@@ -35,10 +40,6 @@ func (c *Config) applyDefaults() error {
3540
3641 c.BaseURL = strings.TrimRight(c.BaseURL, "/")
3742
38- if c.Timeout == 0 {
39- c.Timeout = 60 * time.Second
40- }
41-
4243 if strings.TrimSpace(c.UserAgent) == "" {
4344 c.UserAgent = "go-opencode-zen-sdk/0.1"
4445 }