# Throttling

Some plugins call external providers that embedded API limitations. Because some plugins have trouble handling errors when limits are reached, we may want to reduce plugin calls before reaching those limits.

Using *Throttlings*, you can limit usage of a given plugin version, in 3 different ways :&#x20;

* Rate limit :  you can limit the number of calls by second, by using `max_qps` field.
* Concurrency : you can limit the number of simultaneous calls, by using `max_concurrency` field.
* Timeout : you can define a maximum duration for the calls, by using `timeout_qps` field.

{% hint style="warning" %}
You have to define at least one of those restrictions.
{% endhint %}

*Throttling* can be defined at 4 different levels :&#x20;

* GLOBAL
* CONTAINER
* ORGANISATION
* DATAMART

You can define a *Throttling* using this route :

## Create a throttling

<mark style="color:green;">`POST`</mark> `https://api.mediarithmics.com/v1/plugins/:plugin_id/versions/:version_id/throttlings`

#### Request Body

| Name                                                  | Type    | Description                                                                                                             |
| ----------------------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------- |
| scope<mark style="color:red;">\*</mark>               | String  | Define the application scope of the Throttling. Possible values : GLOBAL, CONTAINER, DATAMART or ORGANISATION.          |
| plugin\_version\_id<mark style="color:red;">\*</mark> | String  | The ID of the plugin version.                                                                                           |
| throttling\_key                                       | String  | Is equals to the datamart id if the scope is DATAMART or the organisation id if the scope is ORGANISATION.              |
| max\_concurrency                                      | Integer | The maximum number of simultaneous calls to the end\_point.                                                             |
| max\_qps                                              | Double  | The maximum number of calls to the end\_point by second. It can be decimal, 0.5 means : maximum 1 call every 2 seconds. |
| plugin\_endpoint<mark style="color:red;">\*</mark>    | String  | The plugin routes affected by this throttling. Exemple : `/v1/user_segment_update`                                      |
| timeout\_ms                                           | Integer | The call to the endpoint is killed if it lasts more than this duration (in ms).                                         |

{% tabs %}
{% tab title="201: Created " %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

You can list, delete or update Throttlings by using thoses routes :

## Get throttlings for the Plugin Version

<mark style="color:blue;">`GET`</mark> `https://api.mediarithmics.com/v1/plugins/:plugin_id/versions/:version_id/throttlings`

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

## Delete a throttling

<mark style="color:red;">`DELETE`</mark> `https://api.mediarithmics.com/v1/plugins/:plugin_id/versions/:version_id/throttlings/:throttling_id`

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

## Update a throttling

<mark style="color:orange;">`PUT`</mark> `https://api.mediarithmics.com/v1/plugins/:plugin_id/versions/:version_id/throttlings/:throttling_id`

#### Request Body

| Name                                               | Type    | Description                                                                                                             |
| -------------------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------- |
| scope<mark style="color:red;">\*</mark>            | String  | Define the application scope of the Throttling. Possible values : GLOBAL, CONTAINER, DATAMART or ORGANISATION.          |
| throttling\_key                                    | String  | Is equals to the datamart id if the scope is DATAMART or the organisation id if the scope is ORGANISATION.              |
| max\_concurrency                                   | Integer | The maximum number of simultaneous calls to the end\_point.                                                             |
| max\_qps                                           | Double  | The maximum number of calls to the end\_point by second. It can be decimal, 0.5 means : maximum 1 call every 2 seconds. |
| plugin\_endpoint<mark style="color:red;">\*</mark> | String  | The plugin routes affected by this throttling. Exemple : `/v1/user_segment_update`                                      |
| timeout\_ms                                        | Integer | The call to the endpoint is killed if it lasts more than this duration (in ms).                                         |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}


---

# 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://developer.mediarithmics.io/advanced-usages/plugins/throttling.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.
