# Is it possible to run and stop an endpoint using code/API to avoid be billed when it is not used?

**URL:** <https://discuss.huggingface.co/t/is-it-possible-to-run-and-stop-an-endpoint-using-code-api-to-avoid-be-billed-when-it-is-not-used/30208>\
**Category:** Inference Endpoints on the Hub\
**Created:** [January 23, 2023, 9:27am UTC](https://discuss.huggingface.co/t/is-it-possible-to-run-and-stop-an-endpoint-using-code-api-to-avoid-be-billed-when-it-is-not-used/30208 "2023-01-23T09:27:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![smartinezbragado](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@smartinezbragado](https://discuss.huggingface.co/u/smartinezbragado)\
**Post date:** [January 23, 2023, 9:27am UTC](https://discuss.huggingface.co/t/is-it-possible-to-run-and-stop-an-endpoint-using-code-api-to-avoid-be-billed-when-it-is-not-used/30208/1 "2023-01-23T09:27:03Z")

</div>

I want to use the HF inference endpoint for my project but, since the model will be used just few hours per day I want to launch the endpoint and stop it within the same day. Is it possible?

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [January 23, 2023, 8:54pm UTC](https://discuss.huggingface.co/t/is-it-possible-to-run-and-stop-an-endpoint-using-code-api-to-avoid-be-billed-when-it-is-not-used/30208/2 "2023-01-23T20:54:18Z")

</div>

hi @smartinezbragado , currently it’s no possible, but it’s on a short term milestone to implement it.

---

<div class="post-metadata">

**Author:** ![ronvolutional](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/ronvolutional/32/4489_2.png) [@ronvolutional](https://discuss.huggingface.co/u/ronvolutional)\
**Post date:** [February 17, 2023, 3:47am UTC](https://discuss.huggingface.co/t/is-it-possible-to-run-and-stop-an-endpoint-using-code-api-to-avoid-be-billed-when-it-is-not-used/30208/3 "2023-02-17T03:47:32Z")

</div>

Happy to let you know we’ve just made this possible!: [Pause and Resume your Endpoint](https://huggingface.co/docs/inference-endpoints/guides/pause_endpoint)  
You can Pause/Resume as often as you’d like to only be billed while you need the model.

---

<div class="post-metadata">

**Author:** ![smartinezbragado](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@smartinezbragado](https://discuss.huggingface.co/u/smartinezbragado)\
**Post date:** [February 20, 2023, 10:50pm UTC](https://discuss.huggingface.co/t/is-it-possible-to-run-and-stop-an-endpoint-using-code-api-to-avoid-be-billed-when-it-is-not-used/30208/4 "2023-02-20T22:50:28Z")

</div>

Thanks @radames and @ronvolutional . I am reading the documentations of the API and I did not find anything to pause and resume the endpoint (only downscale it to 0). Is it possible to pause/resume it through API or only manually?

Thanks in advance 🙂

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [February 22, 2023, 1:48am UTC](https://discuss.huggingface.co/t/is-it-possible-to-run-and-stop-an-endpoint-using-code-api-to-avoid-be-billed-when-it-is-not-used/30208/5 "2023-02-22T01:48:40Z")

</div>

just copying and pasting @philschmid response from discord here

> ```auto
> curl --request PUT \
> --url https://api.endpoints.huggingface.cloud/endpoint/ENPOINT-NAME \
> --header 'Authorization: Bearer TOKEN' \
> --header 'Content-Type: application/json' \
> --data '{
> "compute": {
> "scaling": {
> "minReplica": 0,
> "maxReplica": 0
> }
> }
> }'
> 
> ```

---

<div class="post-metadata">

**Author:** ![mperesson](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@mperesson](https://discuss.huggingface.co/u/mperesson)\
**Post date:** [June 19, 2023, 12:25pm UTC](https://discuss.huggingface.co/t/is-it-possible-to-run-and-stop-an-endpoint-using-code-api-to-avoid-be-billed-when-it-is-not-used/30208/6 "2023-06-19T12:25:21Z")

</div>

This does not work anymore. I get a `400` error.

The dashboard get the exact same error when clicking on the “Stop endpoint” button.  
I guess it’s linked to the new “Automatic Scale-to-Zero” option.

Any idea on how to pause/resume endpoints now?

---

<div class="post-metadata">

**Author:** ![mcpotato](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mcpotato/32/19469_2.png) [@mcpotato](https://discuss.huggingface.co/u/mcpotato)\
**Post date:** [June 19, 2023, 3:10pm UTC](https://discuss.huggingface.co/t/is-it-possible-to-run-and-stop-an-endpoint-using-code-api-to-avoid-be-billed-when-it-is-not-used/30208/7 "2023-06-19T15:10:51Z")

</div>

Hello, we’ve indeed changed the way you pause/stop an endpoint. There are two new routes, `/pause` and `/resume`.

You can check the swagger docs [here](https://api.endpoints.huggingface.cloud/#/v2%3A%3Aendpoint/pause_endpoint), let me know if there is anything else I can do to help.
