# `vllm_mlx.audio_limits`

Resource limits for optional audio endpoints.

[View the complete module source at #L1-L77](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/audio_limits.py#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
    options:
      members:
        - DEFAULT_MAX_AUDIO_UPLOAD_MB
        - DEFAULT_MAX_AUDIO_UPLOAD_BYTES
        - DEFAULT_MAX_TTS_INPUT_CHARS
        - UPLOAD_CHUNK_SIZE
        - AsyncReadableUpload
        - save_upload_with_limit
        - validate_tts_input_length
      filters: []
      show_if_no_docstring: true

## 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.

<details class="api-contract" id="contract-vllm_mlx.audio_limits.AsyncReadableUpload" markdown="1">
<summary><code>vllm_mlx.audio_limits.AsyncReadableUpload</code> · class</summary>

```python
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](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/audio_limits.py#L17-L25).

</details>

<details class="api-contract" id="contract-vllm_mlx.audio_limits.AsyncReadableUpload.read" markdown="1">
<summary><code>vllm_mlx.audio_limits.AsyncReadableUpload.read</code> · method</summary>

```python
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](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/audio_limits.py#L22-L25).

</details>

<details class="api-contract" id="contract-vllm_mlx.audio_limits.save_upload_with_limit" markdown="1">
<summary><code>vllm_mlx.audio_limits.save_upload_with_limit</code> · function</summary>

```python
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](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/audio_limits.py#L28-L65).

</details>

<details class="api-contract" id="contract-vllm_mlx.audio_limits.validate_tts_input_length" markdown="1">
<summary><code>vllm_mlx.audio_limits.validate_tts_input_length</code> · function</summary>

```python
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](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/audio_limits.py#L68-L77).

</details>

## 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`](#contract-vllm_mlx.audio_limits.AsyncReadableUpload) | class | `AsyncReadableUpload()` | Structural type for an asynchronously readable uploaded file. | [#L17-L25](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/audio_limits.py#L17-L25) |
| [`AsyncReadableUpload.read`](#contract-vllm_mlx.audio_limits.AsyncReadableUpload.read) | method | `async AsyncReadableUpload.read(size: int = -1) -> bytes` | Read at most ``size`` bytes, or all remaining bytes when negative. | [#L22-L25](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/audio_limits.py#L22-L25) |
| [`save_upload_with_limit`](#contract-vllm_mlx.audio_limits.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](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/audio_limits.py#L28-L65) |
| [`validate_tts_input_length`](#contract-vllm_mlx.audio_limits.validate_tts_input_length) | function | `validate_tts_input_length(text: str, *, max_chars: int) -> None` | Reject oversized TTS requests before synthesis starts. | [#L68-L77](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/audio_limits.py#L68-L77) |
