# Mastra.getWorkflow()

The `.getWorkflow()` method is used to retrieve a workflow by its registration key. This method provides full TypeScript type inference for workflow input and output schemas.

## Usage example

```typescript
// Retrieve workflow by its registration key (recommended for type inference)
const workflow = mastra.getWorkflow('testWorkflow')
const run = await workflow.createRun()

// TypeScript will properly infer the input schema type
await run.startAsync({
  inputData: {
    /* properly typed */
  },
})
```

## Type inference

For best TypeScript support, use `getWorkflow()` with the workflow's **registration key** (the key used when adding the workflow to Mastra). This provides full type inference for:

- Input data schemas
- Output data schemas
- Step results

If you need to retrieve a workflow by its `id` property instead of its registration key, you can use `getWorkflowById()`, but note that type inference won't be as precise.

## Parameters

**id** (`TWorkflowId extends keyof TWorkflows`): The ID of the workflow to retrieve. Must be a valid workflow ID that exists in the Mastra configuration.

**options** (`{ serialized?: boolean }`): Optional configuration object. When \`serialized\` is true, returns only the workflow name instead of the full workflow instance.

## Returns

**workflow** (`TWorkflows[TWorkflowId]`): The workflow instance with the specified ID. Throws an error if the workflow is not found.

## Related

- [Workflows overview](https://mastra.ai/docs/workflows/overview)