Skip to content

Feature: Add AsyncMegaNova async client support #18

@yiming-dev

Description

@yiming-dev

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

  1. async_transport.pyAsyncTransport class using httpx.AsyncClient

    • Async request method with retry + exponential backoff
    • SSE streaming support via async for iteration
    • __aenter__ / __aexit__ for context manager support
  2. async_client.pyAsyncMegaNova 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:
  3. 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
  4. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions