---
title: mock_server
---

<div class="python-reference">
<a id="fastvideo.entrypoints.streaming.mock_server-classes"></a>
<a id="fastvideo.entrypoints.streaming.mock_server-functions"></a>
<a id="fastvideo.entrypoints.streaming.mock_server"></a>
<p>Mock streaming server — a frontend dev aid.</p>
<p>Boots the same FastAPI app the real streaming server uses, but backs
it with :class:<code>InProcessGpuPool</code> wrapping a synthetic generator that
emits pre-baked RGB frames. No GPU or model weights required.</p>
<p>Use cases:</p>
<ul>
<li>Frontend development without a real model loaded.</li>
<li>Integration tests that exercise the WS protocol end-to-end.</li>
<li>Reproducing protocol bugs locally.</li>
</ul>
<p>Launch: <code>python -m fastvideo.entrypoints.streaming.mock_server</code>.</p>
<h2 id="fastvideo.entrypoints.streaming.mock_server.ContinuationState"><code>fastvideo.entrypoints.streaming.mock_server.ContinuationState</code></h2>
<pre class="doc-signature"><code>ContinuationState(kind: str, payload: dict&#91;str, Any&#93;)</code></pre>


<h2 id="fastvideo.entrypoints.streaming.mock_server.GenerationRequest"><code>fastvideo.entrypoints.streaming.mock_server.GenerationRequest</code></h2>
<pre class="doc-signature"><code>GenerationRequest(prompt: str | list&#91;str&#93; | None = None, negative_prompt: str | None = None, inputs: InputConfig = InputConfig(), sampling: SamplingConfig = SamplingConfig(), runtime: RequestRuntimeConfig = RequestRuntimeConfig(), output: OutputConfig = OutputConfig(), stage_overrides: dict&#91;str, Any&#93; = dict(), state: ContinuationState | None = None, plan: GenerationPlan | None = None, extensions: dict&#91;str, Any&#93; = dict())</code></pre>


<h2 id="fastvideo.entrypoints.streaming.mock_server.GeneratorConfig"><code>fastvideo.entrypoints.streaming.mock_server.GeneratorConfig</code></h2>
<pre class="doc-signature"><code>GeneratorConfig(model_path: str, revision: str | None = None, trust_remote_code: bool = False, engine: EngineConfig = EngineConfig(), pipeline: PipelineSelection = PipelineSelection())</code></pre>


<h2 id="fastvideo.entrypoints.streaming.mock_server.SamplingConfig"><code>fastvideo.entrypoints.streaming.mock_server.SamplingConfig</code></h2>
<pre class="doc-signature"><code>SamplingConfig(num_videos_per_prompt: int = 1, seed: int = 1024, max_sequence_length: int | None = None, num_frames: int = 125, height: int = 720, width: int = 1280, height_sr: int = 1072, width_sr: int = 1920, fps: int = 24, audio_start_in_s: float | None = None, audio_end_in_s: float | None = None, num_inference_steps: int = 50, num_inference_steps_sr: int = 50, guidance_scale: float = 1.0, batch_cfg: bool = False, guidance_scale_2: float | None = None, guidance_rescale: float = 0.0, true_cfg_scale: float | None = None, use_embedded_guidance: bool | None = None, boundary_ratio: float | None = None, sigmas: list&#91;float&#93; | None = None, pyramid_num_inference_steps_list: list&#91;int&#93; | None = None, history_sizes: list&#91;int&#93; | None = None, num_latent_frames_per_chunk: int = 9, keep_first_frame: bool = True, is_skip_first_chunk: bool = False, use_zero_init: bool = True, zero_steps: int = 1, is_amplify_first_chunk: bool = False)</code></pre>


<h2 id="fastvideo.entrypoints.streaming.mock_server.ServeConfig"><code>fastvideo.entrypoints.streaming.mock_server.ServeConfig</code></h2>
<pre class="doc-signature"><code>ServeConfig(generator: GeneratorConfig, server: ServerConfig = ServerConfig(), default_request: GenerationRequest = GenerationRequest(), streaming: StreamingConfig | None = None)</code></pre>
<p>Typed serve config loaded from <code>fastvideo serve --config</code>.</p>
<p><code>default_request</code> is a full :class:<code>GenerationRequest</code> — the same type
clients POST to <code>/v1/videos</code>. At request time the server merges it into
the incoming body as the operator-pinned baseline.</p>
<p>Important nuance: only fields the operator <strong>explicitly wrote</strong> in the
serve YAML/JSON count as defaults. Although the in-memory object is
fully populated (schema defaults fill every unset field), the merge
walks <code>_fastvideo_explicit_paths</code> — populated during parse — so
unset fields are <em>not</em> forced onto requests. Per-request precedence:</p>
<pre><code>body (client-explicit) &gt; default_request (operator-explicit)
                       &gt; hardcoded fallback (e.g. ``fps=24``)
</code></pre>
<p>See :func:<code>fastvideo.api.compat.explicit_request_updates</code> for the
projection and <code>entrypoints/openai/video_api.py::_build_generation_kwargs</code>
for the merge.</p>

<h2 id="fastvideo.entrypoints.streaming.mock_server.StreamingConfig"><code>fastvideo.entrypoints.streaming.mock_server.StreamingConfig</code></h2>
<pre class="doc-signature"><code>StreamingConfig(session_timeout_seconds: int = 300, generation_segment_cap: int = 6, stream_mode: Literal&#91;&#x27;av_fmp4&#x27;, &#x27;legacy_jpeg&#x27;&#93; = &#x27;av_fmp4&#x27;, warmup: WarmupConfig = WarmupConfig(), pool: GpuPoolConfig = GpuPoolConfig(), prompt: PromptEnhancerConfig = PromptEnhancerConfig(), safety: PromptSafetyConfig = PromptSafetyConfig())</code></pre>


<h2 id="fastvideo.entrypoints.streaming.mock_server.build_app"><code>fastvideo.entrypoints.streaming.mock_server.build_app</code></h2>
<pre class="doc-signature"><code>build_app(serve_config: ServeConfig, generator: _GeneratorProto | None = None, *, pool: GpuPool | None = None, session_store: SessionStore | None = None) -&gt; FastAPI</code></pre>
<p>Build the FastAPI app used by :func:<code>run_server</code>.</p>
<p>Exposed so tests can drive the WebSocket endpoint in-process via
<code>starlette.testclient.TestClient(app).websocket_connect(...)</code>.</p>
<p>Exactly one of <code>generator</code> (backed by :class:<code>InProcessGpuPool</code>)
or <code>pool</code> (for the subprocess-backed production shape) must be
given.</p>
<h2 id="fastvideo.entrypoints.streaming.mock_server.MockGenerator"><code>fastvideo.entrypoints.streaming.mock_server.MockGenerator</code></h2>
<pre class="doc-signature"><code>MockGenerator(sleep_ms: float = 0.0)</code></pre>
<p>Generator stand-in that returns synthetic gradient frames.</p>
<p>Each call produces one segment worth of frames whose pixels vary by
a constant derived from the request seed and segment index. Latency
is configurable via <code>sleep_ms</code> so the caller can exercise slow-
generate scenarios without spinning a GPU.</p>

<details><summary>Source</summary><pre><code>@dataclass
class MockGenerator:
    &quot;&quot;&quot;Generator stand-in that returns synthetic gradient frames.

    Each call produces one segment worth of frames whose pixels vary by
    a constant derived from the request seed and segment index. Latency
    is configurable via ``sleep_ms`` so the caller can exercise slow-
    generate scenarios without spinning a GPU.
    &quot;&quot;&quot;

    sleep_ms: float = 0.0

    def generate(self, request: GenerationRequest) -&gt; dict&#91;str, Any&#93;:
        if self.sleep_ms:
            time.sleep(self.sleep_ms / 1000.0)
        width = max(16, request.sampling.width)
        height = max(16, request.sampling.height)
        num_frames = max(1, request.sampling.num_frames)
        frames = &#91;_gradient_frame(height, width, idx, seed=request.sampling.seed) for idx in range(num_frames)&#93;
        state = ContinuationState(
            kind=&quot;ltx2.v1&quot;,
            payload=&#123;
                &quot;schema_version&quot;: 1,
                &quot;segment_index&quot;: 0,
                &quot;source_prompt&quot;: request.prompt,
            &#125;,
        )
        return &#123;
            &quot;frames&quot;: frames,
            &quot;audio_sample_rate&quot;: 24000,
            &quot;state&quot;: state,
        &#125;</code></pre></details>
<h3 id="fastvideo.entrypoints.streaming.mock_server.MockGenerator.generate"><code>fastvideo.entrypoints.streaming.mock_server.MockGenerator.generate</code></h3>
<pre class="doc-signature"><code>generate(request: GenerationRequest) -&gt; dict&#91;str, Any&#93;</code></pre>

<details><summary>Source</summary><pre><code>def generate(self, request: GenerationRequest) -&gt; dict&#91;str, Any&#93;:
    if self.sleep_ms:
        time.sleep(self.sleep_ms / 1000.0)
    width = max(16, request.sampling.width)
    height = max(16, request.sampling.height)
    num_frames = max(1, request.sampling.num_frames)
    frames = &#91;_gradient_frame(height, width, idx, seed=request.sampling.seed) for idx in range(num_frames)&#93;
    state = ContinuationState(
        kind=&quot;ltx2.v1&quot;,
        payload=&#123;
            &quot;schema_version&quot;: 1,
            &quot;segment_index&quot;: 0,
            &quot;source_prompt&quot;: request.prompt,
        &#125;,
    )
    return &#123;
        &quot;frames&quot;: frames,
        &quot;audio_sample_rate&quot;: 24000,
        &quot;state&quot;: state,
    &#125;</code></pre></details>
<h2 id="fastvideo.entrypoints.streaming.mock_server.build_mock_app"><code>fastvideo.entrypoints.streaming.mock_server.build_mock_app</code></h2>
<pre class="doc-signature"><code>build_mock_app(*, sleep_ms: float = 0.0)</code></pre>
<p>Build a FastAPI app backed by :class:<code>MockGenerator</code>.</p>
<details><summary>Source</summary><pre><code>def build_mock_app(*, sleep_ms: float = 0.0):
    &quot;&quot;&quot;Build a FastAPI app backed by :class:`MockGenerator`.&quot;&quot;&quot;
    serve_config = ServeConfig(
        generator=GeneratorConfig(model_path=&quot;/models/mock&quot;),
        streaming=StreamingConfig(
            session_timeout_seconds=120,
            generation_segment_cap=6,
        ),
    )
    serve_config.default_request.sampling = SamplingConfig(
        num_frames=24,
        height=256,
        width=256,
        fps=24,
        num_inference_steps=1,
    )
    return build_app(serve_config, MockGenerator(sleep_ms=sleep_ms))</code></pre></details>
<h2 id="fastvideo.entrypoints.streaming.mock_server.main"><code>fastvideo.entrypoints.streaming.mock_server.main</code></h2>
<pre class="doc-signature"><code>main() -&gt; None</code></pre>

<details><summary>Source</summary><pre><code>def main() -&gt; None:  # pragma: no cover - CLI entry
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument(&quot;--host&quot;, default=&quot;127.0.0.1&quot;)
    parser.add_argument(&quot;--port&quot;, type=int, default=8000)
    parser.add_argument(
        &quot;--sleep-ms&quot;,
        type=float,
        default=0.0,
        help=&quot;Per-segment artificial latency for testing slow paths&quot;,
    )
    args = parser.parse_args()

    import uvicorn

    app = build_mock_app(sleep_ms=args.sleep_ms)
    uvicorn.run(app, host=args.host, port=args.port)</code></pre></details>
</div>
