fix: route Azure codex models to Responses API in OpenAI Compatible handler#11952
Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
Draft
fix: route Azure codex models to Responses API in OpenAI Compatible handler#11952roomote-v0[bot] wants to merge 1 commit intomainfrom
roomote-v0[bot] wants to merge 1 commit intomainfrom
Conversation
Azure-hosted GPT-5.x codex models (e.g., gpt-5.3-codex) do not support the Chat Completions API and return a 400 error. This change detects codex models by checking if the model ID contains "codex" and routes them through the OpenAI Responses API (responses.create) instead of chat.completions.create. Changes: - Add _isCodexModel() helper to detect codex model IDs - Add handleCodexMessage() that uses the Responses API with full streaming event processing (text, reasoning, tool calls, usage) - Add _formatConversationForResponsesApi() to convert Anthropic message format to Responses API input format - Add _convertToolsForResponsesApi() to convert tools from Chat Completions nested format to Responses API flat format - Update completePrompt() to also use Responses API for codex models - Add comprehensive tests for all new code paths Fixes #11951
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #11951
Description
This PR attempts to address Issue #11951. Feedback and guidance are welcome.
Root Cause: The
OpenAiHandler(used by the "OpenAI Compatible" provider) exclusively usesclient.chat.completions.create()for all API calls. Azure-hosted GPT-5.x codex models (likegpt-5.3-codex) do not support the Chat Completions API -- they only support the Responses API. This causes the 400 error: "The chatCompletion operation does not work with the specified model."Fix: When a codex model is detected (model ID contains "codex"), the handler now routes requests through the OpenAI Responses API (
responses.create()) instead of the Chat Completions API.Key implementation details:
_isCodexModel()helper method for case-insensitive codex model detectionhandleCodexMessage()that usesresponses.create()with full streaming event processing (text deltas, reasoning, tool calls, usage tracking)_formatConversationForResponsesApi()to convert Anthropic message format to the Responses API input format (input_text, output_text, function_call, function_call_output)_convertToolsForResponsesApi()to convert tools from Chat Completions nested format to Responses API flat formatcompletePrompt()to also use Responses API for codex modelshandleO3FamilyMessage()routing pattern in the same handlerTest Procedure
openai-codex-responses.spec.tscovering:responses.create(), non-codex models usechat.completions.create()completePrompt()routing for both codex and non-codex modelsopenai.spec.tstests still passRun tests:
Pre-Submission Checklist
Documentation Updates
Additional Notes
This fix only affects codex model requests while preserving existing behavior for all other models. It mirrors patterns already established in the same handler (e.g.,
handleO3FamilyMessagefor o1/o3/o4 models) and inOpenAiNativeHandlerwhich already uses the Responses API for all models.Interactively review PR in Roo Code Cloud