如何用Bicep编写带API密钥的Azure Form Recognizer API连接?
正确配置Logic App与Azure AI Document Intelligence的API连接(Bicep)
以下是实现Logic App与Azure AI Document Intelligence(原Form Recognizer)API连接的正确Bicep配置,核心是准确匹配API连接的参数要求和认证方式:
param location string = resourceGroup().location param documentIntelligenceAccountName string param documentIntelligenceApiKey string // 引用已存在的Azure AI Document Intelligence实例 resource documentIntelligence 'Microsoft.CognitiveServices/accounts@2023-05-01' existing = { name: documentIntelligenceAccountName } // 创建formrecognizer类型的API连接 resource formRecognizerConnection 'Microsoft.Web/connections@2016-06-01' = { name: 'formrecognizer-connection' // 自定义连接名称 location: location properties: { displayName: 'Azure AI Document Intelligence Connection' api: { // 引用formrecognizer的托管API定义,路径自动匹配当前订阅和区域 id: '/subscriptions/${subscription().subscriptionId}/providers/Microsoft.Web/locations/${location}/managedApis/formrecognizer' } // 必填参数:API密钥和服务端点 parameterValues: { apiKey: documentIntelligenceApiKey endpoint: documentIntelligence.properties.endpoint } // 指定ApiKey认证方式 authentication: { type: 'ApiKey' parameter: { name: 'apiKey' type: 'string' value: documentIntelligenceApiKey // 若使用Key Vault存储密钥,可替换value为以下配置(需提前授予连接资源访问密钥权限) // keyVaultSecretReference: { // secretName: 'document-intelligence-api-key' // keyVault: { // id: '/subscriptions/<订阅ID>/resourceGroups/<资源组>/providers/Microsoft.KeyVault/vaults/<密钥保管库名称>' // } // } } } } }
关键配置说明
- API定义引用:必须通过
api.id指定formrecognizer的托管API资源路径,确保Logic App识别连接类型。 - 必填参数:
parameterValues中必须同时提供apiKey和endpoint,二者缺一不可,这是formrecognizer连接的硬性要求。 - 认证方式:明确设置
authentication.type为ApiKey,并在parameter中绑定密钥参数名apiKey,确保认证逻辑正确。
常见错误排查
- 参数名误用:formrecognizer连接仅支持
apiKey作为密钥参数名,sharedKey/accountKey等均不适用。 - 遗漏端点:未配置
endpoint会导致连接无法完成服务验证,即使密钥正确也会失败。 - 认证类型错误:请勿使用其他认证类型(如OAuth),formrecognizer API连接仅支持ApiKey认证。
内容的提问来源于stack exchange,提问作者Andries
相关产品推荐
相关产品推荐

