openai/openai-python · error · RuntimeError

Async runtime {async_library} is not supported yet. Only asy

Error message

Async runtime {async_library} is not supported yet. Only asyncio or trio is supported

What it means

`upload_and_poll` uploads files concurrently using either asyncio or trio, selected via `get_async_library()`. If the running async backend is neither (e.g. curio or a custom event loop), the SDK raises this RuntimeError because no compatible concurrency primitives are available for the fan-out uploads.

Source

Thrown at src/openai/resources/vector_stores/file_batches.py:785

            # We only import if the library is being used.
            # We support Python 3.7 so are using an older version of trio that does not have type information
            import trio  # type: ignore # pyright: ignore[reportMissingTypeStubs]

            async def trio_upload_file(limiter: trio.CapacityLimiter, file: FileTypes) -> None:
                async with limiter:
                    file_obj = await self._client.files.create(
                        file=file,
                        purpose="assistants",
                    )
                    uploaded_files.append(file_obj)

            limiter = trio.CapacityLimiter(max_concurrency)

            async with trio.open_nursery() as nursery:
                for file in files:
                    nursery.start_soon(trio_upload_file, limiter, file)  # pyright: ignore [reportUnknownMemberType]
        else:
            raise RuntimeError(
                f"Async runtime {async_library} is not supported yet. Only asyncio or trio is supported",
            )

        batch = await self.create_and_poll(
            vector_store_id=vector_store_id,
            file_ids=[*file_ids, *(f.id for f in uploaded_files)],
            poll_interval_ms=poll_interval_ms,
            chunking_strategy=chunking_strategy,
        )
        return batch


class FileBatchesWithRawResponse:
    def __init__(self, file_batches: FileBatches) -> None:
        self._file_batches = file_batches

        self.create = _legacy_response.to_raw_response_wrapper(
            file_batches.create,

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Run the call inside standard asyncio (`asyncio.run(main())`) or trio (`trio.run(main())`)
  2. If you use a custom loop, port the upload logic to plain sequential `await client.vector_stores.files.upload_and_poll` calls and then create the batch yourself
  3. Upgrade the openai package in case newer versions support your runtime

Example fix

# before
await client.vector_stores.file_batches.upload_and_poll(vs_id, files)  # inside custom loop

# after
import asyncio
asyncio.run(client.vector_stores.file_batches.upload_and_poll(vs_id, files))
Defensive patterns

Strategy: fallback

Validate before calling

import sniffio

lib = sniffio.current_async_library()
if lib not in {"asyncio", "trio"}:
    raise RuntimeError(f"Run under asyncio or trio, not {lib!r}")
batch = await client.vector_stores.file_batches.upload_and_poll(vs_id, files)

Try / catch

try:
    batch = await client.vector_stores.file_batches.upload_and_poll(vs_id, files)
except RuntimeError as e:
    if "not supported yet" in str(e):
        # fallback: sequential uploads then create the batch manually
        ids = [(await client.vector_stores.files.upload_and_poll(vs_id, f)).id for f in files]
        batch = await client.vector_stores.file_batches.create_and_poll(vector_store_id=vs_id, file_ids=ids)
    else:
        raise

Prevention

When it happens

Trigger: Running `await client.vector_stores.file_batches.upload_and_poll(...)` inside a non-asyncio/non-trio async framework, or a runtime where `sniffio.get_async_library()` returns an unexpected library name.

Common situations: Embedding the SDK in a custom event loop, using curio, or test frameworks that replace the async backend; also version drift where an older sniffio/anyio combination reports a different library name.

Related errors


AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28). Data as JSON: /api/errors/6c759f0e9a58e409. Report an issue: GitHub.