Implementation:Googleapis Python genai Interactions BaseClient
| Knowledge Sources | |
|---|---|
| Domains | HTTP_Client, SDK_Infrastructure |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
Concrete tool for low-level HTTP client infrastructure with retry logic, pagination, and request/response handling for the _interactions subsystem.
Description
The _base_client module provides BaseClient, SyncAPIClient, and AsyncAPIClient classes that implement HTTP request construction, retry with exponential backoff, response parsing, and pagination. These are the foundation for the Interactions API client that supports the newer Gemini NextGen API surface.
Usage
This is internal infrastructure. Users interact with it indirectly through the Client class when using the Interactions API.
Code Reference
Source Location
- Repository: Googleapis_Python_genai
- File: google/genai/_interactions/_base_client.py
- Lines: 1-2151
Signature
class BaseClient:
def __init__(
self,
*,
version: str,
base_url: str | URL,
_strict_response_validation: bool,
max_retries: int = 5,
timeout: float | Timeout | None = DEFAULT_TIMEOUT,
custom_headers: Mapping[str, str] | None = None,
custom_query: Mapping[str, object] | None = None,
) -> None: ...
class SyncAPIClient(BaseClient):
def request(
self,
cast_to: Type[ResponseT],
options: FinalRequestOptions,
*,
stream: bool = False,
stream_cls: type[_StreamT] | None = None,
) -> ResponseT | _StreamT: ...
class AsyncAPIClient(BaseClient):
async def request(
self,
cast_to: Type[ResponseT],
options: FinalRequestOptions,
*,
stream: bool = False,
stream_cls: type[_StreamT] | None = None,
) -> ResponseT | _StreamT: ...
Import
from google.genai._interactions._base_client import SyncAPIClient, AsyncAPIClient
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| cast_to | Type[ResponseT] | Yes | Target type for response deserialization |
| options | FinalRequestOptions | Yes | Request method, URL, headers, body, timeout |
| stream | bool | No | Whether to return a streaming response |
Outputs
| Name | Type | Description |
|---|---|---|
| request() returns | ResponseT or StreamT | Parsed response or stream object |
Usage Examples
# Internal usage pattern - not directly used by end users
from google.genai._interactions._base_client import SyncAPIClient
from google.genai._interactions._models import FinalRequestOptions
client = SyncAPIClient(
version="1.0.0",
base_url="https://generativelanguage.googleapis.com/",
_strict_response_validation=False,
)