Skip to content

vllm_mlx.audio_limits

Resource limits for optional audio endpoints.

View the complete module source at #L1-L77.

API details

Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.

vllm_mlx.audio_limits

Resource limits for optional audio endpoints.

vllm_mlx.audio_limits.DEFAULT_MAX_AUDIO_UPLOAD_MB module-attribute

DEFAULT_MAX_AUDIO_UPLOAD_MB = 25

vllm_mlx.audio_limits.DEFAULT_MAX_AUDIO_UPLOAD_BYTES module-attribute

DEFAULT_MAX_AUDIO_UPLOAD_BYTES = DEFAULT_MAX_AUDIO_UPLOAD_MB * 1024 * 1024

vllm_mlx.audio_limits.DEFAULT_MAX_TTS_INPUT_CHARS module-attribute

DEFAULT_MAX_TTS_INPUT_CHARS = 4096

vllm_mlx.audio_limits.UPLOAD_CHUNK_SIZE module-attribute

UPLOAD_CHUNK_SIZE = 1024 * 1024

vllm_mlx.audio_limits.AsyncReadableUpload

Bases: Protocol

Structural type for an asynchronously readable uploaded file.

vllm_mlx.audio_limits.AsyncReadableUpload.filename instance-attribute

filename: str | None

vllm_mlx.audio_limits.AsyncReadableUpload.read async

read(size: int = -1) -> bytes

Read at most size bytes, or all remaining bytes when negative.

Source code in vllm_mlx/audio_limits.py
async def read(self, size: int = -1) -> bytes:
    """Read at most ``size`` bytes, or all remaining bytes when negative."""

    ...

vllm_mlx.audio_limits.save_upload_with_limit async

save_upload_with_limit(file: AsyncReadableUpload, *, max_bytes: int, default_suffix: str = '.wav', chunk_size: int = UPLOAD_CHUNK_SIZE) -> str

Stream an uploaded file to disk while enforcing a hard byte limit.

This prevents large audio uploads from being buffered entirely in memory.

Source code in vllm_mlx/audio_limits.py
async def save_upload_with_limit(
    file: AsyncReadableUpload,
    *,
    max_bytes: int,
    default_suffix: str = ".wav",
    chunk_size: int = UPLOAD_CHUNK_SIZE,
) -> str:
    """
    Stream an uploaded file to disk while enforcing a hard byte limit.

    This prevents large audio uploads from being buffered entirely in memory.
    """
    suffix = Path(file.filename or "").suffix or default_suffix
    total_bytes = 0

    with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as tmp:
        tmp_path = tmp.name
        try:
            while True:
                chunk = await file.read(chunk_size)
                if not chunk:
                    break
                total_bytes += len(chunk)
                if total_bytes > max_bytes:
                    raise HTTPException(
                        status_code=413,
                        detail=(
                            f"Audio upload too large: {total_bytes} bytes exceeds "
                            f"the configured limit of {max_bytes} bytes."
                        ),
                    )
                tmp.write(chunk)
        except Exception:
            if os.path.exists(tmp_path):
                os.unlink(tmp_path)
            raise

    return tmp_path

vllm_mlx.audio_limits.validate_tts_input_length

validate_tts_input_length(text: str, *, max_chars: int) -> None

Reject oversized TTS requests before synthesis starts.

Source code in vllm_mlx/audio_limits.py
def validate_tts_input_length(text: str, *, max_chars: int) -> None:
    """Reject oversized TTS requests before synthesis starts."""
    if len(text) > max_chars:
        raise HTTPException(
            status_code=413,
            detail=(
                f"TTS input too long: {len(text)} characters exceeds the configured "
                f"limit of {max_chars} characters."
            ),
        )

Complete contract reference

Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.

vllm_mlx.audio_limits.AsyncReadableUpload · class
vllm_mlx.audio_limits.AsyncReadableUpload()

Structural type for an asynchronously readable uploaded file.

Parameters

This callable has no explicit inputs.

Returns

  • Constructs: vllm_mlx.audio_limits.AsyncReadableUpload

Exceptions and behavior

Class AsyncReadableUpload derives from Protocol and declares 1 direct member(s). No direct raise statement appears in this definition.

View source #L17-L25.

vllm_mlx.audio_limits.AsyncReadableUpload.read · method
async vllm_mlx.audio_limits.AsyncReadableUpload.read(size: int = -1) -> bytes

Read at most size bytes, or all remaining bytes when negative.

Parameters

Name Type Required Default Description
size int no -1 Optional positional or keyword input; defaults to -1.

Returns

  • Type: bytes

Exceptions and behavior

Method AsyncReadableUpload.read contains no state mutation, call, raise, return, await, or yield. No direct raise statement appears in this definition.

View source #L22-L25.

vllm_mlx.audio_limits.save_upload_with_limit · function
async vllm_mlx.audio_limits.save_upload_with_limit(file: AsyncReadableUpload, *, max_bytes: int, default_suffix: str = '.wav', chunk_size: int = UPLOAD_CHUNK_SIZE) -> str

Stream an uploaded file to disk while enforcing a hard byte limit.

Parameters

Name Type Required Default Description
file AsyncReadableUpload yes none Required positional or keyword input.
max_bytes int yes none Required keyword-only input.
default_suffix str no '.wav' Optional keyword-only input; defaults to '.wav'.
chunk_size int no UPLOAD_CHUNK_SIZE Optional keyword-only input; defaults to UPLOAD_CHUNK_SIZE.

Returns

  • Type: str
  • Direct return expressions: tmp_path

Exceptions and behavior

Function save_upload_with_limit calls Path, tempfile.NamedTemporaryFile, file.read, len; awaits asynchronous work; can raise HTTPException; returns tmp_path. Directly raised exceptions: HTTPException.

View source #L28-L65.

vllm_mlx.audio_limits.validate_tts_input_length · function
vllm_mlx.audio_limits.validate_tts_input_length(text: str, *, max_chars: int) -> None

Reject oversized TTS requests before synthesis starts.

Parameters

Name Type Required Default Description
text str yes none Required positional or keyword input.
max_chars int yes none Required keyword-only input.

Returns

  • Type: None

Exceptions and behavior

Function validate_tts_input_length calls len, HTTPException; can raise HTTPException. Directly raised exceptions: HTTPException.

View source #L68-L77.

Complete symbol map

This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.

Symbol Kind Signature and inputs What it does Source
AsyncReadableUpload class AsyncReadableUpload() Structural type for an asynchronously readable uploaded file. #L17-L25
AsyncReadableUpload.read method async AsyncReadableUpload.read(size: int = -1) -> bytes Read at most size bytes, or all remaining bytes when negative. #L22-L25
save_upload_with_limit function async save_upload_with_limit(file: AsyncReadableUpload, *, max_bytes: int, default_suffix: str = '.wav', chunk_size: int = UPLOAD_CHUNK_SIZE) -> str Stream an uploaded file to disk while enforcing a hard byte limit. #L28-L65
validate_tts_input_length function validate_tts_input_length(text: str, *, max_chars: int) -> None Reject oversized TTS requests before synthesis starts. #L68-L77