R
RunPod•7d ago
jackson hole

I want to increase/decrease workers by code, can you help?

I have a serverless setup already. Generally we keep 1 active worker in the actual time when we expect the traffic throughout the day, and at night when no one is using the application we make active workers 0 to avoid any charges. And then the next day, we make active workers 1 manually from runpod dashboard. We are willing to do that automatically. I know there is a GraphQL but I am not able to find relevant code to do that. Can anyone please help? Thanks!!
6 Replies
Mark
Mark•7d ago
I wanted to ask for the exact same thing!
jackson hole
jackson holeOP•6d ago
Let's hope for the best!
Eren
Eren•6d ago
it's actually possible by Graph QL API, you can find a sample Endpoint mutation call below
curl --location --globoff 'https://api.runpod.io/graphql?api_key={{RUNPOD_API_KEY}}' \
--header 'content-type: application/json' \
--data '{"query":"mutation saveEndpoint($input: EndpointInput!) {\n saveEndpoint(input: $input) {\n gpuIds\n id\n idleTimeout\n locations\n name\n networkVolumeId\n scalerType\n scalerValue\n templateId\n userId\n workersMax\n workersMin\n gpuCount\n __typename\n }\n}","variables":{"input":{"gpuIds":"ADA_24,AMPERE_24,-NVIDIA L4,-NVIDIA RTX A5000","gpuCount":1,"allowedCudaVersions":"","id":"{{ID}}","idleTimeout":1,"locations":null,"name":"faster_whisper -fb","networkVolumeId":null,"scalerType":"QUEUE_DELAY","scalerValue":4,"workersMax":3,"workersMin":0,"executionTimeoutMs":180000}}}'
curl --location --globoff 'https://api.runpod.io/graphql?api_key={{RUNPOD_API_KEY}}' \
--header 'content-type: application/json' \
--data '{"query":"mutation saveEndpoint($input: EndpointInput!) {\n saveEndpoint(input: $input) {\n gpuIds\n id\n idleTimeout\n locations\n name\n networkVolumeId\n scalerType\n scalerValue\n templateId\n userId\n workersMax\n workersMin\n gpuCount\n __typename\n }\n}","variables":{"input":{"gpuIds":"ADA_24,AMPERE_24,-NVIDIA L4,-NVIDIA RTX A5000","gpuCount":1,"allowedCudaVersions":"","id":"{{ID}}","idleTimeout":1,"locations":null,"name":"faster_whisper -fb","networkVolumeId":null,"scalerType":"QUEUE_DELAY","scalerValue":4,"workersMax":3,"workersMin":0,"executionTimeoutMs":180000}}}'
GraphQL API Docs: https://graphql-spec.runpod.io/ Without API Docs: you can go to your dashboard and open the Developer Tools by F12 go to Network tab then make an update on your endpoint and find the mutation API call then you can just copy that as CURL and work on it on postman remember to remove all Headers and add api_key query param
jackson hole
jackson holeOP•6d ago
The network hack is a Gem 💎 Will surely try this!! Thanks!!
Eren
Eren•6d ago
🚀 PS: To set Active Worker you need to set the workersMin variable in json
nerdylive
nerdylive•6d ago
In the reference there is no such mutation for endpoints? Oh there is

Did you find this page helpful?