Skip to main content

Module http

Module http 

Source
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§

HttpClientConfig
Configuration for HTTP client behavior.
HttpClientConfigBuilder
Builder for creating HttpClientConfig instances.

Enums§

RetryDelay
Retry delay strategy.

Traits§

HttpClient
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