Skip to content

AsyncIndex4AI Client API Reference ​

python
from index4ai import AsyncIndex4AI

AsyncIndex4AI is the asyncio counterpart to Index4AI. The surface area is identical — every method has the same name, the same parameters, and the same return type. The only difference is that ingest, search, and document calls are await-able and the constructor takes an httpx.AsyncClient.

Use AsyncIndex4AI inside web servers, agents, and pipelines that already run under an event loop. For scripts and notebooks, Index4AI is simpler.

Constructor ​

python
AsyncIndex4AI(
    api_key: str | None = None,
    *,
    timeout: float = 600.0,
    client: httpx.AsyncClient | None = None,
)

Same semantics as Index4AI(...). Reads INDEX4AI_API_KEY if api_key is omitted; raises InvalidApiKeyError on a missing or wrong-prefix key before any HTTP traffic.

Methods ​

Every method on Index4AI is mirrored as async:

Sync (Index4AI)Async (AsyncIndex4AI)
submit(file_path=None, *, remote_url=None, ...) -> strawait submit(...) -> str
collect(job_id, ...) -> IngestResultawait collect(...) -> IngestResult
ingest(file_path=None, *, remote_url=None, ...) -> IngestResultawait ingest(...) -> IngestResult
search(query, ...) -> SearchContextawait search(...) -> SearchContext
search_in_doc(query, doc_filter, ...) -> SearchContextawait search_in_doc(...) -> SearchContext
list_docs() -> list[DocInfo]await list_docs() -> list[DocInfo]
list_attributes() -> AttributeListawait list_attributes() -> AttributeList
get_doc(doc_id) -> DocInfoawait get_doc(doc_id) -> DocInfo
delete_doc(doc_id) -> DeleteDocResponseawait delete_doc(doc_id) -> DeleteDocResponse
close() -> Noneawait aclose() -> None

Parameter semantics and validation behaviour are identical to the sync client — see Index4AI for the per-method tables.

Lifecycle ​

Use as an async context manager so the underlying httpx.AsyncClient is closed automatically:

python
import asyncio
from index4ai import AsyncIndex4AI

async def main() -> None:
    async with AsyncIndex4AI() as client:
        result = await client.ingest("annual-report.pdf")
        ctx = await client.search("How did operating margin change year over year?")
        print(result.job_id, result.status)
        print(ctx.context)

asyncio.run(main())

If you need to keep the client open across multiple unrelated request scopes (e.g. a long-lived web server), instantiate once and call await client.aclose() on shutdown.

Exceptions ​

Identical to Index4AI — InvalidApiKeyError, ApiError, InvalidResponseError, JobWaitError, SubmitUncertainError. See Exceptions.

See also ​