Limit APIs
Install the following packages to run the samples on this page and run the following code
pip install payi dotenvCreate a limit: limits.create()
create() will succeed and return the previously created limitwhen a previously createdlimit_id is specifed to a subsequent call to limits.create() and the configuration max and thresholdparameters match the initially created `limit. If they do not different match, the operation will fail with an error and raises an exception.
| Parameter | Type | Description |
|---|---|---|
limit_name | str | Friendly name |
limit_id | Optional str | Limit identifier. If none provided, Payi will return a limit_id in the response. |
max | float | Maximum limit in USD |
thresold | Optional float | Percentage of the limit's maximum, valid valures are between 0.75 and 0.99 |
limit_type | str = allow or block | allow limits will allow all requests to proceed, even if the max has been reached or exceeded.block limits will prevent requests from proceeding if the max has been reached or exceeded. block limits are only allowed to valid when Payi is a proxy for the inference request. |
properties | Optional dict[str, str] | Property Bag associated with the limit |
from payi import Payi
from dotenv import load_dotenv
load_dotenv()
payi = Payi()
# more common: specify a deterministic limit_id so it can be reused later without additional storage
# less common: Payi generates a limit_id
response = payi.limits.create(
limit_name="Limit 1",
limit_id="limit_1_id",
max=10.0,
limit_type="allow",
threshold=0.80
)
# less common: Payi generates a limit_id
response = payi.limits.create(
limit_name="Limit 2",
max=10.0,
limit_type="allow",
threshold=0.80
)
limit2_id = response.limit.limit_idUpdating a limit: limits.update()
| Paramter | Type |
|---|---|
limit_id | str |
limit_name | Optional str |
max | Optional str |
from payi import Payi
from dotenv import load_dotenv
load_dotenv()
payi = Payi()
limit_id = "update_limit"
response = payi.limits.create(
limit_name="Updated Limit",
limit_id=limit_id,
max=15.0,
limit_type="allow",
threshold=0.80
)
# Update max
updated_response = payi.limits.update(
limit_id=limit_id,
max=30.0
)
# Update name
updated_response = payi.limits.update(
limit_id=limit_id,
limit_name="New Updated Limit"
)Enumerating limits: limits.list()
The SDK automatically handles server request pagination.
| Parameter | Type | Description |
|---|---|---|
limit | Optional int | Limit the the number of limitobjects returned by the underlying Payi service API |
limit_name | Optional str | Filter the results to limitobjects matching limit_name |
sort_ascending | Optional bool | Sort the results by creation date. Default is True |
from payi import Payi
from dotenv import load_dotenv
load_dotenv()
payi = Payi()
response = payi.limits.create(
limit_name="1 Limit",
max=15.0,
limit_type="allow",
threshold=0.80
)
response = payi.limits.create(
limit_name="2 Limit",
max=20.0,
limit_type="allow",
threshold=0.90
)
for limit in payi.limits.list():
print(f"Limit: {limit.limit_name}")You don't need to manually handle pagination or worry about cursor management - the SDK takes care of making multiple API calls as needed when you iterate through the results. This makes it easy to work with large collections of limits without worrying about pagination implementation details.
Resetting a limit: limits.reset()
Reset a limit back to zero
| Parameter | Type |
|---|---|
limit_id | str |
from payi import Payi
from dotenv import load_dotenv
load_dotenv()
payi = Payi()
limit_id = "reset_limit"
response = payi.limits.create(
limit_name="Reset limit",
limit_id=limit_id,
max=15.0,
limit_type="allow",
threshold=0.80
)
response = payi.limits.reset(limit_id=limit_id)Deleting a limit: limits.delete()
It is NOT RECOMMEND to delete limts unless absolutely necessary. Deleting a limit does not delete inference requests already associated with the limit. Deletion only prevents future use of the limit.
NOTE: When experimenting with limits or running the examples in this guide multiple times, you may need to delete created limits.
from payi import Payi
from dotenv import load_dotenv
load_dotenv()
payi = Payi()
limit_id = "delete_limit"
response = payi.limits.create(
limit_name="Delete limit",
limit_id=limit_id,
max=15.0,
limit_type="allow",
threshold=0.80
)
payi.limits.delete(limit_id=limit_id)