> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reactor.inc/llms.txt
> Use this file to discover all available pages before exploring further.

# Commands & Messages

> How two-way communication works between your app and a model

Alongside the video stream, your app and the model exchange data over a real-time channel. You
control the model and receive feedback while it generates.

* **Commands** are instructions your app sends to the model. They control what the model generates
  in real time.
* **Messages** are updates the model sends back to your app. They report state, signal events, or
  deliver data.

For example, a video model might accept a `set_prompt` command to change what it generates, and
respond with periodic `state` messages reporting the current frame number and active prompt.

<Frame>
  <img src="https://mintcdn.com/reactortechnologiesinc/oCeFlbp0H3XO2l0l/diagrams/commands-messages.svg?fit=max&auto=format&n=oCeFlbp0H3XO2l0l&q=85&s=5b0335490ea4b12aa71091b0cc5273d8" alt="Commands flow from your app to the model, messages flow back" width="518" height="228" data-path="diagrams/commands-messages.svg" />
</Frame>

***

## Commands

A command is a named action with a payload.

<CodeGroup>
  ```typescript JavaScript theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
  await reactor.sendCommand("set_prompt", { prompt: "a forest at dawn" });
  ```

  ```tsx React theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
  import { useReactor } from "@reactor-team/js-sdk";

  function PromptButton() {
    const sendCommand = useReactor((s) => s.sendCommand);
    return (
      <button onClick={() => sendCommand("set_prompt", { prompt: "a forest at dawn" })}>
        Set prompt
      </button>
    );
  }
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
  await reactor.send_command("set_prompt", {"prompt": "a forest at dawn"})
  ```
</CodeGroup>

Every model defines its own commands with typed parameters. A prompt-driven model might expose
`set_prompt`; a model with camera controls might expose `move` or `rotate`. Command names, parameter
names, and types are all model-specific.

<Warning>
  **Prefer typed methods over string commands?** Models with a published typed SDK (like
  [Helios](/model-api-reference/helios/overview) or [LingBot](/model-api-reference/lingbot/overview))
  expose every command as a typed method with autocomplete, parameter hints, and compile-time
  validation. No hand-written JSON, no string-typed command names.

  ```typescript Helios typed SDK theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
  import { HeliosModel } from "@reactor-models/helios";

  const helios = new HeliosModel();
  await helios.setPrompt({ prompt: "a forest at dawn" });
  ```

  See [Two layers: base SDK and typed SDKs](/sdk-reference/using-the-sdk#two-layers-base-sdk-and-typed-sdks) for the full picture.
</Warning>

<Note>
  Commands can only be sent when the connection is in the `ready` state.
</Note>

***

## Messages

Reactor models can send structured JSON messages to your app at any time during a session. Each model
defines its own message types.

<CodeGroup>
  ```typescript JavaScript theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
  reactor.on("message", (msg) => {
    console.log(msg);
  });
  ```

  ```tsx React theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
  import { useReactorMessage } from "@reactor-team/js-sdk";

  function MessageLogger() {
    useReactorMessage((msg) => {
      console.log(msg);
    });
    return null;
  }
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
  @reactor.on_message
  def on_message(msg):
      print(msg)
  ```
</CodeGroup>

For the full list of commands and messages per model, see the
[Model API Reference](/model-api-reference/overview).
