> For the complete documentation index, see [llms.txt](https://docs.baas.sh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.baas.sh/baas-console/automations/reference/context.md).

# Context object

The run's own variables, including the previous step's result, the run's identifiers, and the Function time budget.

`context` is what the run itself provides, and its shape is the same whatever the trigger type. It carries the previous step's result, the user of a batch repetition, the run's identifiers, and the time budget your Function code can check.

## context.previous

`context.previous` holds the result of the previous step, the chain introduced in [Chain actions together](/baas-console/automations/actions.md#chain-actions-together). What it contains depends on the type that ran before it: see [API](/baas-console/automations/actions/api.md#what-the-next-step-receives), [Email](/baas-console/automations/actions/email.md#what-the-next-step-receives), [Function](/baas-console/automations/actions/function.md#what-the-next-step-receives), [Notification](/baas-console/automations/actions/notification.md#what-the-next-step-receives), and [Transaction](/baas-console/automations/actions/transaction.md#what-the-next-step-receives).

Some steps have no result to read:

| The step                                                   | What `context.previous` holds                                               |
| ---------------------------------------------------------- | --------------------------------------------------------------------------- |
| First in the pipeline                                      | Nothing: the variable is absent, and code reads `undefined`                 |
| After a step that returned nothing                         | `null`                                                                      |
| After a [batched step](/baas-console/automations/batch.md) | `null`, since a batch produces one result per user rather than a single one |

To a template, absent and `null` are the same thing: no value. For the first action, the Console refuses the path when you save, since nothing precedes it. After a batch or an empty result, `{{context.previous}}` fails the run and `{{context.previous?}}` renders empty. See [how templates render](/baas-console/automations/reference.md#how-templates-render).

Chained results are capped at 64 KiB.

{% hint style="info" %}
**Oversized results become null.** A result over 64 KiB is not truncated and does not fail the action: it is stored as `null` and the run logs a warning.
{% endhint %}

A function's return value has its own configurable limit, [`maxResultBytes`](/baas-console/action-plugins.md#function-defaults) (16 KiB by default): going over that one fails the action with `function_result_too_large`.

## context.batch

An action running in [batch mode](/baas-console/automations/batch.md) repeats once per user, and `context.batch` tells it which user it is serving:

| Variable              | What it holds                                      |
| --------------------- | -------------------------------------------------- |
| `context.batch.user`  | The user of the current repetition                 |
| `context.batch.index` | That user's position in the batch, starting at `0` |

Outside a batch, `context.batch` does not exist. The Console refuses a template that reads it when you save. [What each repetition reads](/baas-console/automations/batch.md#what-each-repetition-reads) lists the fields a user carries.

## The run's identifiers

| Variable           | What it holds                       |
| ------------------ | ----------------------------------- |
| `context.eventId`  | The id of the current run           |
| `context.actionId` | The id of the action being executed |
| `context.sourceId` | The id of the trigger that fired    |

`context.eventId` matches the **Run** column of the [Runs tab](/baas-console/automations/runs-and-logs.md). In the [weekly-rewards example](/baas-console/automations/actions/api.md) from the API action page, the request body can also carry `"runId": {{context.eventId}}`, so your backend can tie each call to its run. For monitor runs, `context.sourceId` carries the same id as [`trigger.monitor.id`](/baas-console/automations/reference/trigger.md#monitor-the-event-envelope).

## In Function code

In code, `context` is the second argument, and it is read-only. One member exists only there: `context.getRemainingTimeInMillis()`, which returns the milliseconds left in the function's time budget. A function that makes several [plugins](/baas-console/automations/reference/plugins.md) calls can check what remains and skip the optional ones when it runs low.

## Next

* [Plugins object](/baas-console/automations/reference/plugins.md): what Function code can call.
* [Actions](/baas-console/automations/actions.md): how the pipeline chains its steps.
* [Runs and logs](/baas-console/automations/runs-and-logs.md): where the run id and its warnings show up.
