Skip to content

fix(azure_ai): route dedicated Cohere Parse endpoints correctly - #51938

Open
emerzon wants to merge 2 commits into
BerriAI:mainfrom
emerzon:litellm_azure_cohere_parse_endpoint
Open

emerzon wants to merge 2 commits into
BerriAI:mainfrom
emerzon:litellm_azure_cohere_parse_endpoint

Conversation

@emerzon

@emerzon emerzon commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

Send dedicated Azure Cohere Parse deployments to /v2/parse while keeping the resource endpoint route. Preserve existing path prefixes and query parameters.

Details

TLDR

Problem this solves:

  • Dedicated Azure Cohere Parse hosts receive the resource endpoint path.

How it solves it:

  • Use /v2/parse for *.models.ai.azure.com hosts.
  • Use /v2/parse for dedicated inference.ai.azure.com hosts.
  • Bill dedicated Parse passthrough calls like resource ones.
  • Keep resource endpoint routing and complete URLs intact.

User Flow

Before, using a dedicated base sends OCR to the wrong route.

  1. A developer configures an Azure Cohere Parse deployment with its dedicated base URL.
  2. They send POST http://localhost:4000/ocr with a document.
  3. The upstream request incorrectly includes /providers/cohere in its path.

After, the same document uses the dedicated Parse route.

  1. A developer configures an Azure Cohere Parse deployment with its dedicated base URL.
  2. They send POST http://localhost:4000/ocr with a document.
  3. The upstream request goes to /v2/parse on that host.

Relevant issues

Fixes #51910. #39862 introduced Parse support. #39427 is the older closed proposal.

The endpoint distinction follows Cohere's Azure deployment guide and the Parse API reference.

Implementation

The existing Rust URL builder selects the path using the parsed hostname. Dedicated *.models.ai.azure.com hosts and dedicated <endpoint>.<region>.inference.ai.azure.com hosts use /v2/parse, including trailing-dot hostnames. Other hosts retain /providers/cohere/v2/parse. Prefixes, query parameters, complete Parse URLs and trailing /models handling remain covered. The passthrough OCR route now also recognizes the dedicated v2/parse path, so those responses normalize and bill the same way as resource endpoint calls. The response format is unchanged.

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks
  • My PR only solves one specific problem
  • Every automated review on the latest commit has finished and its findings are addressed

Screenshots / Proof of Fix

E2E exception at 83a765544ccba57433909b86b99e4f7b5aa6e080. The dedicated-host regression is reproduced and fixed in the URL builder, and the focused Rust tests below trace the full URL construction for every host form this change touches. Real OCR succeeded through two existing configured development deployments, but that control does not establish a vanilla before-and-after request against a dedicated host. No dedicated endpoint or usable credentials are available in this environment, so the live dedicated-host run remains the one unverified item. No deployment was changed for this test.

Before (26807a9)

Apply only the tests from this PR to the base implementation and run the focused Rust command below. The regression run used 00313c9e5b33715e97fbaeaa2a32571be0876536. The production Rust file is byte-identical at the merge base shown above. Four dedicated-base cases fail and four controls pass. For example, the root dedicated host produces this URL.

actual   https://parse.eastus.models.ai.azure.com/providers/cohere/v2/parse?tenant=a
expected https://parse.eastus.models.ai.azure.com/v2/parse?tenant=a
4 failed, 4 passed

After (83a7655)

Run the same cases with the implementation change.

cd litellm/rust
cargo test -p litellm-llms --features test-support   azure_ai::ocr::cohere_parse_transformation::tests --lib
cargo fmt --all -- --check
cargo clippy -p litellm-llms --features test-support --lib -- -D warnings

All 11 cases pass, including dedicated inference.ai.azure.com hosts, a trailing-dot hostname and a one-label inference resource host keeping the provider path. The passthrough route cases pass too, including the dedicated v2/parse path. Formatting passes and make check passes at this tip. The tests fail on the unchanged implementation, so an already complete Parse URL cannot mask the regression.

Live OCR control

The following client was run against the existing configured development service using two Parse aliases. Set QA_PARSE_BASE_URL to a configured proxy, QA_PARSE_API_KEY to its inference key and QA_PARSE_MODELS_JSON to a JSON array of model aliases. The synthetic WEBP fixture contains no user document. Both calls returned HTTP 200 with one page and the fixture text.

Exact OCR client, run with python qa_parse_control.py
import base64
import io
import json
import os

import httpx
from PIL import Image, ImageDraw, ImageFont

fixture = Image.new("RGB", (900, 240), "white")
draw = ImageDraw.Draw(fixture)
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 34)
draw.text((30, 55), "Parse routing test", font=font, fill="black")
draw.text((30, 125), "Invoice 42. Total 100.", font=font, fill="black")
encoded = io.BytesIO()
fixture.save(encoded, format="WEBP")
image_url = "data:image/webp;base64," + base64.b64encode(encoded.getvalue()).decode()
results = []
with httpx.Client(timeout=httpx.Timeout(120, connect=30), trust_env=False, transport=httpx.HTTPTransport(retries=2)) as client:
    for model in json.loads(os.environ["QA_PARSE_MODELS_JSON"]):
        response = client.post(
            os.environ["QA_PARSE_BASE_URL"].rstrip("/") + "/ocr",
            headers={"Authorization": "Bearer " + os.environ["QA_PARSE_API_KEY"]},
            json={"model": model, "document": {"type": "image_url", "image_url": image_url}},
        )
        result = response.json()
        proof = {
            "status": response.status_code,
            "pages": len(result.get("pages", [])),
            "fixture_text_found": "parse routing test" in json.dumps(result).lower(),
        }
        print(json.dumps(proof), flush=True)
        results.append(proof)
        assert proof == {"status": 200, "pages": 1, "fixture_text_found": True}
{"status": 200, "pages": 1, "fixture_text_found": true}
{"status": 200, "pages": 1, "fixture_text_found": true}

For the remaining branch-specific live check, build the native bridge from each checkout, point a local proxy at a dedicated *.models.ai.azure.com deployment and send the same fixture before and after. Router and coordination Redis must share one dedicated instance, with two serving workers on both legs. That check is pending and is not replaced by the unit tests or development control above.

Type

Bug Fix

Caveats

Medium

  • Dedicated-host live before-and-after proof is still pending.

Low

  • Dedicated Parse URLs under a gateway path prefix stay as sent.

@emerzon
emerzon marked this pull request as ready for review November 15, 2026 12:34
@veria-ai

veria-ai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

…se calls

Dedicated Cohere Parse routing now also covers endpoint.region.inference.ai.azure.com hosts and trailing-dot hostnames, and the passthrough OCR route recognizes the dedicated v2/parse path so those pages are billed like resource endpoint calls.

@surlymochan surlymochan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full diff against #51910. The fix reads correctly to me:

  • Dedicated hosts (*.models.ai.azure.com and <endpoint>.<region>.inference.ai.azure.com) now route to /v2/parse, while resource hosts keep /providers/cohere/v2/parse; passthrough_response accepts both paths for AzureCohere.
  • The Rust tests cover the dedicated forms (root, /models, gateway prefix, /v2, complete) plus the trailing-dot host, the inference host form, and the negative cases (plain example.com, resource.inference.ai.azure.com, and the lookalike models.ai.azure.com.example.com).
  • The AGENTS.md note was updated to match the new routing rule.

Two questions (non-blocking, from a reader, not a maintainer):

  1. is_dedicated_host requires a dot in the segment before .inference.ai.azure.com, so a bare single-label host such as https://parse.inference.ai.azure.com would fall back to the resource path. Is that host form real, or is the dot requirement intentional?
  2. In the trailing-dot test the expected URL keeps the trailing dot in the host ({base}/v2/parse with base ending in .). Does Azure accept a trailing-dot host, or should the dot be stripped before building the URL?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Azure Cohere Parse uses the resource-style path for dedicated endpoints

2 participants