# context.invoke

`context.invoke()` triggers another workflow run and pauses until the invoked workflow finishes.

The calling workflow resumes once the invoked workflow either **succeeds**, **fails**, or is **canceled**.

<Note>
    Workflows can only invoke other workflows that were served together in the same `serveMany` route.
    For details, see [Invoke other workflows](/workflow/features/invoke).
</Note>

## Arguments

<ParamField body="workflow" type="function" required>
    The workflow definition to invoke.
    Must be a workflow exposed under the same `serveMany`.
</ParamField>

<ParamField body="body" type="any">
    The payload to send to the invoked workflow.
    This value will be set as `context.requestPayload` in the invoked workflow.
</ParamField>

<ParamField body="headers" type="object" optional>
    Optional HTTP headers to forward to the invoked workflow.
    This value will be set as `context.headers` in the invoked workflow.
</ParamField>

<ParamField body="workflowRunId" type="string" optional>
    Override the workflow run ID for the invoked workflow.
    Defaults to a new ID if not specified.
</ParamField>

<ParamField body="retries" type="number" optional>
    Number of retry attempts configuration of the invoked workflow.
    Defaults to `3`. Retries use exponential backoff.
</ParamField>

<ParamField body="retryDelay" type="number|string" optional>
    Delay between retries of the invoked workflow.
</ParamField>

<ParamField body="flowControl" type="object" optional>
    Flow control configuration of the invoked workflow.

    See [Flow Control](/workflow/features/flow-control) for details.

    <Expandable title="properties">
        <ParamField body="key" type="string">
          A logical grouping key that identifies which requests share the same flow control limits.
        </ParamField>

        <ParamField body="rate" type="number">
            The maximum number of allowed requests per second.
        </ParamField>

        <ParamField body="parallelism" type="number">
            The maximum number of concurrent requests allowed.
        </ParamField>

        <ParamField body="period" type="string|number">
            The time window used to enforce the defined rate limit. Default is `1s`.
        </ParamField>
    </Expandable>
</ParamField>

## Response

<ResponseField name="body" type="any">
    The response body returned by the invoked workflow.
</ResponseField>

<ResponseField name="isFailed" type="boolean">
    `true` if the invoked workflow completed with failure.
</ResponseField>

<ResponseField name="isCanceled" type="boolean">
    `true` if the invoked workflow was canceled before completion.
</ResponseField>

## Usage

```ts
const { body, isFailed, isCanceled } = await context.invoke(
  "invoke another workflow",
  {
    workflow: anotherWorkflow,
    body: "test",
    header: {...}, // headers to pass to anotherWorkflow (optional)
    retries,       // number of retries (optional, default: 3)
    retryDelay,    // delay between retries (optional, uses exponential backoff by default)
    flowControl,   // flow control settings (optional)
    workflowRunId  // workflowRunId to set (optional)
  }
);
```
