Skip to content

[Go SDK] AI client cannot accept a custom HTTP client or transport #437

@santoshkumarradha

Description

@santoshkumarradha

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

  • NewClient(WithHTTPClient(myClient)) uses myClient for all requests instead of creating a new one
  • NewClient(WithTransport(myTransport)) uses myTransport as the round-tripper while keeping the configured timeout
  • Without these options, NewClient behaves exactly as before
  • Tests pass (go test ./sdk/go/...)
  • Linting passes (make lint)

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:aiAI/LLM integrationbugSomething isn't workingenhancementNew feature or requestsdk:goGo SDK related

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions