# Function instances

A function instance binds one function to one application. The instance carries the **Args**, the arguments passed into the context of the function's execution in JSON format. The code of the function cannot be edited at instantiation: an instance sets the Args and nothing else.

A rule in [Rules Engine](/en/documentation/platform/applications/rules-engine/) invokes the instance, not the function. The same function can be instantiated in more than one application, and each instance carries its own Args. An instance that no rule names never runs.

A firewall instantiates functions the same way. An instance on a firewall runs its function before the request reaches the application, so the function can stop the request there. An instance on an application runs its function as part of serving the request. Refer to [Function instances for Firewall](/en/documentation/platform/firewall/functions-instances/) for the firewall object, and to [Firewall limits](/en/documentation/platform/firewall/limits/#rules-and-function-instances) for its bounds.

---

## Instance fields

The [Azion API](https://api.azion.com/) creates an instance under the application it belongs to. These are the fields you set:

| Field        | Type                 | Required | Description                                                                                                                                 |
| ------------ | -------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `name`       | string               | Yes      | Name of the instance.                                                                                                                       |
| `function`   | integer              | Yes      | ID of the function the instance binds. This ID differs from the ID of the instance.                                                         |
| `args`       | JSON object or array | No       | Arguments passed into the context of the function's execution. When the instance sets no args, the `default_args` of the function are used. |
| `azion_form` | JSON object          | No       | A JSON Schema that renders the args as a form. When none is set, an empty object is used.                                                   |
| `active`     | boolean              | No       | Whether the instance is active.                                                                                                             |

The API returns four more fields: `id`, the ID of the instance; `last_editor`, the email address of the account that last changed it; `last_modified`, the timestamp of that change; and `created_at`, the timestamp of creation.

A `POST` request to the `functions` resource of an application creates an instance:

```bash
curl --request POST \
  --url https://api.azion.com/v4/workspace/applications/<application_id>/functions \
  --header 'Accept: application/json' \
  --header 'Authorization: Token [TOKEN VALUE]' \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "My instance Name",
  "function": <function_id>,
  "active": true
}'
```

The API answers with the created object:

```json
{
  "state": "pending",
  "data": {
    "id": <function_instance_id>,
    "name": "My Function Instance",
    "args": {},
    "azion_form": {},
    "function": 123456,
    "active": true,
    "last_editor": "your-email@example.com",
    "last_modified": "2025-08-14T16:41:56.699896Z",
    "created_at": "2025-08-14T16:41:56.812345Z"
  }
}
```

The `"state": "pending"` value means the change takes a few minutes to propagate before it takes effect.

You create the same object in the **Functions Instances** tab of an application in Azion Console. In the `azion.config.js` file that [Azion CLI](/en/documentation/devtools/cli/) reads, an instance carries `name`, `args`, and `active`, and `ref` names the function by name or by ID.

---

## Args

Args are the arguments an instance passes into the context of the function's execution, written as a JSON object. The code reads a key at run time and the instance decides its value, so one function behaves differently in each place it is instantiated. A function can define default Args of its own: the Args of an instance override the keys they repeat, and every key the instance leaves out keeps its default value.

An Args object that sets one key:

```json
{
  "value": "hello_world"
}
```

The Args object holds a maximum of 100 KB, and an object above that ceiling makes the function fail at instantiation. For every Functions limit, refer to [Limits](/en/documentation/platform/functions/limits/).

Args are per-instance configuration. Sensitive values such as API keys, credentials, and access tokens belong in [environment variables](/en/documentation/platform/functions/environment-variables/) instead.

---

## Run Function behavior

**Run Function** is the [Rules Engine](/en/documentation/platform/applications/rules-engine/#run-function) behavior that invokes an instance. The rule names the instance, the execution phase, and the criteria that trigger it. When a request meets those criteria, the function runs on Azion's distributed infrastructure.

Run Function is available in the Request Phase and in the Response Phase, and it requires the [Application Accelerator](/en/documentation/platform/applications/#application-accelerator) module. In the Azion API, the behavior is `run_function` and its `value` attribute holds the ID of the instance.

For the execution phases, the criteria, and the order behaviors run in, refer to [How Functions works](/en/documentation/platform/functions/how-it-works/).

---

## Related resources

- [How Functions works](/en/documentation/platform/functions/how-it-works.md): The path a request takes from a Rules Engine rule to your function code.
- [How to instantiate functions in your application](/en/documentation/guides/application-development/getting-started/instantiate-functions.md): The steps to create an instance in Azion Console and through the Azion API.
- [Using args](/en/documentation/platform/functions/using-args.md): A function that reads a key from its Args and answers with the value.
- [Limits](/en/documentation/platform/functions/limits.md): The size ceiling for Args and every other Functions limit.
