@Sisodia, Deepak Thanks for reaching out. You can leverage send-request policy to call any external service that will perform complex processing functions and return data to the API Management service that can be used for further policy processing. In your case to generate the token you need to call your service that will return the token and APIM will pass the newly generated token to your backend service.
You can also refer to this article which explains how you can leverage policy for Access Token Acquisition, Caching, Renewal, and pas the same to your backend service.