Skip to content

Conversation

@SannidhyaSah
Copy link
Collaborator

@SannidhyaSah SannidhyaSah commented Jun 28, 2025

Description

Fixes #5212

This PR resolves the 404 "Resource not found" error when using Azure OpenAI with the RooCode extension's "OpenAI Compatible" provider. The issue occurred because the OpenAI SDK automatically appends /embeddings to the base URL, which conflicts with Azure OpenAI's requirement for complete endpoint URLs that include the deployment name and API version.

Beyond Azure OpenAI, this enhancement provides broader compatibility with various OpenAI-compatible endpoints that require specific URL structures, making the provider more flexible and robust for diverse deployment scenarios.

Changes Made

  • Enhanced URL Detection: Added isFullEndpointUrl() method to detect when users provide complete endpoint URLs (containing /embeddings or /deployments/)
  • Direct HTTP Requests: Implemented makeDirectEmbeddingRequest() for bypassing the OpenAI SDK when full URLs are provided
  • Conditional Logic: Modified _embedBatchWithRetries() to use either the OpenAI SDK or direct fetch based on URL type
  • Universal Compatibility: Added support for both api-key and Authorization headers to ensure compatibility with various OpenAI-compatible services
  • Base64 Encoding: Used encoding_format: "base64" for consistent embedding handling across both paths

Broader Benefits

This solution enhances compatibility with various OpenAI-compatible endpoints beyond just Azure OpenAI:

  • Custom OpenAI Deployments: Services that require specific endpoint paths or query parameters
  • Proxy Services: OpenAI-compatible proxies that need complete URLs to route requests correctly
  • Enterprise Deployments: Internal OpenAI-compatible services with custom URL structures
  • Multi-tenant Services: Platforms that embed tenant/deployment information in the URL path
  • API Gateways: Services that require specific URL formats for routing and authentication
  • Local/Self-hosted Models: OpenAI-compatible local deployments with custom endpoint structures

The intelligent URL detection ensures that:

  • Standard OpenAI endpoints continue to work exactly as before (backward compatibility)
  • Full endpoint URLs bypass SDK URL manipulation, preserving query parameters and custom paths
  • Flexible authentication supports both api-key and Authorization header patterns
  • Consistent behavior across different deployment types through unified base64 encoding

Testing

  • All existing tests pass (39/39 tests passing)
  • Added comprehensive unit tests for new functionality:
    • URL detection logic for various endpoint formats
    • Direct HTTP request handling with proper headers
    • Azure OpenAI compatibility scenarios
    • Error handling and retry mechanisms
    • Multiple OpenAI-compatible endpoint patterns
  • Linting checks pass with no warnings
  • Type checking passes across all packages

Verification of Acceptance Criteria

  • Azure OpenAI Support: Users can now provide complete Azure OpenAI endpoint URLs including deployment names and API versions
  • Backward Compatibility: Existing OpenAI and OpenAI-compatible providers continue to work unchanged
  • Error Resolution: The 404 "Resource not found" error is resolved for Azure OpenAI configurations
  • Universal Headers: Both api-key and Authorization headers are included for broad compatibility
  • Enhanced Flexibility: Support for various OpenAI-compatible endpoint URL structures

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Comments added for complex logic
  • No breaking changes
  • Comprehensive test coverage added
  • All existing functionality preserved
  • Enhanced compatibility with multiple OpenAI-compatible services

Important

Fixes Azure OpenAI 404 error by supporting full endpoint URLs in OpenAICompatibleEmbedder, enhancing compatibility with various OpenAI-compatible services.

  • Behavior:
    • Fixes 404 error for Azure OpenAI by supporting full endpoint URLs in OpenAICompatibleEmbedder.
    • Adds isFullEndpointUrl() to detect full URLs and makeDirectEmbeddingRequest() to handle them.
    • Modifies _embedBatchWithRetries() to choose between SDK and direct requests based on URL type.
    • Supports both api-key and Authorization headers for broader compatibility.
    • Ensures consistent base64 encoding for embeddings.
  • Testing:
    • Adds unit tests in openai-compatible.spec.ts for URL detection, direct requests, and error handling.
    • Tests cover Azure OpenAI scenarios, rate limiting, and multiple endpoint patterns.

This description was created by Ellipsis for 49e775a. You can customize this summary. It will automatically update as commits are pushed.

@SannidhyaSah SannidhyaSah requested review from cte, jr and mrubens as code owners June 28, 2025 07:58
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working Enhancement New feature or request labels Jun 28, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jun 28, 2025
@SannidhyaSah
Copy link
Collaborator Author

SannidhyaSah commented Jun 28, 2025

i can confirm that this pr is working properly and fixes the issue originally mentioned in #5212
image

@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jun 28, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jun 28, 2025
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

Hey @SannidhyaSah I left a couple of suggestions that are worth taking a look at.

Let me know what you think.

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jun 30, 2025
- Add HttpError interface for better type safety
- Cache isFullEndpointUrl result for performance optimization
- Implement smart URL detection with regex patterns for known providers
- Add comprehensive tests for URL detection edge cases
- Add tests for URLs with 'embeddings' in non-endpoint contexts
- Add tests for URLs with 'deployments' in non-endpoint contexts
- Verify actual endpoint URLs are still correctly identified
- Addresses PR review feedback for better test coverage
@SannidhyaSah
Copy link
Collaborator Author

@daniel-lxs I've made the changes mentioned in the review.

@daniel-lxs daniel-lxs moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap Jul 1, 2025
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

Thank you @SannidhyaSah!

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 1, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Jul 1, 2025
@mrubens mrubens merged commit 37619d7 into RooCodeInc:main Jul 3, 2025
10 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 3, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Jul 3, 2025
@SannidhyaSah SannidhyaSah deleted the fix/issue-5212-azure-openai-compatibility branch July 12, 2025 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Enhancement New feature or request lgtm This PR has been approved by a maintainer PR - Needs Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Codebase Indexing with Azure OpenAI: API version missing

4 participants