Maybe a short hint to the excellent article from Julia.
In meanwhile it is possible to use Managed Identity to authenticate against the Azure OpenAI Instances.
Therefore the following steps needs to be done:
- Enable Managed Identity on APIM
- Add APIM Managed Identity with role "Cognitive Services OpenAI User" to the OpenAI Instance.
- Replacing Julias Inbound policy with the following snippet:
<authentication-managed-identity resource="https://cognitiveservices.azure.com" output-token-variable-name="msi-access-token" ignore-error="false" />
<set-header name="Authorization" exists-action="override">
<value>@("Bearer " + (string)context.Variables["msi-access-token"])</value>
</set-header>
The authentication-managed-identity policy (https://learn.microsoft.com/en-us/azure/api-management/authentication-managed-identity-policy) is using the APIM System Managed Identity to request a Token with the required OAuth scope "https://cognitiveservices.azure.com". In the next step the set-header policy is used to set/replace the Authorization http header to authenticate the request