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
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.