Repository navigation
fix(ocr): isolate Azure Document Intelligence credential resolution - #40499
yujonglee-berri wants to merge 3 commits into
Conversation
Greptile SummaryThis PR moves OCR connection-parameter resolution behind provider adapters so Azure Document Intelligence can ignore inferred generic Azure AI credentials while preserving explicit credentials and other providers’ existing behavior.
Confidence Score: 5/5The PR appears safe to merge; the adapter refactor preserves existing behavior while correctly isolating Azure Document Intelligence credential defaults. No actionable regressions or outstanding previous findings remain. The earlier provider-specific-logic concern is fully addressed because Document Intelligence branching now resides in its provider adapter.
|
| Filename | Overview |
|---|---|
| litellm/llms/azure_ai/ocr/document_intelligence/transformation.py | Adds adapter-local suppression of inferred generic Azure credentials when Document Intelligence credentials were not explicitly supplied. |
| litellm/llms/base_llm/ocr/transformation.py | Adds a default connection-resolution hook that preserves existing credential precedence for other OCR providers. |
| litellm/ocr/main.py | Delegates connection resolution to the selected OCR adapter and consistently propagates the resulting values. |
| tests/test_litellm/ocr/test_ocr_azure_document_intelligence_api_base.py | Covers dedicated environment credentials, explicit credentials, secret references, and sync/async request preparation. |
| tests/test_litellm/proxy/auth/test_auth_utils.py | Adds regression coverage confirming that request-supplied OCR endpoints remain blocked by the proxy’s existing policy. |
Reviews (2): Last reviewed commit: "refactor(ocr): clarify credential resolu..." | Re-trigger Greptile
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@greptileai Please review the adapter refactor, simplified credential tests, and regression coverage for the existing proxy endpoint restriction |
TLDR
Problem this solves:
How it solves it:
User Flow
The bug occurs when an application configures both Azure AI and Azure Document Intelligence credentials, then calls Document Intelligence OCR without an explicit
api_key. LiteLLM sends the generic Azure AI key to the Document Intelligence endpoint, causing 401 even though the correct dedicated key is configuredBoth services use
litellm.ocr(); themodelstring selects the service. The keys and resource URLs below are placeholders to replace with your own valuesBefore: the Document Intelligence call fails despite valid dedicated credentials
api_keyorapi_baseAuthenticationErrorwith status 401: the call usesfoundry-keyagainst the Document Intelligence endpoint instead ofdi-keyAfter: the same Document Intelligence call uses its dedicated credentials and succeeds
api_keyorapi_base1parsed page: the call usesdi-keyandhttps://my-di.cognitiveservices.azure.comThe same fix applies to the async SDK call, inside an async function:
Other Azure OCR services retain their existing behavior. For example, this call uses
AZURE_AI_API_KEYandAZURE_AI_API_BASEbefore and after the fix, with the model available on the configured endpoint:Explicit Document Intelligence credentials also continue to take precedence:
Relevant issues
The proxy already rejects request-supplied
api_baseunless the administrator enables client-side overrides. A regression test covers the reported Document Intelligence payload without a key. SDK callers can still combine an explicit endpoint with environment credentialsValidation: 125 OCR and provider tests, 317 auth tests, and both live SDK calls pass. The request tests check the final endpoint and subscription-key header for environment and explicit credentials in sync and async modes
Linear ticket
Pre-Submission checklist
uv run pytest tests/test_litellm/<your_test_file>.py -vDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review)
Screenshots / Proof of Fix
The live check uses separate Azure AI and Document Intelligence keys, the documented environment-only SDK setup, and a public one-page PDF. LiteLLM documents these provider-specific variables, while Microsoft documents that Document Intelligence calls require the resource key and endpoint
Before (a8bb2f9)
python /tmp/ocr_auth_matrix.py --case azure-di-env-key --modes both --jobs 1 --delay 1After (2c10639)
python /tmp/ocr_auth_matrix.py --case azure-di-env-key --modes both --jobs 1 --delay 5Type
🐛 Bug Fix
Caveats (if any)
Final Attestation