Expand description
§HTTP Client Implementation
Provides a robust HTTP client for communicating with the Zhipu AI API. This module implements connection pooling, error handling, and request/response processing.
§Features
- Connection Pooling - Reuses HTTP connections for better performance
- Error Handling - Comprehensive error parsing and reporting
- Authentication - Bearer token authentication support
- Retry with Jitter - Automatic retry with exponential backoff and random jitter
- Sensitive Data Masking - Automatic masking of API keys in logs
- Structured Logging - Uses tracing for detailed request/response logging
§Usage
The HttpClient trait provides a standardized interface for making HTTP
requests to the Zhipu AI API endpoints.
§Retry Configuration
The HTTP client supports configurable retry behavior:
ⓘ
use zai_rs::client::http::HttpClientConfig;
let config = HttpClientConfig::builder()
.max_retries(5)
.timeout(Duration::from_secs(120))
.retry_delay(RetryDelay::exponential(Duration::from_millis(100), Duration::from_secs(10)))
.build();Structs§
- Http
Client Config - Configuration for HTTP client behavior.
- Http
Client Config Builder - Builder for creating
HttpClientConfiginstances.
Enums§
- Retry
Delay - Retry delay strategy.
Traits§
- Http
Client - Trait for HTTP clients that communicate with the Zhipu AI API.
Functions§
- http_
client_ with_ config - Get or create an HTTP client with the specified configuration
- parse_
api_ error_ response - Parse an API error response body into a ZaiError.
- parse_
typed_ response - Parse a successful HTTP response into a typed value.
- send_
empty_ request - Send a request without a JSON body through the shared transport pipeline.
- send_
json_ request - Send a JSON request through the shared transport pipeline.
- send_
multipart_ request - Send a multipart/form-data request through the shared transport pipeline.