Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 20, 2025

Plan: Fix Azure OpenAI Endpoint Double /v1 Issue

  • Explore repository structure and locate AI-related code
  • Identify the issue: Azure OpenAI base URL handling
  • Fix the selectAIProvider function to properly handle Azure OpenAI base URLs
  • Fix the getModels endpoint to properly handle Azure OpenAI URLs
  • Update getProviderHeaders to use correct Azure OpenAI authentication
  • Add tests for Azure OpenAI URL normalization
  • Refactor duplicated URL normalization logic into shared utility function
  • Address code review feedback (improved regex, removed API key validation duplication)
  • Run security checks and fix vulnerabilities
  • Add edge case test for partial path segment matching
  • Resolve merge conflicts with canary branch (integrated Perplexity AI provider changes)
  • All changes complete and verified ✅

Root Cause

The issue is that when users provide Azure OpenAI URLs like https://workspacename.openai.azure.com/openai/v1, the createAzure SDK function appends its own path, resulting in double /v1 in the final URL: https://workspacename.openai.azure.com/openai/v1/v1/chat/completions.

Changes Made

  1. selectAIProvider: Strip trailing /openai/v1 and /v1 from Azure base URLs before passing to createAzure
  2. getModels: Handle Azure deployments endpoint separately with proper URL cleanup and consolidated API key validation
  3. getProviderHeaders: Use correct api-key header for Azure OpenAI authentication with secure hostname validation
  4. Tests: Added 9 comprehensive tests to verify Azure URL normalization logic including edge cases
  5. Refactoring:
    • Extracted URL normalization logic to normalizeAzureUrl() utility function
    • Improved regex to handle all URL variations in one pass
    • Consolidated API key validation to eliminate duplication
  6. Security:
    • Fixed URL substring sanitization vulnerabilities by using proper hostname parsing
    • Replaced substring checks with exact hostname matching for Azure domains
    • All CodeQL security checks pass with 0 alerts
  7. Conflict Resolution:
    • Rebased onto canary branch
    • Integrated new Perplexity AI provider support from canary
    • Both Azure and Perplexity cases now work together

Testing & Validation

  • ✅ All 9 unit tests pass (including edge cases for partial path segments)
  • ✅ Linting and formatting checks pass
  • ✅ CodeQL security scan passes with 0 vulnerabilities
  • ✅ Rebased successfully onto latest canary branch
  • ✅ Code review feedback addressed
Original prompt

This section details on the original issue you should resolve

<issue_title>Azure OpenAI Endpoint not working</issue_title>
<issue_description>### To Reproduce

  1. Added model in AI Settings (https://workspacename.openai.azure.com/openai/v1) - URL/API Key combination was working in the settings tab as it showed the list of models to choose from.

  2. Tried using the AI Assisted service creation and got this error: Resource not found. Web console showed:
    "message": "Resource not found", "code": -32600, "data": { "code": "BAD_REQUEST", "httpStatus": 400, "path": "ai.suggest", "zodError": null

  3. Server error logs show that the API endpoint is being called with another /v1 suffix at the end of the URL:

Error in suggestVariants: Error [AI_APICallError]: Resource not found at ignore-listed frames { cause: undefined, url: 'https://workspacename.openai.azure.com/openai/v1//v1/chat/completions?api-version=preview',

  1. Tried modifying the URL structure in the AI Settings to exclude '/v1' however that was not accepted by the application (Got the same resource not found error when trying to save the config).

Current vs. Expected behavior

Unable to use Azure models via the OpenAI compatible endpoints for ai assisted service creation.

Provide environment information

OS: Linux (ubuntu 22.04) Dokploy Version: v0.26.2 Application Feature: Create Service > AI Assistant

Which area(s) are affected? (Select all that apply)

Application

Are you deploying the applications where Dokploy is installed or on a remote server?

Same server where Dokploy is installed

Additional context

Proxy Setup: Application server deployed behind reverse proxy (Pangolin) - Other apps are working fine though so I assume it's to do with the URL request structure rather than this, but including just in case.

Will you send a PR to fix it?

Yes</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 6 commits December 20, 2025 06:43
Co-authored-by: Siumauricio <47042324+Siumauricio@users.noreply.github.com>
Co-authored-by: Siumauricio <47042324+Siumauricio@users.noreply.github.com>
Co-authored-by: Siumauricio <47042324+Siumauricio@users.noreply.github.com>
…plication Co-authored-by: Siumauricio <47042324+Siumauricio@users.noreply.github.com>
… attacks Co-authored-by: Siumauricio <47042324+Siumauricio@users.noreply.github.com>
Co-authored-by: Siumauricio <47042324+Siumauricio@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Azure OpenAI endpoint not working issue Fix Azure OpenAI endpoint double /v1 path issue Dec 20, 2025
Copilot AI requested a review from Siumauricio December 20, 2025 06:57
@Siumauricio Siumauricio marked this pull request as ready for review December 20, 2025 19:28
@Siumauricio
Copy link
Contributor

@copilot resolve the conflicts

Copy link
Contributor Author

Copilot AI commented Dec 20, 2025

@copilot resolve the conflicts

Conflicts resolved! The branch has been rebased onto the latest canary branch. The Azure OpenAI endpoint fix now works alongside the new Perplexity AI provider support. All tests pass (9/9) and the code is ready for review.

Note: The branch history has been rewritten due to the rebase. The changes remain the same but are now based on the latest canary commit (6772575).

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

Labels

None yet

2 participants