Safe Http Client

Safe HTTP client factory with version compatibility and graceful degradation. Resistant to package upgrades and dependency changes.

This module provides a robust factory for creating HTTP clients that work across different package versions and gracefully degrade when advanced features are not available.

Classes

class arshai.clients.safe_http_client.SafeHttpClientFactory[source]

Bases: object

Factory for creating HTTP clients with safe defaults and version compatibility

static create_openai_client(api_key, use_custom_http_client=True, **kwargs)[source]

Create OpenAI client with safe configuration and version compatibility.

Parameters:
  • api_key (str) – OpenAI API key

  • **kwargs – Additional arguments to pass to OpenAI client

Return type:

Any

Returns:

Configured OpenAI client instance

Raises:

ValueError – If client cannot be created with any configuration

static create_azure_openai_client(azure_deployment, api_version, use_custom_http_client=True, **kwargs)[source]

Create Azure OpenAI client with safe configuration and version compatibility.

Parameters:
  • azure_deployment (str) – Azure deployment name

  • api_version (str) – Azure API version

  • use_custom_http_client (bool) – Whether to try using custom httpx client

  • **kwargs – Additional arguments to pass to AzureOpenAI client

Return type:

Any

Returns:

Configured AzureOpenAI client instance

Raises:

ValueError – If client cannot be created with any configuration

static create_openrouter_client(api_key, base_url, default_headers, use_custom_http_client=True, **kwargs)[source]

Create OpenRouter client with safe configuration and version compatibility.

Parameters:
  • api_key (str) – OpenRouter API key

  • base_url (str) – OpenRouter base URL

  • default_headers (dict) – OpenRouter headers

  • use_custom_http_client (bool) – Whether to try using custom httpx client

  • **kwargs – Additional arguments to pass to OpenAI client

Return type:

Any

Returns:

Configured OpenAI client instance for OpenRouter

Raises:

ValueError – If client cannot be created with any configuration

static create_genai_client(**kwargs)[source]

Create Google GenAI client with safe configuration.

Parameters:

**kwargs – Arguments to pass to GenAI client

Return type:

Any

Returns:

Configured GenAI client instance

Raises:

ValueError – If client cannot be created

class arshai.clients.safe_http_client.VersionMonitor[source]

Bases: object

Monitor package versions and alert on significant changes

static log_environment_info()[source]

Log current package versions for debugging

static check_compatibility()[source]

Check if current package versions are known to work

static validate_configuration()[source]

Validate that HTTP client configurations work