Repository: microsoft/semantic-kernel
File: dotnet/src/Connectors/Connectors.OpenAI/Extensions/OpenAIServiceCollectionExtensions.DependencyInjection.cs (C#)

Code before:
        string? apiKey = null,
        string? orgId = null,
        string? serviceId = null,
        HttpClient? httpClient = null,
        string? openTelemetrySourceName = null,
        Action<OpenTelemetryChatClient>? openTelemetryConfig = null)
    {
        Verify.NotNull(services);

        IChatClient Factory(IServiceProvider serviceProvider, object? _)
        {
            var loggerFactory = serviceProvider.GetService<ILoggerFactory>();

            // Get or create HttpClient with proper BaseAddress for the endpoint
            HttpClient clientHttpClient;
            if (httpClient is not null)
            {
                clientHttpClient = httpClient;
            }
            else
            {
                var defaultClient = HttpClientProvider.GetHttpClient(serviceProvider);
                // If using default client and it doesn't have BaseAddress set, create one with the endpoint
                if (defaultClient.BaseAddress is null)
                {
                    clientHttpClient = new HttpClient(new HttpClientHandler())
                    {
                        BaseAddress = endpoint
                    };
                }
                else
                {
                    clientHttpClient = defaultClient;
                }
            }

            var builder = new OpenAIClient(
                    credential: new ApiKeyCredential(apiKey ?? SingleSpace),
                    options: ClientCore.GetOpenAIClientOptions(
                        httpClient: clientHttpClient,
                        endpoint: endpoint,
                        orgId: orgId))
                .GetChatClient(modelId)
                .AsIChatClient()
                .AsBuilder()
                .UseKernelFunctionInvocation(loggerFactory)
                .UseOpenTelemetry(loggerFactory, openTelemetrySourceName, openTelemetryConfig);

            if (loggerFactory is not null)
            {
                builder.UseLogging(loggerFactory);

Review comment (suggestion):
```suggestion
                    Verify.NotNull(endpoint);
                    
                    // A new one needs to be created as we can't cross boundaries and modify an existing client 
                    innerHttpClient = HttpClientProvider.GetHttpClient()
```

Code after:
        string? apiKey = null,
        string? orgId = null,
        string? serviceId = null,
        HttpClient? httpClient = null,
        string? openTelemetrySourceName = null,
        Action<OpenTelemetryChatClient>? openTelemetryConfig = null)
    {
        Verify.NotNull(services);

        IChatClient Factory(IServiceProvider serviceProvider, object? _)
        {
            var loggerFactory = serviceProvider.GetService<ILoggerFactory>();

            // Get or create HttpClient with proper BaseAddress for the endpoint
            HttpClient innerHttpClient;
            if (httpClient is not null)
            {
                innerHttpClient = httpClient;
            }
            else
            {
                var defaultClient = HttpClientProvider.GetHttpClient(serviceProvider);
                // If using default client and it doesn't have BaseAddress set or BaseAddress doesn't match the endpoint, create one with the endpoint
                if (defaultClient.BaseAddress is null || defaultClient.BaseAddress != endpoint)
                {
                    Verify.NotNull(endpoint);

                    // A new one needs to be created as we can't cross boundaries and modify an existing client 
                    innerHttpClient = HttpClientProvider.GetHttpClient();
                    innerHttpClient.BaseAddress = endpoint;
                }
                else
                {
                    innerHttpClient = defaultClient;
                }
            }

            var builder = new OpenAIClient(
                    credential: new ApiKeyCredential(apiKey ?? SingleSpace),
                    options: ClientCore.GetOpenAIClientOptions(
                        httpClient: innerHttpClient,
                        endpoint: endpoint,
                        orgId: orgId))
                .GetChatClient(modelId)
                .AsIChatClient()
                .AsBuilder()
                .UseKernelFunctionInvocation(loggerFactory)
                .UseOpenTelemetry(loggerFactory, openTelemetrySourceName, openTelemetryConfig);

            if (loggerFactory is not null)
            {