Multiple endpoints within one handler

I have had success creating serverless endpoints in runpod with handler.py files that look like this: imports ... def handler(job): job_input = job['input'] ... return result runpod.serverless.start({"handler": handler}) Now im trying to deploy a severless endpoint with a handler that has two individual functions instead of one. With a traditional flask api set up, it would look like two app.routes. I understand runpod doesnt work with flask But if i were to want to structure a handler.py with multiple endpoints (multiple different def handler(job) methods), how would i do that? and then how would i call those endpoints? I would assume its like this: https://api.runpod.ai/v2/.../runsync/<endpoint1> https://api.runpod.ai/v2/.../runsync/<endpoint2> Can anyone assist me in solving this problem?
4 Replies
flash-singh
flash-singh2mo ago
you can use an environment variable to select which handler is passed to the runpod.serverless.start({"handler": handler}) e.g.
if x == "A":
runpod.serverless.start({"handler": handlerA})
elif x == "B"
runpod.serverless.start({"handler": handlerB})
if x == "A":
runpod.serverless.start({"handler": handlerA})
elif x == "B"
runpod.serverless.start({"handler": handlerB})
zfmoodydub
zfmoodydubOP2mo ago
will give this a go, thanks!
flash-singh
flash-singh2mo ago
also you can override the start command, you can create 2 templates using same container image, override the start command to call a different .py script
zfmoodydub
zfmoodydubOP2mo ago
thats a good backup. cheers i did in fact use your first suggestion and it worked, thank you
Want results from more Discord servers?
Add your server