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

# Functions

> Execute long-running JavaScript functions in Cognigy.AI for async processes like HTTP API calls to third-party systems.

*Functions* are JavaScript functions that you can define and execute in Cognigy.AI. You can use Functions to assist with long-running and asynchronous processes, such as interacting with third-party systems through HTTP API.

The execution of Functions is independent of Flows, but you can trigger them from a Flow. You can also use the [inject and notify](/ai/agents/deploy/endpoints/inject-and-notify) API endpoints in a Function to send results back into a Flow.

You can access the `parameters` and `api` objects from the Function's arguments.

## Limitations

* The maximum run-time of a Function instance is 15 minutes. For on-premises installations, you can change this limit via the `FUNCTION_EXECUTION_MAX_EXECUTION_TIME_IN_MINUTES` environment variable in the `values.yaml` file.
* You can define a Function only in JavaScript or TypeScript.

## Working with Functions

<Tabs>
  <Tab title="GUI">
    You can view, create, edit, and delete Functions in **Build > Functions**. To define, trigger, and monitor a Function, use the **Code** and **Instances** tabs.

    Also, you can trigger a Function from the Flow editor by using the [Trigger Function Node](/ai/agents/develop/node-reference/service/trigger-function).
  </Tab>

  <Tab title="API">
    You can view, create, edit, and delete Functions using the [Cognigy.AI API](https://api-trial.cognigy.ai/openapi#tag--Functions-v2.0). Using this API, you can also monitor, trigger, and stop a Function instance.
  </Tab>
</Tabs>

## Examples

<Note>
  You can use HTTP requests to interact with third-party systems.
</Note>

#### GET Request

```js theme={null}
export default async ({ parameters, api }: IFunctionExecutionArguments) => {
    const response = await api.httpRequest({
        method: "get",
        url: "https://example.com/api/v2",
        headers: {
            "Accept": "application/json"
        }
    });
}
```

#### POST Request

```js theme={null}
export default async ({ parameters, api }: IFunctionExecutionArguments) => {
    const response = await api.httpRequest({
        method: "post",
        url: "https://api.github.com/repos/octocat/Hello-World/issues",
        headers: {
            "Accept": "application/vnd.github.v3+json",
            "Authorization": "Bearer <your-github-token>"
        },
        data: {
            "title": "Found a bug",
            "body": "I'm having a problem with this.",
            "labels": ["bug"]
        }
    });
}
```

<Note>
  Functions can interact with Flows through the [Inject and Notify](/ai/agents/deploy/endpoints/inject-and-notify) APIs.

  The following examples assume that you pass `userId` and `sessionId` through the function's parameters.
</Note>

#### Injecting Text into Flows

```js theme={null}
export default async ({ parameters, api }: IFunctionExecutionArguments) => {
    const { userId, sessionId } = parameters;

    api.inject({
        userId,
        sessionId,
        text: "This text was injected through a Function"
    });
}
```

#### Sending Notifications

```js theme={null}
export default async ({ parameters, api }: IFunctionExecutionArguments) => {
    const { userId, sessionId } = parameters;

    api.notify({
        userId,
        sessionId,
        text: "This text was injected through a Function"
    });
}
```

Find more Function examples in the Cognigy's [functions](https://github.com/Cognigy/Functions?tab=readme-ov-file) repository.

## Use Case

Functions can help you handle HTTP requests that exceed the timeout in the [HTTP Request Node](/ai/agents/develop/node-reference/service/http-request). The HTTP Request Node allows direct access to API responses from the Flow, which is not possible with Functions. However, Functions allow you to work with slower APIs or long-running processes.

## More Information

* [Inject and Notify](/ai/agents/deploy/endpoints/inject-and-notify)
* [Trigger Function Node](/ai/agents/develop/node-reference/service/trigger-function)
