You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在无凭据情况下使用Azure DocumentAnalysisClient?

无需凭据使用DocumentAnalysisClient的解决方案

你的Form Recognizer端点是开放无认证的场景,可以使用Azure SDK提供的AnonymousCredential类来实例化DocumentAnalysisClient,该凭据不会向请求添加任何认证信息,完美适配你的开放端点需求。

完整示例代码

from azure.ai.formrecognizer import DocumentAnalysisClient
from azure.core.credentials import AnonymousCredential

# 注意:endpoint不要携带api-version参数,SDK会自动处理版本匹配
my_endpoint = "http://form_recognizer..."
client = DocumentAnalysisClient(endpoint=my_endpoint, credential=AnonymousCredential())

# 调用客户端内置方法示例(以预构建的读取模型为例)
with open("target-document.pdf", "rb") as doc_file:
    poller = client.begin_analyze_document("prebuilt-read", document=doc_file)
analysis_result = poller.result()

# 处理分析结果示例
for page in analysis_result.pages:
    for line in page.lines:
        print(line.content)

关键注意事项

  • 不要在endpoint中包含api-version参数,SDK会根据客户端版本自动匹配对应的API版本,避免手动指定导致的版本冲突。
  • 如果你的开放端点需要自定义请求头,可以在实例化客户端时通过headers参数添加:
    client = DocumentAnalysisClient(
        endpoint=my_endpoint,
        credential=AnonymousCredential(),
        headers={"X-Custom-Header": "custom-value"}
    )
    

内容的提问来源于stack exchange,提问作者user3124181

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 10:29:55