Skip to content

Implement get_async_http_client function for async Foundry HTTP clients#341

Open
daankolthof wants to merge 4 commits intopalantir:developfrom
daankolthof:develop
Open

Implement get_async_http_client function for async Foundry HTTP clients#341
daankolthof wants to merge 4 commits intopalantir:developfrom
daankolthof:develop

Conversation

@daankolthof
Copy link
Copy Markdown

This is needed to use the 'AsyncOpenAI' OpenAI Python client.

@daankolthof daankolthof requested a review from Copilot April 11, 2026 00:45
@changelog-app
Copy link
Copy Markdown

changelog-app bot commented Apr 11, 2026

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

Implement get_async_http_client function for async Foundry HTTP clients

Check the box to generate changelog(s)

  • Generate changelog entry

@changelog-app
Copy link
Copy Markdown

changelog-app bot commented Apr 11, 2026

Successfully generated changelog entry!

Need to regenerate?

Simply interact with the changelog bot comment again to regenerate these entries.


📋Changelog Preview

✨ Features

  • Implement get_async_http_client function for async Foundry HTTP clients (#341)

This comment was marked as outdated.

@daankolthof daankolthof requested a review from Copilot April 11, 2026 01:16
Copy link
Copy Markdown

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 6 comments.


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

token = get_foundry_token(preview=True)

# Merge auth header with any user-provided headers
return HttpClient(config=_create_http_client_config(config))
Copy link

Copilot AI Apr 11, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines +160 to +163
return AsyncHttpClient(config=_create_http_client_config(config))


def _create_http_client_config(config: Optional[Config]) -> Config:
Copy link

Copilot AI Apr 11, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines +176 to +179
return Config(default_headers=auth_header)
else:
merged_headers = {**auth_header, **(config.default_headers or {})}
config = replace(config, default_headers=merged_headers)

return HttpClient(config=config)
return replace(config, default_headers=merged_headers)
Copy link

Copilot AI Apr 11, 2026

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.

Copilot uses AI. Check for mistakes.
config = Config(default_headers=auth_header)
return Config(default_headers=auth_header)
else:
merged_headers = {**auth_header, **(config.default_headers or {})}
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

The merge order allows caller-provided headers to override Authorization, which contradicts the helper’s stated purpose of ensuring the Foundry token is included and can lead to requests being sent with the wrong credentials. If the SDK should guarantee Foundry auth, reverse the merge order so Authorization from auth_header wins (or explicitly set/overwrite only the Authorization key).

Suggested change
merged_headers = {**auth_header, **(config.default_headers or {})}
merged_headers = {**(config.default_headers or {}), **auth_header}

Copilot uses AI. Check for mistakes.
def get_async_http_client(
*, preview: bool = False, config: Optional[Config] = None
) -> AsyncHttpClient:
"""Get an async HTTP client configured for the current Foundry environment.
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

The docstring claims a RuntimeError can be raised when the API gateway base URL is unavailable, but get_async_http_client() no longer computes/validates the base URL in this diff. Either restore base URL configuration/validation (so the documented error can occur), or update the docstring to only describe the errors actually raised via token retrieval/config handling.

Copilot uses AI. Check for mistakes.
Comment on lines +148 to +152
An AsyncHttpClient instance configured with the Foundry hostname and authentication.

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.

This comment was marked as outdated.

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.

2 participants