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

# call node

> Run one function or effect once, with named inputs, and keep its validated result.

A `call` runs one function or effect and waits for its result. It is the step that runs your
code, reads or writes an outside system, or calls an Effective API operation. To run another
published procedure as a step, use [`invoke`](https://docs.canary.effectiveai.app/procedures/reference/nodes/invoke) instead. To
build a value from data you already have, without running code, use
[`value`](https://docs.canary.effectiveai.app/procedures/reference/nodes/value).

## Syntax

```yaml call id=read-policy theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
function: '@local.read-policy'
input:
  policyNumber: $inputs.policy_number
output: policy
```

The fence takes no attributes after `id`.

## Fields

| Field | Type | Required | Default | What it does |
| - | - | - | - | - |
| `function` | string | Yes | None | The callable to run. `'@local.<id>'` names a [`ts function` or `ts effect`](https://docs.canary.effectiveai.app/procedures/reference/nodes/function-and-effect) declared in the same document. Other namespaces, such as `'@effective.api.<operation>'`, name a catalog callable. Quote the value so the `@` reads as an address. |
| `input` | object | Yes | None | Named operands. Each value is a literal or a `$` reference. The whole object must match the callable's input schema: every required operand present and no extra ones. Write `input: {}` when the callable takes nothing. |
| `output` | name | No | None | A new named value that holds the result, for later nodes to read as `$<name>`. Without it, the result is still validated and recorded, then discarded. |

Names in `output` use lowercase letters, digits and underscores, and start with a letter. Each
name can be produced only once in a procedure, and must not reuse an input or output name.

Operands are named, never positional. Secrets and credentials are never operands: an effect reads
them through its declared [secret slots](https://docs.canary.effectiveai.app/procedures/reference/nodes/secret.md).

## Example

A pure function cleans up the policy number, then an effect reads the policy from the policy
administration system:

````markdown policy-status.procedure.md theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
---
kind: procedure@v0
id: policy-status

inputs:
  policy_number: { type: string }
outputs:
  status: { schema: policy-status-result }
---

# Policy status

Normalize a policy number, read the policy from the policy administration
system, and return its status.

## Normalize

```yaml call id=normalize-input
function: '@local.normalize-policy-number'
input:
  raw: $inputs.policy_number
output: policy_ref
```

## Read policy

```yaml call id=fetch-policy
function: '@local.read-policy'
input:
  policyNumber: $policy_ref.policyNumber
output: policy
```

```yaml complete id=done
output: status
value:
  policyNumber: $policy_ref.policyNumber
  status: $policy.status
```

## Resources

```yaml schema id=raw-policy-number
type: object
additionalProperties: false
required: [raw]
properties:
  raw: { type: string }
```

```yaml schema id=policy-ref
type: object
additionalProperties: false
required: [policyNumber]
properties:
  policyNumber: { type: string }
```

```yaml schema id=policy
type: object
additionalProperties: false
required: [status]
properties:
  status: { enum: [active, cancelled, lapsed] }
```

```yaml schema id=policy-status-result
type: object
additionalProperties: false
required: [policyNumber, status]
properties:
  policyNumber: { type: string }
  status: { enum: [active, cancelled, lapsed] }
```

```yaml secret id=pas-token
format: text
description: Token for the policy administration system API
```

```ts function id=normalize-policy-number input=raw-policy-number result=policy-ref
({ raw }) => ({ policyNumber: raw.trim().toUpperCase() });
```

```ts effect id=read-policy input=policy-ref result=policy uses=fetch,secrets secrets=pas-token
async ({ policyNumber }, { fetch, secrets, signal, FatalError }) => {
  const token = await secrets.getText('pas-token');
  const response = await fetch(`https://pas.northwind.example/v1/policies/${policyNumber}`, {
    headers: { Authorization: `Bearer ${token}` },
    signal,
  });
  if (response.status === 404) throw new FatalError(`Policy ${policyNumber} not found`);
  if (!response.ok) throw new Error(`Policy read failed (${response.status})`);
  const body = await response.json();
  if (
    typeof body !== 'object' ||
    body === null ||
    !('status' in body) ||
    (body.status !== 'active' && body.status !== 'cancelled' && body.status !== 'lapsed')
  ) {
    throw new Error('Policy response has no valid status');
  }
  return { status: body.status };
};
```
````

> [!NOTE]
>
> The policy administration host, its path and the `pas-token` secret are illustrative. Use your own
> system's API.

The call fence and the declaration it runs need different IDs, because all fences in a document
share one ID namespace. Here `fetch-policy` runs `@local.read-policy`.

## On retry and resume

* **Inputs are checked before the code runs.** The run resolves every reference in `input` into
  one object and validates it against the callable's input schema before dispatch.
* **Each call has a stable identity.** The run fixes one operation identity for the call before it
  runs. Every attempt of the same call sees the same `operation.idempotencyKey`, which an effect
  sends to the system it writes to.
* **Failed attempts retry under a policy.** Local functions and effects get three attempts by
  default. A [`retry`](https://docs.canary.effectiveai.app/procedures/reference/nodes/retry) policy on the declaration replaces that.
  An effect error is retried; a pure-function error is not, because running it again gives the
  same answer. See [writes to your systems](https://docs.canary.effectiveai.app/procedures/concepts/writes-to-your-systems.md).
* **A finished call doesn't run again.** A successful result is validated, recorded, and bound to
  `output` once. A run that resumes uses the recorded result and does not call your code again.
* **Not exactly once.** A write can reach your system and its answer still be lost, and a retry
  can then send it again. Use your system's idempotency key or a natural business key, or allow
  only one attempt. Put each write that must recover on its own in its own call.
* **Callables are pinned.** Publishing a procedure pins each callable it resolves, including your
  local code. A run never picks up a different implementation part way through.

When a call fails for a technical reason, the step fails with one of these codes, and the run
fails with it. The run's `failure.code` is `operation_failed`; its `failure.message`, which is for
people to read, names the step and the step's code. The codes are never turned into a business
result or a `choice` value:

| Code | Meaning |
| - | - |
| `local-code-failed` | The code threw, or its retry attempts ran out |
| `operation-timeout` | The code ran past its time limit |
| `operation-cancelled` | The run was cancelled while the call was running |
| `worker-lost` | The run lost contact with the attempt after it started |
| `code-admission-failed` | The code could not be loaded to run |
| `invalid-result` | The result did not match the callable's result schema |
| `resource-exhausted` | The code hit a fixed compute, memory, stack or output limit |

The message doesn't include what your code threw. A thrown message could hold a secret value, so
Effective doesn't show it, for `FatalError` or any other error.

Expected business outcomes, such as "policy not found, so skip", belong in the result schema as
values a later [`choice`](https://docs.canary.effectiveai.app/procedures/reference/nodes/choice) can route on. So do refusals you
need to see: return them as typed results, and log the detail in your own system.

A `call` of an `@effective.api.*` operation has no failure routing: if the API refuses it, the run
stops with the API's reason. To branch on a refusal, make the request inside a `ts effect` and use
`effective.apiError`, as described on the
[function and effect page](https://docs.canary.effectiveai.app/procedures/reference/nodes/function-and-effect.md#branch-on-a-refused-effective-api-call).

## Common errors

| Code | Cause | Fix |
| - | - | - |
| `PROC-CALL-001` | The body has a field other than `function`, `input` and `output`, or the function reference is malformed. | Remove the extra field. Write the reference as `'@namespace.name'`. |
| `PROC-CALL-002` | The function doesn't resolve, for example `Unresolved callable @local.read-polcy.` | Fix the name, or add the `ts function` or `ts effect` declaration. |
| `PROC-CALL-005` | The callable's timeout or retry policy is invalid. | Fix the policy on the declaration. |
| `PROC-DATA-004` | An input references a value that doesn't exist, for example `Unresolved data reference $inputs.policy_numbr.` | Fix the reference, or produce the value earlier. |
| `PROC-SCHEMA-005` | The input doesn't match the callable's input schema, for example `input.effectiveDate is not declared by policy-ref.` | Add or remove operands to match the schema. |
| `PROC-GRAPH-005` | The `output` name is already used. | Pick a name no other node, input or output uses. |
| `PROC-GRAPH-006` | The value an input reads isn't produced on every path before this call. | Move the call after the node that produces the value. |
| `PROC-FENCE-004` | The call has the same ID as another fence, often the declaration it runs. | Give the call its own ID. |

## See also

* [Function and effect declarations](https://docs.canary.effectiveai.app/procedures/reference/nodes/function-and-effect.md)
* [`retry` policy](https://docs.canary.effectiveai.app/procedures/reference/nodes/retry)
* [`invoke` node](https://docs.canary.effectiveai.app/procedures/reference/nodes/invoke)
* [`value` node](https://docs.canary.effectiveai.app/procedures/reference/nodes/value)
* [`wait` node](https://docs.canary.effectiveai.app/procedures/reference/nodes/wait), whose polling form runs an effect repeatedly
* [Writes to your systems](https://docs.canary.effectiveai.app/procedures/concepts/writes-to-your-systems.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.