Skip to content

fix: route Azure codex models to Responses API in OpenAI Compatible handler#11952

Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/azure-codex-responses-api
Draft

fix: route Azure codex models to Responses API in OpenAI Compatible handler#11952
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/azure-codex-responses-api

Conversation

@roomote-v0
Copy link
Contributor

@roomote-v0 roomote-v0 bot commented Mar 18, 2026

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 uses client.chat.completions.create() for all API calls. Azure-hosted GPT-5.x codex models (like gpt-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:

  • Added _isCodexModel() helper method for case-insensitive codex model detection
  • Added handleCodexMessage() that uses responses.create() with full streaming event processing (text deltas, reasoning, tool calls, usage tracking)
  • Added _formatConversationForResponsesApi() to convert Anthropic message format to the Responses API input format (input_text, output_text, function_call, function_call_output)
  • Added _convertToolsForResponsesApi() to convert tools from Chat Completions nested format to Responses API flat format
  • Updated completePrompt() to also use Responses API for codex models
  • The pattern follows the existing handleO3FamilyMessage() routing pattern in the same handler

Test Procedure

  • Added 13 new tests in openai-codex-responses.spec.ts covering:
    • Codex model detection (positive and negative cases, case-insensitive)
    • Routing: codex models use responses.create(), non-codex models use chat.completions.create()
    • Conversation formatting with tool use (function_call/function_call_output)
    • Tool call streaming (partial and complete tool calls)
    • completePrompt() routing for both codex and non-codex models
    • Error handling (API errors and stream error events)
  • Verified all 48 existing openai.spec.ts tests still pass

Run tests:

cd src && npx vitest run api/providers/__tests__/openai-codex-responses.spec.ts
cd src && npx vitest run api/providers/__tests__/openai.spec.ts

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: No documentation updates are required.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

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., handleO3FamilyMessage for o1/o3/o4 models) and in OpenAiNativeHandler which already uses the Responses API for all models.

Interactively review PR in Roo Code Cloud

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
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 gpt-5.3-codex not working

1 participant