# Execution Options

## About&#x20;

Execution options provide additional control over the request execution. &#x20;

***

<table><thead><tr><th width="193">Property</th><th>Description</th></tr></thead><tbody><tr><td>priority</td><td>The priority of the request and the way it should be executed. Applicable only if the EES priority is set to Configurable during EES Wizard. Otherwise, the EES original priority is used.</td></tr><tr><td>deduplicationId</td><td>Allows preventing the execution of the same request multiple times.</td></tr><tr><td>retries</td><td>The number of retries. If not provided, the default value from the EES Wizard will be used.</td></tr><tr><td>fallback</td><td>The service that may be used in case of unsuccessful retries.</td></tr><tr><td>callback</td><td>The fallback channel in case when EES is asynchronous. If not provided, the default channel from the EES Wizard will be used.</td></tr></tbody></table>

## priority

***

The `priority` property determines the execution priority, with options available only if the [EES (Elastic Endpoint)](/services/ees-elastic-endpoint.md) priority is set to Configurable during the [EES (Elastic Endpoint)](/services/ees-elastic-endpoint.md) Wizard setup.&#x20;

The system adjusts its load balancing strategy based on the chosen priority options, whether directly selected or configured through the [EES (Elastic Endpoint)](/services/ees-elastic-endpoint.md) wizard. Opting for suitable priorities can lead to cost savings on services like [AIL (AI Lambda)](/services/ail-ai-lambda.md), especially when there's a defined timeframe for execution.

The following options are available:

1. **AT\_EASE**:

   The request will be executed as soon as possible depending on the current load of the system.
2. **PRIORITIZED**:

   The request will be executed with the highest priority. However, it will be executed only after all INSTANT requests. If the system is overloaded, the request may be delayed.
3. **INSTANT**:

   Regardless of the system load, the request will be executed immediately.

### Use Cases

⭐️ **Delayed Execution**

When real-time results are not imperative, C4AI offers cost-saving opportunities on processing. For instance, if there's a week-long timeframe to prepare marketing materials, utilizing the `AT_EASE` priority can be advantageous.&#x20;

⭐️ **Background Processing**

For tasks such as document parsing or preparing design materials (e.g., an Image Library) that can be processed in the background, delaying execution helps in cost reduction. When combined with [EES (Elastic Endpoint)](/services/ees-elastic-endpoint.md) `ASYNC` mode, this approach facilitates the development of event-oriented data processing workflows with minimal additional effort.

## deduplicationId

***

The `deduplicationId` property prevents the execution of duplicate requests. The system will retain only the initial request associated with the `deduplicationId`. Subsequent requests will be disregarded until the corresponding C4AI Command Request transitions into either a COMPLETED or FAILED state.

#### Use Cases

⭐️ **Continues Updates**

By utilizing the `deduplicationId`, you can effectively avoid redundant executions. For instance, if you maintain your database containing product information that administrators can update at any time, you can generate a custom deduplicationId incorporating your product ID. This approach helps minimize the number of requests to the Embeddings API.

## retries

***

The `retries` property specifies the number of retries, utilizing the default value from the EES Wizard if not provided.

By adjusting the retry count, you can tailor the handling of unsuccessful executions to your specific needs. **The maximum number of retries allowed is set at 10**.

> 💡 **Note:**  If you're looking for more advanced Retry Policies, please contact us via Support Requests in Your [C4AI Cloud Console](https://console.cloud4.ai).&#x20;

### Use Cases

⭐️ **Instability of AI Providers**

In scenarios where the AI provider encounters stability issues, such as maintenance downtime, critical responses may be impacted. In such cases, defining the number of retries can mitigate the impact on user experience.

## fallback&#x20;

***

The `fallback` property specifies a service to use in case of unsuccessful retries.

Fallback Commands offer the flexibility to determine alternative actions in situations where all retries have been exhausted and the command still fails. By supplying an array of alternative commands, you can devise a customized behavior that aligns with your specific requirements.

> ❗️**Note:**  All commands provided in Array will be executed in the same sequence as they are define during the request

In contrast to [#callback](#callback "mention"), fallbacks are triggered on unsuccessful executions. Therefore, even if you submit an ASYNC request without a predefined callback operation, you have the option to define your own behavior using fallbacks.

### Use Cases

⭐️ **Instability of AI Providers**

When you require an alternative AI provider to be utilized in the event of primary provider downtime, you can specify this using an additional command.

```typescript
const command = new C4AI_EES.Commands.EXECUTE({
    service: new C4AI_EES(sic),
    command: new C4AI_AAC.Commands.EXECUTE({
        service: new C4AI_AAC(aacSic),
        parameters: new C4AI_RequestParameters(),
    }),
    options: new C4AI_EES_ExecutionOptions({
        fallback: [
            new C4AI_AAC.Commands.EXECUTE({
                service: new C4AI_AAC(alternativeAACSic),
                parameters: new C4AI_RequestParameters(),
            })
        ]
    }),
});
```

⭐️ **Background Fail**

In scenarios where your requests are in ASYNC mode, you can designate one or more API schemas as callbacks to receive notifications regarding failed executions.

In the example below, the WebHook will be called only in case when both: primary and alternative AI providers fail.&#x20;

```typescript
const command = new C4AI_EES.Commands.EXECUTE({
    service: new C4AI_EES(sic),
    command: new C4AI_AAC.Commands.EXECUTE({
        service: new C4AI_AAC(aacSic),
        parameters: new C4AI_RequestParameters(),
    }),
    options: new C4AI_EES_ExecutionOptions({
        fallback: [
            new C4AI_AAC.Commands.EXECUTE({
                service: new C4AI_AAC(alternativeAACSic),
                parameters: new C4AI_RequestParameters(),
            }),
            new C4AI_APISchema.Commands.EXECUTE({
                service: new C4AI_APISchema(errorHandlerSic),
                parameters: new C4AI_RequestParameters(),
            })
        ]
    }),
});
```

## callback

***

The `callback` property specifies a fallback channel in case EES is asynchronous, utilizing the default channel from the EES Wizard if not provided.

With Callback, you can specify one or more channels where data should be posted, effectively functioning as a broadcast mechanism. Consequently, all callback commands provided in an array will be executed regardless of their order, alongside the result of the command execution.

> 💡 **Note:** When additional mapping or object destruction is required, leverage the SDK's predefined parameters.

### Use Cases

⭐️ **Additional Storage**

By utilizing callback, you can direct the result to be stored in various storage options such as KDB, CDB, or even as a file within the system, if necessary. In these scenarios, all objects will be utilized. If any transformations are required, the IDTS service can be employed with additional preferences.

```typescript
const command = new C4AI_EES.Commands.EXECUTE({
    service: new C4AI_EES(sic),
    command: new C4AI_AAC.Commands.EXECUTE({
        service: new C4AI_AAC(aacSic),
        parameters: new C4AI_RequestParameters(),
    }),
    options: new C4AI_EES_ExecutionOptions({
        callback: [
            new C4AI_KDB.Commands.INSERT({
                service: new C4AI_AAC(alternativeAACSic)
            })
        ]
    }),
});
```

⭐️ **Alternative Execution Pipeline**

When you require additional processing of the result, you have the option to specify another command or request to the AI provider to utilize the result as input. For instance, the first provider may generate questions, and another provider can subsequently answer them using the generated output.

> ❗️**Note:**  Unlike [#fallback](#fallback "mention"), callbacks will only be executed upon successful execution of the target command

```typescript
const command = new C4AI_EES.Commands.EXECUTE({
    service: new C4AI_EES(sic),
    command: new C4AI_AAC.Commands.EXECUTE({
        service: new C4AI_AAC(aacSic),
        parameters: new C4AI_RequestParameters(),
    }),
    options: new C4AI_EES_ExecutionOptions({
        callback: [
            new C4AI_AAC.Commands.EXECUTE({
                service: new C4AI_AAC(alternativeAACSic)
            })
        ]
    }),
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cloud4.ai/sdk/request/execution-options.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
