AsyncIndex4AI Client API Reference
from index4ai import AsyncIndex4AIAsyncIndex4AI 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
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, ...) -> str | await submit(...) -> str |
collect(job_id, ...) -> IngestResult | await collect(...) -> IngestResult |
ingest(file_path=None, *, remote_url=None, ...) -> IngestResult | await ingest(...) -> IngestResult |
search(query, ...) -> SearchContext | await search(...) -> SearchContext |
search_in_doc(query, doc_filter, ...) -> SearchContext | await search_in_doc(...) -> SearchContext |
list_docs() -> list[DocInfo] | await list_docs() -> list[DocInfo] |
list_attributes() -> AttributeList | await list_attributes() -> AttributeList |
get_doc(doc_id) -> DocInfo | await get_doc(doc_id) -> DocInfo |
delete_doc(doc_id) -> DeleteDocResponse | await delete_doc(doc_id) -> DeleteDocResponse |
close() -> None | await 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:
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
Index4AI— sync client with per-method tables.- index4.ai in the SDK — workflow walkthrough.
- index4.ai for developers — endpoint-level reference, RetrievalContext format, billing.