Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Googleapis Python genai ReplayApiClient

From Leeroopedia
Knowledge Sources
Domains Testing, API_Infrastructure
Last Updated 2026-02-15 14:00 GMT

Overview

Concrete tool for recording and replaying API interactions for deterministic testing.

Description

The ReplayApiClient extends BaseApiClient to support record/replay testing modes. In record mode, it captures HTTP interactions to JSON files. In replay mode, it serves responses from recorded files without making actual API calls. It also provides request redaction for sensitive data and case-insensitive request matching.

Usage

Used by the SDK test suite for deterministic, offline testing of API interactions without requiring real API credentials or network access.

Code Reference

Source Location

Signature

class ReplayApiClient(BaseApiClient):
    def __init__(
        self,
        mode: Literal['record', 'replay', 'auto', 'api'],
        replay_id: str,
        replays_directory: Optional[str] = None,
        vertexai: bool = False,
        api_key: Optional[str] = None,
        credentials: Optional[google.auth.credentials.Credentials] = None,
        project: Optional[str] = None,
        location: Optional[str] = None,
        http_options: Optional[HttpOptions] = None,
        private: bool = False,
    ) -> None: ...

    def initialize_replay_session(self, replay_id: str) -> None: ...
    def close(self) -> None: ...

Import

from google.genai._replay_api_client import ReplayApiClient

I/O Contract

Inputs

Name Type Required Description
mode Literal['record', 'replay', 'auto', 'api'] Yes Operating mode
replay_id str Yes Unique identifier for the replay session
replays_directory str No Directory for storing replay files
vertexai bool No Whether to use Vertex AI backend

Outputs

Name Type Description
_request returns HttpResponse Response from API or replay file
close() None Writes recorded interactions to replay file

Usage Examples

from google.genai._replay_api_client import ReplayApiClient

# Create a replay client for testing
client = ReplayApiClient(
    mode="replay",
    replay_id="test_generate_content",
    replays_directory="google/genai/tests",
)

# Use the client normally - responses come from recorded files
response = client._request(http_request)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment