# Start a run

Start a [run](/docs/concepts/runs.md) of a task from Studio, the CLI or the API, then read its status and output.

## Before you start

You need a task. See [Write a task](/docs/orchestration/tasks.md).

## Start a run

**Studio**

1. In your project, open **Orchestration** > **Runs**.

2. Click **Create run**.

3. Pick **Task** as the **Type**.

4. Pick `word-count` as the **Target**.

5. Paste the **Payload**:

   ```json
   { "text": "Veryfront runs agents, tasks and workflows" }
   ```

6. Click **Create run**. You should now see the run **Completed**, with `{ "words": 6 }` as its **Output**.

**Code**

1. [Sign in](/docs/start/authentication.md) to the CLI.
2. Set `PROJECT_ID` to your project's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export PROJECT_ID=<id>`.
3. Start the run. The `--idempotency-key` makes a retry return the same run:

```bash
npx veryfront project runs create --idempotency-key word-count-1 --json --body '{
  "project_id": "'$PROJECT_ID'",
  "target": { "type": "task", "id": "word-count" },
  "input": { "text": "Veryfront runs agents, tasks and workflows" }
}'
```

4. Set `RUN_ID` to `data.run_id` in the answer: `export RUN_ID=<run_id>`.
5. Read the run until its `status` is `completed`. You should now see `"words": 6` in its `output`:

```bash
npx veryfront project runs get --run-id $RUN_ID --json
```

### Try it in a sandbox

```playground
step: Add the word-count task | curl -fsS -X PUT https://api.veryfront.com/projects/$VERYFRONT_PROJECT_REFERENCE/files/tasks%2Fword-count.ts -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"content":"export default { name: \"word-count\", description: \"Count the words in a text.\", schedulable: true, async run({ input }) { return { words: String(input.text).trim().split(/\\s+/).length }; } };"}'
step: Set PROJECT_ID | export PROJECT_ID=$VERYFRONT_PROJECT_ID
step: Start the run | npx veryfront project runs create --idempotency-key word-count-1 --json --body '{ "project_id": "'$PROJECT_ID'", "target": { "type": "task", "id": "word-count" }, "input": { "text": "Veryfront runs agents, tasks and workflows" } }' | tee run.json
step: Set RUN_ID | export RUN_ID=$(jq -r .data.run_id run.json)
step: Wait until it is completed | until [ "$(npx veryfront project runs get --run-id $RUN_ID --json | jq -r .data.status)" = completed ]; do sleep 2; done
check: npx veryfront project runs get --run-id $RUN_ID --json
expect: "words": 6
```

**API**

1. Set `PROJECT` to your project's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export PROJECT=<id>`.
2. Get the project, with your [API key](/docs/authentication/api-keys.md). A run takes its `id`, not the slug:

```bash
curl https://api.veryfront.com/projects/$PROJECT \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

3. Set `PROJECT_ID` to the `id` in the response: `export PROJECT_ID=<id>`.
4. Start the run. The `Idempotency-Key` makes a retry return the same run:

```bash
curl -X POST https://api.veryfront.com/runs \
  -H "Authorization: Bearer $VERYFRONT_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: word-count-1" \
  -d '{
    "project_id": "'$PROJECT_ID'",
    "target": { "type": "task", "id": "word-count" },
    "input": { "text": "Veryfront runs agents, tasks and workflows" }
  }'
```

5. Set `RUN_ID` to the `run_id` in the response: `export RUN_ID=<run_id>`.
6. Read the run until `status` is `completed`. You should now see `output` as `{"words":6}`:

```bash
curl https://api.veryfront.com/runs/$RUN_ID \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

### Try it in a sandbox

```playground
step: Add the word-count task | curl -fsS -X PUT https://api.veryfront.com/projects/$VERYFRONT_PROJECT_REFERENCE/files/tasks%2Fword-count.ts -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"content":"export default { name: \"word-count\", description: \"Count the words in a text.\", schedulable: true, async run({ input }) { return { words: String(input.text).trim().split(/\\s+/).length }; } };"}'
step: Set PROJECT | export PROJECT=$VERYFRONT_PROJECT_REFERENCE
step: Get the project | curl https://api.veryfront.com/projects/$PROJECT -H "Authorization: Bearer $VERYFRONT_API_KEY"
step: Set PROJECT_ID | export PROJECT_ID=$(curl -s https://api.veryfront.com/projects/$PROJECT -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -r .id)
step: Start the run | curl -X POST https://api.veryfront.com/runs -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -H "Idempotency-Key: word-count-1" -d '{ "project_id": "'$PROJECT_ID'", "target": { "type": "task", "id": "word-count" }, "input": { "text": "Veryfront runs agents, tasks and workflows" } }'
step: Set RUN_ID | export RUN_ID=$(curl -s -X POST https://api.veryfront.com/runs -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -H "Idempotency-Key: word-count-1" -d '{ "project_id": "'$PROJECT_ID'", "target": { "type": "task", "id": "word-count" }, "input": { "text": "Veryfront runs agents, tasks and workflows" } }' | jq -r .run_id)
step: Wait until it is completed | until [ "$(curl -s https://api.veryfront.com/runs/$RUN_ID -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -r .status)" = completed ]; do sleep 2; done
check: curl https://api.veryfront.com/runs/$RUN_ID -H "Authorization: Bearer $VERYFRONT_API_KEY"
expect: "words":6
```

## With MCP

1. Call `veryfront__get_project` with `"project_reference": "my-project"`. A run takes the project's `id`, not the slug.
2. Call `veryfront__create_run` with the `id` as `project_id`:

```json
{
  "input": {
    "project_id": "<id>",
    "target": { "type": "task", "id": "word-count" },
    "input": { "text": "Veryfront runs agents, tasks and workflows" }
  },
  "idempotency_key": "word-count-1"
}
```

3. Call `veryfront__get_run` with the returned `run_id`. It starts `pending`: call it again until `status` is `completed`, a few seconds. It worked when `output` is `{"words":6}`.

## Next steps

* [Debug a run](/docs/observability/debug.md)
* [Schedule a run](/docs/orchestration/schedules.md)
