Summary
NewClient in the Go SDK AI package always constructs its own http.Client with only a timeout, providing no way to inject a custom transport, proxy, or mock for tests.
Context
client.go:29 in sdk/go/ai creates &http.Client{Timeout: cfg.Timeout} unconditionally. There is no option to pass a custom http.RoundTripper or an existing *http.Client. This blocks several common production requirements: corporate-proxy transports, custom TLS root CAs, retry middleware (e.g. hashicorp/go-retryablehttp), shared connection-pool tuning, and — most critically — deterministic HTTP mocking in unit tests. The sdk/go/client package already supports this via WithHTTPClient; the AI client should follow the same pattern.
Scope
In Scope
- Add
WithHTTPClient(c *http.Client) ClientOption option to NewClient.
- Add
WithTransport(t http.RoundTripper) ClientOption option that wraps the default client's transport.
- When neither option is provided, use the existing default
http.Client{Timeout: cfg.Timeout} behavior.
Out of Scope
- Adding retry logic —
WithTransport enables callers to inject retry transports themselves.
- Changing any request or response logic.
- Modifying
sdk/go/client — it already has this feature.
Files
sdk/go/ai/client.go:29 — add ClientOption func type and WithHTTPClient / WithTransport options; apply them in NewClient
sdk/go/ai/client_test.go — test: WithHTTPClient injects a mock transport; requests use the injected client; WithTransport wraps correctly
Acceptance Criteria
Notes for Contributors
Severity: MEDIUM
See sdk/go/client/client.go for the existing WithHTTPClient implementation — port that pattern directly. For the test, use httptest.NewServer or an http.RoundTripper mock (e.g. a function implementing RoundTrip) to intercept requests and assert the correct URL and headers are used without making real network calls.
Summary
NewClientin the Go SDK AI package always constructs its ownhttp.Clientwith only a timeout, providing no way to inject a custom transport, proxy, or mock for tests.Context
client.go:29insdk/go/aicreates&http.Client{Timeout: cfg.Timeout}unconditionally. There is no option to pass a customhttp.RoundTripperor an existing*http.Client. This blocks several common production requirements: corporate-proxy transports, custom TLS root CAs, retry middleware (e.g.hashicorp/go-retryablehttp), shared connection-pool tuning, and — most critically — deterministic HTTP mocking in unit tests. Thesdk/go/clientpackage already supports this viaWithHTTPClient; the AI client should follow the same pattern.Scope
In Scope
WithHTTPClient(c *http.Client) ClientOptionoption toNewClient.WithTransport(t http.RoundTripper) ClientOptionoption that wraps the default client's transport.http.Client{Timeout: cfg.Timeout}behavior.Out of Scope
WithTransportenables callers to inject retry transports themselves.sdk/go/client— it already has this feature.Files
sdk/go/ai/client.go:29— addClientOptionfunc type andWithHTTPClient/WithTransportoptions; apply them inNewClientsdk/go/ai/client_test.go— test:WithHTTPClientinjects a mock transport; requests use the injected client;WithTransportwraps correctlyAcceptance Criteria
NewClient(WithHTTPClient(myClient))usesmyClientfor all requests instead of creating a new oneNewClient(WithTransport(myTransport))usesmyTransportas the round-tripper while keeping the configured timeoutNewClientbehaves exactly as beforego test ./sdk/go/...)make lint)Notes for Contributors
Severity: MEDIUM
See
sdk/go/client/client.gofor the existingWithHTTPClientimplementation — port that pattern directly. For the test, usehttptest.NewServeror anhttp.RoundTrippermock (e.g. a function implementingRoundTrip) to intercept requests and assert the correct URL and headers are used without making real network calls.