Skip to content

fix(azure): Strip operation suffixes from deployment URLs to prevent 404 errors - #70

Merged
josemaria-vilaplana merged 1 commit into
carto/mainfrom
fix/azure-chat-completions-url-sanitization
Jan 26, 2026
Merged

fix(azure): Strip operation suffixes from deployment URLs to prevent 404 errors#70
josemaria-vilaplana merged 1 commit into
carto/mainfrom
fix/azure-chat-completions-url-sanitization

Conversation

@josemaria-vilaplana

@josemaria-vilaplana josemaria-vilaplana commented Jan 21, 2026

Copy link
Copy Markdown

Title

fix(azure): Strip operation suffixes from deployment URLs to prevent 404 errors

Summary

When api_base is configured with full deployment paths like:

https://ai-azure-product-dev.openai.azure.com/openai/deployments/gpt-4o/chat/completions

The Azure SDK appends the operation path again, resulting in duplicate paths:

https://ai-azure-product-dev.openai.azure.com/openai/deployments/gpt-4o/chat/completions/chat/completions

This causes 404 errors from Azure.

Solution

This fix updates select_azure_base_url_or_endpoint in litellm/llms/azure/common_utils.py to strip operation suffixes before passing the URL to the Azure SDK:

  • /chat/completions
  • /completions
  • /embeddings
  • /audio/speech
  • /audio/transcriptions
  • /images/generations

This is the counterpart to PR #61 which fixed the same issue for the Responses API.

Relevant issues

Counterpart to #61 (Azure Responses API URL fix)

Pre-Submission checklist

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix

Changes

  • litellm/llms/azure/common_utils.py: Updated select_azure_base_url_or_endpoint to strip operation-specific suffixes from deployment URLs
  • tests/test_litellm/llms/azure/test_azure_common_utils.py: Added 12 unit tests for URL sanitization

Test plan

  • Unit tests for all supported operation suffixes
  • Unit tests for edge cases (trailing slashes, no deployment path, None values)
  • Docker image built successfully (litellm-azure-url-fix)

🤖 Generated with Claude Code

…404 errors

When api_base is configured with full deployment paths like
.../openai/deployments/gpt-4o/chat/completions, the Azure SDK appends
the operation path again, resulting in duplicate paths and 404 errors.

This fix updates select_azure_base_url_or_endpoint to strip operation
suffixes (/chat/completions, /completions, /embeddings, /audio/speech,
/audio/transcriptions, /images/generations) before passing the URL
to the Azure SDK.

This is the counterpart to PR #61 which fixed the same issue for the
Responses API.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@josemaria-vilaplana josemaria-vilaplana changed the title fix(azure): Strip operation suffixes from deployment URLs to prevent … fix(azure): Strip operation suffixes from deployment URLs to prevent 404 errors Jan 21, 2026
@josemaria-vilaplana
josemaria-vilaplana merged commit 8eee06f into carto/main Jan 26, 2026
5 of 6 checks passed
@josemaria-vilaplana
josemaria-vilaplana deleted the fix/azure-chat-completions-url-sanitization branch January 26, 2026 08:42
mateo-di added a commit that referenced this pull request Jan 29, 2026
…ution

Replace simple PR listing with intelligent context building:

- Fetch ALL merged PRs to carto/main (up to 1000, no arbitrary limit)
- For each CARTO-modified conflicted file, show:
  - Which PRs modified it
  - PR title (what the change does)
  - Author and lines changed (+/-)
  - Summary from PR description (first 150 chars)
- Provide full PR reference table sorted by recency

Example context for Claude:
```
### `litellm/llms/azure/chat/gpt_transformation.py`
**2 CARTO PR(s) modified this file:**
  - PR #70: fix(azure): Strip operation suffixes from deployment URLs
    Author: @josemaria-vilaplana | +189/-1 lines
  - PR #61: fix: Azure Responses API URL construction
    Author: @josemaria-vilaplana | +77/-3 lines
```

This gives Claude full understanding of WHY each file was modified,
enabling smarter conflict resolution decisions.
mateo-di added a commit that referenced this pull request Jan 29, 2026
* feat: Implement CARTO-First resolution strategy for upstream syncs

Add CARTO-FIRST conflict resolution priority that mandates preserving
CARTO customizations made by CartoDB org members during upstream syncs.

Key changes:
- Resolver: Add pre-analysis step to identify CARTO-modified files
- Resolver: Update prompt with CARTO-FIRST priority table (6 priorities)
- Resolver: Add known CARTO customizations list (Azure, Snowflake, etc.)
- CI Fixer: Add FORBIDDEN ACTIONS (never revert CARTO code)
- CI Fixer: Add REQUIRED ACTIONS (fix tests, not CARTO code)
- Docs: Update CARTO_CLAUDE.md with new resolution priorities

The key insight is using `git log` to identify files with commits from
@carto.com or @cartodb.com authors, then prioritizing those files.

[sc-XXXXX]

* fix: Use GitHub org membership check instead of email domains

Update CARTO file detection to use GitHub API org membership check,
matching the approach in calculate_carto_version.sh (PR #72).

Changes:
- Resolver: Fetch CartoDB org members via `gh api orgs/CartoDB/members`
- Resolver: Check commit authors against org member list
- CI Fixer: Update docs to reference "CartoDB GitHub org members"
- Docs: Update CARTO_CLAUDE.md with org membership reference

This is more reliable than email domain matching because:
- GitHub usernames are authoritative
- Works for users with non-CARTO emails
- Consistent with version calculator logic

* feat: Build rich CARTO context from ALL merged PRs for conflict resolution

Replace simple PR listing with intelligent context building:

- Fetch ALL merged PRs to carto/main (up to 1000, no arbitrary limit)
- For each CARTO-modified conflicted file, show:
  - Which PRs modified it
  - PR title (what the change does)
  - Author and lines changed (+/-)
  - Summary from PR description (first 150 chars)
- Provide full PR reference table sorted by recency

Example context for Claude:
```
### `litellm/llms/azure/chat/gpt_transformation.py`
**2 CARTO PR(s) modified this file:**
  - PR #70: fix(azure): Strip operation suffixes from deployment URLs
    Author: @josemaria-vilaplana | +189/-1 lines
  - PR #61: fix: Azure Responses API URL construction
    Author: @josemaria-vilaplana | +77/-3 lines
```

This gives Claude full understanding of WHY each file was modified,
enabling smarter conflict resolution decisions.
mateo-di added a commit that referenced this pull request Feb 4, 2026
…text

Simplifies the resolver for a purer goal-driven approach:

- Remove CARTO-MODIFIED vs UPSTREAM-ONLY classification
- Keep only PR feature summaries and file-to-PR mapping
- Claude decides per-file based on context, not rigid labels
- Replace complex verification steps with simple sanity check
- Reduce workflow from 1284 to 1078 lines

Philosophy: "This file was touched by PR #70 (Azure fix). You decide."
Instead of: "This file is CARTO-MODIFIED, keep it."
Cartofante pushed a commit that referenced this pull request Feb 4, 2026
Features restored:
- [PR #70] Azure URL suffix stripping - Strip operation suffixes
  (/chat/completions, /embeddings, etc.) from deployment URLs to
  prevent 404 errors when Azure SDK appends them again
- [PR #54] JSON repair for streaming tool calls - Use JSONDecoder.raw_decode()
  to handle malformed JSON from Gemini streaming that sends
  duplicate/overlapping chunks

Integration approach:
- PR #70: Restored regex-based stripping in select_azure_base_url_or_endpoint()
  with docstring explaining the fix. Added 12 unit tests.
- PR #54: Restored _validate_and_repair_tool_arguments() function and integrated
  it into get_combined_tool_content() and get_combined_function_call_content().
  Added 19 unit tests.

Verified: syntax checks, ruff linting passed

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
mateo-di added a commit that referenced this pull request Feb 10, 2026
Static registry of critical CARTO customizations that must survive
upstream syncs. The resolver should verify all patterns exist after
every sync to prevent silent feature regressions (like the OCI Gemini
and Snowflake tool calling drops in v1.81.0).

Tracks: OCI Gemini (#68), Snowflake streaming/tool calling (#38, #58),
Azure URL stripping (#70), JSON repair (#54), Redis sessions (#16).
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.

2 participants