Skip to main content

enterprise_ai.core.transport

Source: sdks/python/src/enterprise_ai/_core/transport.py. Back to the Python SDK reference index.

note

This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.

Model ClientConfig​

Connection settings. Values not given fall back to EAI_* environment variables.

Fields:

NameTypeRequiredDescription
base_urlstr | NonenoAddress of the API, trailing slash removed and validated. Env: EAI_BASE_URL, a local address by default.
api_keystr | NonenoAPI key sent in the X-API-Key header. Env: EAI_API_KEY.
tokenstr | NonenoAccess token of the Hub. Write only, sealed; null keeps the stored token.
tenantstr | NonenoTenant slug.
projectstr | NonenoIdentifier of the project the results are restricted to.
environmentstr | NonenoTarget environment sent in the X-Environment header. Env: EAI_ENVIRONMENT.
localestr | NonenoLanguage of the messages, sent in Accept-Language, for example fr; resolved from the environment when not given.
timeoutfloatnoTimeout of each HTTP request, in seconds. Default 30.0.
retriesintnoNumber of retries after the first attempt on a transient failure. Default 3.
backofffloatnoBase delay in seconds of the exponential retry backoff (doubled on each attempt, plus jitter). Default 0.5.
max_backofffloatnoUpper bound in seconds of the delay between two retries, Retry-After included. Default 20.0.
dev_userstr | NonenoUser sent in X-Dev-User when no token nor API key is set and a tenant is; sdk-dev by default. Env: EAI_DEV_USER.
dev_rolesstr | NonenoRoles sent in X-Dev-Roles when no token nor API key is set and a tenant is. Env: EAI_DEV_ROLES.
traceparentstr | NonenoW3C traceparent sent when no operation of enterprise_ai.telemetry sets one.
headersdict[str, str]noHeaders of the event, string values. The trace context is added.
ca_bundlestr | NonenoPEM bundle of extra trusted certificate authorities; verification stays on. Env: EAI_CA_BUNDLE.
dangerously_disable_tls_verification_for_localhostboolnoDisable TLS certificate verification; refused with ValueError unless the base URL host is local. Default False.

ClientConfig.default_headers​

default_headers() -> dict[str, str]

Headers sent with every request (auth, tenancy, locale, user agent).

This element takes no parameter.

Returns: dict[str, str]. Header name to value: Accept, Accept-Language, User-Agent, then the auth, X-Dev-*, X-Project, X-Environment and custom headers.

ClientConfig.httpx_options​

httpx_options() -> dict[str, Any]

TLS 1.2+ with verification on (or the explicit localhost opt out), redirects not followed.

This element takes no parameter.

Returns: dict[str, Any]. Keyword arguments for the httpx client: verify (an SSL context) and follow_redirects=False.

Model ApiResponse​

Decoded body plus the response metadata (raw=True calls).

Fields:

NameTypeRequiredDescription
dataAnyyesDecoded body of the response: JSON value, text, or None for an empty answer.
statusintyesHTTP status code of the response, for example 200.
headershttpx.HeadersyesHeaders of the event, string values. The trace context is added.

Attributes:

NameTypeRequiredDescription
cost_estimatedstr | NoneyesEstimated cost of the call, read from the x-eai-cost-estimated response header, or None.
cost_measuredstr | NoneyesMeasured cost of the call, read from the x-eai-cost-measured response header, or None.
decision_idstr | NoneyesIdentifier of the policy decision, read from the x-eai-decision-id response header, or None.
request_idstr | NoneyesRequest identifier, read from the x-request-id response header, or None.

Model Call​

One prepared API call. template is the documented path template.

Fields:

NameTypeRequiredDescription
methodstryesName of the method, for example basic, token or none.
templatestryesDocumented path template the call was built from, for example /v1/catalog/bricks/{id}.
pathstryesPath with its placeholders filled and URL encoded, relative to the base URL.
paramsdict[str, Any] | NonenoQuery parameters, with None values already removed, or None.
jsonAnynoValue sent as the JSON request body, or None.
filesAnynoFiles to import (1 to 200).
dataAnynoForm fields of the request (with files, a multipart body), or None.
headersdict[str, str]noHeaders of the event, string values. The trace context is added.
idempotency_keystr | NonenoValue of the Idempotency-Key header; when set, the call is retried even if its method is not idempotent.
rawboolnoWhen True, the call returns an ApiResponse with the status and headers instead of the decoded body only. Default False.
contentbytes | NonenoRaw bytes sent as the request body, or None.

Class SyncTransport​

Blocking transport over :class:httpx.Client.

_BaseTransport

Attributes:

NameTypeRequiredDescription
httpyesUnderlying httpx.Client that sends the requests.

Constructor SyncTransport​

SyncTransport(config: ClientConfig, http_client: httpx.Client | None = None, **httpx_kwargs: Any) -> None

Create the transport, building an httpx.Client from the configuration unless one is given.

NameTypeDefaultRequiredDescription
configClientConfigyesConnection settings (ClientConfig): base URL, credentials, timeout and retry policy.
http_clienthttpx.Client | NoneNonenoExisting httpx.Client to use as is; by default a new one is created with the configured base URL, timeout and TLS options.
**httpx_kwargsAnynoExtra options passed to httpx.Client; verify and follow_redirects=True are refused with ValueError.

SyncTransport.close​

close() -> None

Close the underlying HTTP client and its connections.

This element takes no parameter.

Returns: None.

SyncTransport.paginate​

paginate(method: str, template: str, args: tuple[Any, ...] = (), **kwargs: Any) -> Page

Send a listing call and return its first page as a Page.

NameTypeDefaultRequiredDescription
methodstryesHTTP method of the call, for example GET (upper cased).
templatestryesDocumented path template, for example /v1/catalog/bricks/{id}.
argstuple[Any, ...]()noValues of the path placeholders, in order; they are URL encoded.
**kwargsAnynoOptions of the call: params, json, files, data, content, headers, idempotent, idempotency_key, raw.

Returns: Page. A Page: First page of a {items, next_cursor} listing. Iterating follows every cursor.

SyncTransport.request​

request(method: str, template: str, args: tuple[Any, ...] = (), **kwargs: Any) -> Any

Prepare and send one call, then return its decoded body.

NameTypeDefaultRequiredDescription
methodstryesHTTP method of the call, for example GET (upper cased).
templatestryesDocumented path template, for example /v1/catalog/bricks/{id}.
argstuple[Any, ...]()noValues of the path placeholders, in order; they are URL encoded.
**kwargsAnynoOptions of the call: params, json, files, data, content, headers, idempotent, idempotency_key, raw.

Returns: Any. Decoded body (JSON value, text or None for an empty answer), or an ApiResponse when raw=True.

SyncTransport.send​

send(call: Call, stream: bool = False) -> httpx.Response

Send with retries; raises the typed error on a final failure.

NameTypeDefaultRequiredDescription
callCallyesPrepared Call to send.
streamboolFalsenoWhen True, the body is not read up front so it can be consumed as a stream. Default False.

Returns: httpx.Response. The successful httpx.Response (status below 400).

Raises: TransportError.

SyncTransport.sse​

sse(method: str, template: str, args: tuple[Any, ...] = (), **kwargs: Any) -> Iterator[ServerSentEvent]

Open a Server Sent Events stream (Accept: text/event-stream) and return an iterator of its events.

NameTypeDefaultRequiredDescription
methodstryesHTTP method of the call, for example GET (upper cased).
templatestryesDocumented path template, for example /v1/catalog/bricks/{id}.
argstuple[Any, ...]()noValues of the path placeholders, in order; they are URL encoded.
**kwargsAnynoOptions of the call: params, json, files, data, content, headers, idempotent, idempotency_key, raw.

Returns: Iterator[ServerSentEvent]. A ServerSentEvent: One SSE event. data is the raw text; :meth:json decodes it.

Class AsyncTransport​

Non blocking transport over :class:httpx.AsyncClient.

_BaseTransport

Attributes:

NameTypeRequiredDescription
httpyesUnderlying httpx.AsyncClient that sends the requests.
sleepyesFunction awaited between retries; asyncio.sleep by default, replaceable in tests.

Constructor AsyncTransport​

AsyncTransport(config: ClientConfig, http_client: httpx.AsyncClient | None = None, **httpx_kwargs: Any) -> None

Create the transport, building an httpx.AsyncClient from the configuration unless one is given.

NameTypeDefaultRequiredDescription
configClientConfigyesConnection settings (ClientConfig): base URL, credentials, timeout and retry policy.
http_clienthttpx.AsyncClient | NoneNonenoExisting httpx.AsyncClient to use as is; by default a new one is created with the configured base URL, timeout and TLS options.
**httpx_kwargsAnynoExtra options passed to httpx.AsyncClient; verify and follow_redirects=True are refused with ValueError.

AsyncTransport.close​

async close() -> None

Close the underlying HTTP client and its connections (a coroutine).

This element takes no parameter.

Returns: None.

AsyncTransport.paginate​

async paginate(method: str, template: str, args: tuple[Any, ...] = (), **kwargs: Any) -> AsyncPage

Send a listing call and return its first page as an AsyncPage (a coroutine).

NameTypeDefaultRequiredDescription
methodstryesHTTP method of the call, for example GET (upper cased).
templatestryesDocumented path template, for example /v1/catalog/bricks/{id}.
argstuple[Any, ...]()noValues of the path placeholders, in order; they are URL encoded.
**kwargsAnynoOptions of the call: params, json, files, data, content, headers, idempotent, idempotency_key, raw.

Returns: AsyncPage. A AsyncPage: Async counterpart of :class:Page (async for item in page).

AsyncTransport.request​

async request(method: str, template: str, args: tuple[Any, ...] = (), **kwargs: Any) -> Any

Prepare and send one call, then return its decoded body (a coroutine).

NameTypeDefaultRequiredDescription
methodstryesHTTP method of the call, for example GET (upper cased).
templatestryesDocumented path template, for example /v1/catalog/bricks/{id}.
argstuple[Any, ...]()noValues of the path placeholders, in order; they are URL encoded.
**kwargsAnynoOptions of the call: params, json, files, data, content, headers, idempotent, idempotency_key, raw.

Returns: Any. Decoded body (JSON value, text or None for an empty answer), or an ApiResponse when raw=True.

AsyncTransport.send​

async send(call: Call, stream: bool = False) -> httpx.Response

Send a prepared call with retries on transient failures; raises the typed error on a final failure (a coroutine).

NameTypeDefaultRequiredDescription
callCallyesPrepared Call to send.
streamboolFalsenoWhen True, the body is not read up front so it can be consumed as a stream. Default False.

Returns: httpx.Response. The successful httpx.Response (status below 400).

Raises: TransportError.

AsyncTransport.sse​

sse(method: str, template: str, args: tuple[Any, ...] = (), **kwargs: Any) -> AsyncIterator[ServerSentEvent]

Open a Server Sent Events stream (Accept: text/event-stream) and return an async iterator of its events.

NameTypeDefaultRequiredDescription
methodstryesHTTP method of the call, for example GET (upper cased).
templatestryesDocumented path template, for example /v1/catalog/bricks/{id}.
argstuple[Any, ...]()noValues of the path placeholders, in order; they are URL encoded.
**kwargsAnynoOptions of the call: params, json, files, data, content, headers, idempotent, idempotency_key, raw.

Returns: AsyncIterator[ServerSentEvent]. A ServerSentEvent: One SSE event. data is the raw text; :meth:json decodes it.

Class Page​

First page of a {items, next_cursor} listing. Iterating follows every cursor.

Attributes:

NameTypeRequiredDescription
itemsyesElements of this page only (a list).
next_cursoryesCursor of the following page, or None on the last page.
rawyesDecoded response body of this page, as received.

Constructor Page​

Page(transport: SyncTransport, call: Call, payload: Any) -> None

Wrap the decoded payload of a listing call; the call is kept to fetch the following pages.

NameTypeDefaultRequiredDescription
transportSyncTransportyesTransport shared by the sub-clients of one client.
callCallyesPrepared Call that produced this page, reused with the cursor query parameter for the next page.
payloadAnyyesDecoded response body: an {items, next_cursor} object, a plain list or a single value.

Page.next_page​

next_page() -> Page | None

Fetch the following page, or None at the end.

This element takes no parameter.

Returns: Page \| None. A Page: First page of a {items, next_cursor} listing. Iterating follows every cursor.

Class AsyncPage​

Async counterpart of :class:Page (async for item in page).

Attributes:

NameTypeRequiredDescription
itemsyesElements of this page only (a list).
next_cursoryesCursor of the following page, or None on the last page.
rawyesDecoded response body of this page, as received.

Constructor AsyncPage​

AsyncPage(transport: AsyncTransport, call: Call, payload: Any) -> None

Wrap the decoded payload of a listing call; the call is kept to fetch the following pages.

NameTypeDefaultRequiredDescription
transportAsyncTransportyesTransport shared by the sub-clients of one client.
callCallyesPrepared Call that produced this page, reused with the cursor query parameter for the next page.
payloadAnyyesDecoded response body: an {items, next_cursor} object, a plain list or a single value.

AsyncPage.next_page​

async next_page() -> AsyncPage | None

Fetch the following page, or return None at the end of the listing.

This element takes no parameter.

Returns: AsyncPage \| None. A AsyncPage: Async counterpart of :class:Page (async for item in page).

Class Resource​

Base of every sub-client. Methods map 1:1 to documented API paths.

Constructor Resource​

Resource(transport: SyncTransport | AsyncTransport, client: Any = None) -> None

Bind the sub-client to a sync or async transport and, optionally, to its parent client.

NameTypeDefaultRequiredDescription
transportSyncTransport | AsyncTransportyesTransport shared by the sub-clients of one client.
clientAnyNonenoParent client.

Functions​

new_traceparent​

new_traceparent() -> str

Generate a fresh sampled W3C traceparent.

This element takes no parameter.

Returns: str. A traceparent string 00-<32 hex trace id>-<16 hex span id>-01.

expand_path​

expand_path(template: str, args: tuple[Any, ...]) -> str

Fill {placeholders} of template in order with URL encoded args.

NameTypeDefaultRequiredDescription
templatestryesPath template with {name} placeholders, for example /v1/catalog/bricks/{id}.
argstuple[Any, ...]yesValues of the placeholders, in order; a missing or extra value raises ValueError.

Returns: str. The filled path, each value URL encoded with no safe character.

Raises: ValueError.

retry_delay​

retry_delay(attempt: int, response: httpx.Response | None, backoff: float, max_backoff: float) -> float

Delay before retry attempt (0 based), honoring Retry-After (seconds or HTTP date).

NameTypeDefaultRequiredDescription
attemptintyesIndex of the retry, starting at 0; the backoff doubles on each one.
responsehttpx.Response | NoneyesFailed response whose Retry-After header is honored, or None after a network error.
backofffloatyesBase delay in seconds of the exponential backoff.
max_backofffloatyesUpper bound of the returned delay, in seconds.

Returns: float. Delay in seconds: Retry-After capped at max_backoff, otherwise backoff * 2**attempt plus up to half of it as jitter, capped.

then​

then(result: Any, fn: Callable[[Any], Any]) -> Any

Apply fn to a sync result, or chain it after an awaitable one (async client).

NameTypeDefaultRequiredDescription
resultAnyyesValue returned by a sync call, or a coroutine or future returned by an async call.
fnCallable[[Any], Any]yesFunction applied to the resolved result.

Returns: Any. fn(result) directly, or a coroutine that awaits result and then applies fn.

body​

body(**fields: Any) -> dict[str, Any]

Build a JSON body, dropping None values and merging an extra dict.

NameTypeDefaultRequiredDescription
**fieldsAnynoFields of the body as keyword arguments; None values are dropped and the extra dict is merged last.

Returns: dict[str, Any]. The JSON body as a dict.