Skip to content

Conversation

@csgulati09
Copy link
Contributor

Title: Default base_url for HTTP Client

Description:

  • Adds default base_url to passed http client if not passed by the user

Motivation:
Sid asked for it

Related Issues:
Fixes: #402

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. auto:enhancement labels Oct 30, 2025
@VisargD VisargD requested a review from Copilot November 14, 2025 08:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds default base URL handling for custom HTTP clients passed to Portkey's sync and async client constructors. When users provide their own HTTP client without a base URL, the client will now inherit the base URL from the Portkey client configuration.

Key Changes:

  • Added base URL defaulting logic for custom HTTP clients in both sync and async client constructors
  • Ensures custom HTTP clients use Portkey's base URL when no base URL is explicitly set

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

self.allHeaders = self._build_headers(create_model_instance(Options))
if http_client:
http_client.base_url = (
http_client.base_url if http_client.base_url != "" else self.base_url
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison http_client.base_url != \"\" may not correctly handle all cases where base_url is unset. HTTPX's base_url is a URL object, not a string, and when unset it defaults to an empty URL object (which doesn't equal an empty string). Consider using if not http_client.base_url or str(http_client.base_url) == \"\" for a more robust check.

Suggested change
http_client.base_url if http_client.base_url != "" else self.base_url
http_client.base_url if http_client.base_url and str(http_client.base_url) != "" else self.base_url

Copilot uses AI. Check for mistakes.
self.allHeaders = self._build_headers(create_model_instance(Options))
if http_client:
http_client.base_url = (
http_client.base_url if http_client.base_url != "" else self.base_url
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison http_client.base_url != \"\" may not correctly handle all cases where base_url is unset. HTTPX's base_url is a URL object, not a string, and when unset it defaults to an empty URL object (which doesn't equal an empty string). Consider using if not http_client.base_url or str(http_client.base_url) == \"\" for a more robust check.

Suggested change
http_client.base_url if http_client.base_url != "" else self.base_url
http_client.base_url if (http_client.base_url and str(http_client.base_url) != "") else self.base_url

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto:enhancement size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Http Client

2 participants