欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 培训 > Using Managed Identity to Access Azure OpenAI Service

Using Managed Identity to Access Azure OpenAI Service

2024/10/25 11:35:22 来源:https://blog.csdn.net/suiusoar/article/details/141564041  浏览:    关键词:Using Managed Identity to Access Azure OpenAI Service

题意:使用托管身份访问 Azure OpenAI 服务

问题背景:

I'm working with Azure OpenAI service, and want to test its Managed Identity support. According to the docs it supports Managed Identity authentication, for example - using a VM.

我正在使用 Azure OpenAI 服务,并希望测试其托管身份(Managed Identity)支持。根据文档,它支持托管身份认证,例如使用虚拟机(VM)。

So I did the following:        因此,我进行了以下操作:

  1. Created a VM in Azure        在 Azure 中创建了一个虚拟机(VM)
  2. Assigned it a managed identity   为其分配了一个托管身份(Managed Identity)
  3. Assigned this identity a "Cognitive Services User" role (as per the docs) on the OpenAI resource   在 OpenAI 资源上为这个身份分配了“Cognitive Services User”角色(根据文档)。
  4. Downloaded Postman to the VM   在虚拟机上下载了 Postman
  5. Tried to access OpenAI API without the API Key (that's the whole point, isn't it?)

尝试在没有 API 密钥的情况下访问 OpenAI API(这不正是重点吗?)

But I keep getting a 401 error.        但我一直收到 401 错误。

What am I missing? With other services, VM with authenticated Managed Identity can access the service (ie. Storage Account, KeyVault). Why isn't it working here?

我遗漏了什么?对于其他服务,带有已认证托管身份的虚拟机可以访问该服务(例如,存储帐户、KeyVault)。为什么在这里不起作用呢?

问题解决:

In order to access Azure Open AI service, you still need an authentication header.

为了访问 Azure OpenAI 服务,你仍然需要一个认证头。

The difference that has a managed identity configured is instead of using api key, you can also use an access token to access the service.

配置了托管身份的区别在于,你可以使用访问令牌而不是 API 密钥来访问服务。

You can take GitHub - openai/openai-python: The official Python library for the OpenAI API as a reference about how to get the access token with managed identity.

你可以参考 GitHub 上的 openai/openai-python: The official Python library for the OpenAI API 了解如何使用托管身份获取访问令牌。

(I am a Microsoft employee working in the Azure SDK team.)

我是一名在 Azure SDK 团队工作的 Microsoft 员工。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com