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:
objectFactory 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:
- 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:
- Return type:
- 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:
- Return type:
- 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:
- Returns:
Configured GenAI client instance
- Raises:
ValueError – If client cannot be created