Description
The SDK v0.4.0 is entirely synchronous. There is no AsyncMegaNova client, no AsyncTransport, and no async implementations anywhere in the package. This makes it unsuitable for async environments like FastAPI services or concurrent batch processing.
Current State
- Only
MegaNova (sync client) exists, using requests.Session()
- No
async_client.py, async_transport.py, or async_resources.py files
__init__.py does not export AsyncMegaNova
- All resource methods are blocking/synchronous
Proposed Implementation
New Files
-
async_transport.py — AsyncTransport class using httpx.AsyncClient
- Async request method with retry + exponential backoff
- SSE streaming support via
async for iteration
__aenter__ / __aexit__ for context manager support
-
async_client.py — AsyncMegaNova class
- Same constructor signature as
MegaNova (api_key, base_url, timeout, max_retries, region)
- Same resource attributes (chat, models, images, videos, audio, embeddings, serverless, usage, billing, rerank)
- Async context manager support:
async with AsyncMegaNova(...) as client:
-
resources/async_resources.py — Async versions of all resource classes
- Mirror every sync resource method with
async def equivalents
- Streaming methods return
AsyncIterator instead of Iterator
-
Update __init__.py — Export AsyncMegaNova
Usage Example
from meganova import AsyncMegaNova
async with AsyncMegaNova(api_key="sk-xxx") as client:
# Non-blocking chat
response = await client.chat.completions.create(
model="meganova-ai/manta-mini-1.0",
messages=[{"role": "user", "content": "Hello"}],
)
# Async streaming
stream = await client.chat.completions.create(
model="meganova-ai/manta-mini-1.0",
messages=[{"role": "user", "content": "Hello"}],
stream=True,
)
async for chunk in stream:
print(chunk.choices[0].delta.get("content", ""), end="")
Dependencies
Add httpx>=0.27 as an optional dependency:
[project.optional-dependencies]
async = ["httpx>=0.27"]
Environment
- SDK version: 0.4.0
- Discovered during integration testing (3 async tests skipped due to missing module)
Description
The SDK v0.4.0 is entirely synchronous. There is no
AsyncMegaNovaclient, noAsyncTransport, and no async implementations anywhere in the package. This makes it unsuitable for async environments like FastAPI services or concurrent batch processing.Current State
MegaNova(sync client) exists, usingrequests.Session()async_client.py,async_transport.py, orasync_resources.pyfiles__init__.pydoes not exportAsyncMegaNovaProposed Implementation
New Files
async_transport.py—AsyncTransportclass usinghttpx.AsyncClientasync foriteration__aenter__/__aexit__for context manager supportasync_client.py—AsyncMegaNovaclassMegaNova(api_key, base_url, timeout, max_retries, region)async with AsyncMegaNova(...) as client:resources/async_resources.py— Async versions of all resource classesasync defequivalentsAsyncIteratorinstead ofIteratorUpdate
__init__.py— ExportAsyncMegaNovaUsage Example
Dependencies
Add
httpx>=0.27as an optional dependency:Environment