Skip to content

Conversation

@sachaservan
Copy link

@sachaservan sachaservan commented Jan 5, 2026

What

Expose URLSessionFactory and related delegate protocols as public APIs, and add a new OpenAI initializer that accepts a custom URLSessionFactory for streaming requests.

Why

The official openai-go SDK (and others like openai-node) support custom HTTP clients via option.WithHTTPClient(). This change brings the same capability to the Swift SDK. This change allows full control over all HTTP requests.
Specifically, it allows us to provide custom URLSession implementations for streaming requests (chatsStream, etc.), enabling use cases like custom transport layers, request encryption, or specialized networking requirements.

Affected Areas

  • URLSessionFactory protocol and FoundationURLSessionFactory (now public)
  • URLSessionDelegateProtocol and URLSessionDataDelegateProtocol (now public with AnyObject constraint)
  • OpenAI class (new convenience initializer)
  • ImplicitURLSessionStreamingSessionFactory (accepts custom URLSessionFactory)

The official openai-go SDK (and others) supports custom HTTP client
injection via option.WithHTTPClient(), enabling use cases like
custom transports, proxies, and testing. This change brings
the same capability to the Swift SDK.

Changes:
- Make URLSessionProtocol and related types public
- Add public convenience init accepting customSession parameter

This allows users to provide their own URLSessionProtocol implementation,
similar to how openai-go allows custom http.Client injection.
@sachaservan sachaservan changed the title feat: support custom HTTP client via URLSessionProtocol Add support for custom HTTP client via URLSessionProtocol Jan 5, 2026
Expose URLSessionFactory protocol publicly to allow injecting custom
session factories for streaming requests. This enables custom HTTP
transport implementations to intercept streaming data.

Changes:
- Make URLSessionFactory, URLSessionDelegateProtocol, and
  URLSessionDataDelegateProtocol public
- Add AnyObject constraint to delegate protocols for weak references
- Update ImplicitURLSessionStreamingSessionFactory to accept custom factory
- Add new OpenAI initializer with streamingURLSessionFactory parameter
@sachaservan sachaservan changed the title Add support for custom HTTP client via URLSessionProtocol Add support for custom HTTP transport via URLSessionProtocol and URLSessionFactory Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant