-
Notifications
You must be signed in to change notification settings - Fork 38
Implement get_async_http_client function for async Foundry HTTP clients #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
e1020c8
3e1ee08
9322052
fede5f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,7 +19,7 @@ | |||||
| from foundry_sdk._core.config import Config | ||||||
| from foundry_sdk._core.context_and_environment_vars import HOSTNAME_VAR | ||||||
| from foundry_sdk._core.context_and_environment_vars import TOKEN_VAR | ||||||
| from foundry_sdk._core.http_client import HttpClient | ||||||
| from foundry_sdk._core.http_client import HttpClient, AsyncHttpClient | ||||||
|
|
||||||
|
|
||||||
| def _get_api_gateway_base_url(*, preview: bool = False) -> str: | ||||||
|
|
@@ -125,20 +125,58 @@ def get_http_client(*, preview: bool = False, config: Optional[Config] = None) - | |||||
|
|
||||||
| Raises: | ||||||
| ValueError: If preview is not set to True. | ||||||
| RuntimeError: If the Foundry API gateway base URL or token is not available in the current context. | ||||||
| RuntimeError: If the Foundry token is not available in the current context. | ||||||
| """ | ||||||
| if not preview: | ||||||
| raise ValueError( | ||||||
| "get_http_client() is in beta. " "Please set the preview parameter to True to use it." | ||||||
| ) | ||||||
| token = get_foundry_token(preview=True) | ||||||
|
|
||||||
| # Merge auth header with any user-provided headers | ||||||
| return HttpClient(config=_create_http_client_config(config)) | ||||||
|
|
||||||
|
|
||||||
| def get_async_http_client( | ||||||
| *, preview: bool = False, config: Optional[Config] = None | ||||||
| ) -> AsyncHttpClient: | ||||||
| """Get an async HTTP client configured for the current Foundry environment. | ||||||
|
||||||
|
|
||||||
| Args: | ||||||
| preview: Must be set to True to use this beta feature. | ||||||
| config: Optional configuration for the async HTTP client. | ||||||
|
|
||||||
| Returns: | ||||||
| An AsyncHttpClient instance configured with the Foundry hostname and authentication. | ||||||
|
|
||||||
| Raises: | ||||||
| ValueError: If preview is not set to True. | ||||||
| RuntimeError: If the Foundry token is not available in the current context. | ||||||
| """ | ||||||
| if not preview: | ||||||
| raise ValueError( | ||||||
| "get_async_http_client() is in beta. " | ||||||
| "Please set the preview parameter to True to use it." | ||||||
| ) | ||||||
|
|
||||||
| return AsyncHttpClient(config=_create_http_client_config(config)) | ||||||
|
|
||||||
|
|
||||||
| def _create_http_client_config(config: Optional[Config]) -> Config: | ||||||
|
Comment on lines
+160
to
+163
|
||||||
| """Create a Config object for the HTTP client, ensuring that the Foundry token is included in the headers. | ||||||
|
|
||||||
| Args: | ||||||
| config: An optional Config object provided by the user. | ||||||
|
|
||||||
| Returns: | ||||||
| A Config object with the Foundry token included in the default headers. | ||||||
|
|
||||||
| Raises: | ||||||
| RuntimeError: If the Foundry token is not available in the current context. | ||||||
| """ | ||||||
| token = get_foundry_token(preview=True) | ||||||
| auth_header = {"Authorization": f"Bearer {token}"} | ||||||
|
|
||||||
| if config is None: | ||||||
| config = Config(default_headers=auth_header) | ||||||
| return Config(default_headers=auth_header) | ||||||
| else: | ||||||
| merged_headers = {**auth_header, **(config.default_headers or {})} | ||||||
|
||||||
| merged_headers = {**auth_header, **(config.default_headers or {})} | |
| merged_headers = {**(config.default_headers or {}), **auth_header} |
Copilot
AI
Apr 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_create_http_client_config() only injects auth headers but does not appear to set the Foundry API gateway/base URL (or hostname) when config is None. This likely breaks the stated goal of returning clients 'configured for the current Foundry environment' since the client may not know where to send requests. Consider setting base_url (e.g., using _get_api_gateway_base_url(preview=True)) when constructing a new Config, and when config is provided, preserve its base_url (or fill a default if it’s unset) while still merging headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_create_http_client_config()only injects auth headers but does not appear to set the Foundry API gateway/base URL (or hostname) whenconfig is None. This likely breaks the stated goal of returning clients 'configured for the current Foundry environment' since the client may not know where to send requests. Consider settingbase_url(e.g., using_get_api_gateway_base_url(preview=True)) when constructing a newConfig, and whenconfigis provided, preserve itsbase_url(or fill a default if it’s unset) while still merging headers.