MCPcopy Create free account
hub / github.com/anomalyco/opencode-sdk-python / AsyncAPIClient

Class AsyncAPIClient

src/opencode_ai/_base_client.py:1348–1811  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1346
1347
1348class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
1349 _client: httpx.AsyncClient
1350 _default_stream_cls: type[AsyncStream[Any]] | None = None
1351
1352 def __init__(
1353 self,
1354 *,
1355 version: str,
1356 base_url: str | URL,
1357 _strict_response_validation: bool,
1358 max_retries: int = DEFAULT_MAX_RETRIES,
1359 timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
1360 http_client: httpx.AsyncClient | None = None,
1361 custom_headers: Mapping[str, str] | None = None,
1362 custom_query: Mapping[str, object] | None = None,
1363 ) -> None:
1364 if not is_given(timeout):
1365 # if the user passed in a custom http client with a non-default
1366 # timeout set then we use that timeout.
1367 #
1368 # note: there is an edge case here where the user passes in a client
1369 # where they've explicitly set the timeout to match the default timeout
1370 # as this check is structural, meaning that we'll think they didn't
1371 # pass in a timeout and will ignore it
1372 if http_client and http_client.timeout != HTTPX_DEFAULT_TIMEOUT:
1373 timeout = http_client.timeout
1374 else:
1375 timeout = DEFAULT_TIMEOUT
1376
1377 if http_client is not None and not isinstance(http_client, httpx.AsyncClient): # pyright: ignore[reportUnnecessaryIsInstance]
1378 raise TypeError(
1379 f"Invalid `http_client` argument; Expected an instance of `httpx.AsyncClient` but got {type(http_client)}"
1380 )
1381
1382 super().__init__(
1383 version=version,
1384 base_url=base_url,
1385 # cast to a valid type because mypy doesn't understand our type narrowing
1386 timeout=cast(Timeout, timeout),
1387 max_retries=max_retries,
1388 custom_query=custom_query,
1389 custom_headers=custom_headers,
1390 _strict_response_validation=_strict_response_validation,
1391 )
1392 self._client = http_client or AsyncHttpxClientWrapper(
1393 base_url=base_url,
1394 # cast to a valid type because mypy doesn't understand our type narrowing
1395 timeout=cast(Timeout, timeout),
1396 )
1397
1398 def is_closed(self) -> bool:
1399 return self._client.is_closed
1400
1401 async def close(self) -> None:
1402 """Close the underlying HTTPX client.
1403
1404 The client will *not* be usable after this.
1405 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected