- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.4k
feat: Add support for Responses API in OpenAI Compatible Provider while keeping the Chat Completions compatibility (with Azure Portal style base url support) #7355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! I've reviewed the changes and this is a solid implementation of Responses API support. The auto-detection logic is clever and the backward compatibility is well maintained. I have some suggestions for improvement, particularly around streaming support and type safety.
        
          
                src/api/providers/openai.ts
              
                Outdated
          
        
      | payload.max_output_tokens = this.options.modelMaxTokens || modelInfo.maxTokens | ||
| } | ||
|  | ||
| // NOTE: Streaming for Responses API isn't covered by current tests. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment indicates streaming isn't covered by tests and defaults to non-streaming. Since streaming is a critical feature for user experience, could we consider implementing streaming support for the Responses API? If not feasible now, should we at least document this limitation more prominently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented the streaming based on the openai-native provider code.
        
          
                src/api/providers/openai.ts
              
                Outdated
          
        
      | // NOTE: Streaming for Responses API isn't covered by current tests. | ||
| // We call non-streaming for now to preserve stable behavior. | ||
| try { | ||
| const response: any = await (this.client as any).responses.create(payload) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional that we're casting to any here? The OpenAI client might not have a responses property. Should we add validation or a more graceful fallback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed casting to any as much as I can.
| } | ||
| } | ||
|  | ||
| private _toResponsesInput(anthropicMessages: Anthropic.Messages.MessageParam[]): Array<{ | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper method _toResponsesInput appears to be unused. Is this intentional or leftover from development? If it's for future use, could we add a comment explaining its purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed to use it, allowing the image input with responses API.
| this._isAzureOpenAiResponses(baseURL) | ||
|  | ||
| // Always use 'preview' for Azure Responses API calls (per user requirement) | ||
| const azureVersion = isResponsesFlavor | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API version is hardcoded to "preview" for Azure Responses. Could this break when Azure releases a stable version? Should we make this configurable or at least add a comment explaining why "preview" is always used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As of now, only preview version is available and I cannot do anything for it.
        
          
                src/api/providers/openai.ts
              
                Outdated
          
        
      |  | ||
| // Verbosity: include via text.verbosity (Responses API expectation per openai-native handler) | ||
| if (this.options.verbosity || verbosity) { | ||
| ;(payload as any).text = { verbosity: this.options.verbosity || verbosity } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple uses of as any bypass TypeScript's type checking. Could we define proper types for the Responses API to improve type safety?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed casting to any as much as I can.
|  | ||
| // --- Responses helpers --- | ||
|  | ||
| private _resolveApiFlavor(baseUrl: string): "responses" | "chat" { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The auto-detection logic is clever but not immediately obvious. Could we add JSDoc comments explaining the URL pattern matching?
|  | ||
| // -- Added Responses API tests (TDD) -- | ||
|  | ||
| describe("OpenAI Compatible - Responses API", () => { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great test coverage for the Responses API! Consider adding a test for streaming support once it's implemented. Also, it might be helpful to test the error case when the OpenAI client doesn't support the Responses API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests for streaming support.
| I found my implementation is not working with requests with Images. | 
… handling; tests
- Add previous_response_id retry path on 400 “Previous response … not found”
  - Non-streaming and streaming: drop previous_response_id and retry once; clear continuity state
  - Code: [src/api/providers/openai.ts](src/api/providers/openai.ts:238), [src/api/providers/openai.ts](src/api/providers/openai.ts:291), guard [OpenAiHandler._isPreviousResponseNotFoundError()](src/api/providers/openai.ts:934)
- Support GPT‑5-style reasoning summary and minimal effort on Responses API
  - Default enable summary: "auto" unless explicitly disabled in settings
  - Include reasoning: { effort: "minimal" | "low" | "medium" | "high", summary?: "auto" }
  - Code: constructor default [OpenAiHandler](src/api/providers/openai.ts:38), payload assembly [createMessage](src/api/providers/openai.ts:193)
- Improve Responses streaming event coverage
  - Handle response.content_part.added (emit text)
  - Handle response.audio_transcript.delta (emit text as transcript)
  - Preserve response.id via stream callback for continuity
  - Code: [handleResponsesStream](src/api/transform/responses-stream.ts:91), [src/api/transform/responses-stream.ts](src/api/transform/responses-stream.ts:47), responseId callback [src/api/transform/responses-stream.ts](src/api/transform/responses-stream.ts:19) and usage in [openai.ts](src/api/providers/openai.ts:283)
- Maintain conversation continuity for Responses API
  - Store lastResponseId on both streaming and non-streaming paths; pass previous_response_id unless suppressed
  - Code: stream wiring [src/api/providers/openai.ts](src/api/providers/openai.ts:283), non-streaming capture [src/api/providers/openai.ts](src/api/providers/openai.ts:889)
- Update and extend tests
  - Add tests for 400 previous_response_id retry (streaming and non-streaming)
  - Add tests for content_part and audio_transcript events
  - Add tests for reasoning minimal + summary auto, and summary disabling
  - Adjust expectation to allow summary in reasoning payload
  - Tests: [src/api/providers/__tests__/openai.spec.ts](src/api/providers/__tests__/openai.spec.ts:1663), [src/api/providers/__tests__/openai.spec.ts](src/api/providers/__tests__/openai.spec.ts:1170)
- Minor: default enableGpt5ReasoningSummary to true in compatible provider for Responses flows
    | Now I have fixed the problems. I think we need to refactor to unify the implementation of the  | 
        
          
                src/package.json
              
                Outdated
          
        
      | "node-ipc": "^12.0.0", | ||
| "ollama": "^0.5.17", | ||
| "openai": "^5.0.0", | ||
| "openai": "^5.15.0", | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updaetd to "openai": "^5.15.0" because verbosity parameter is added for Responses API request.
c2aebf9    to
    cd51254      
    Compare
  
    | Thanks for the implementation! The Responses API support is working well, but before merging I think there are a few areas that could use some cleanup. One thing I noticed is the error retry logic – the checks for  Another area is type safety. There’s a lot of  Lastly,  The functionality itself looks solid, I just think a bit of refactoring here would make the implementation easier to maintain in the long run. | 
…reateWithRetries; dedupe checks for previous_response_id, verbosity, and Azure input_text invalid in streaming and non-streaming paths
…ible-responses-api
…atible-responses-api # Conflicts: # pnpm-lock.yaml # src/api/providers/openai.ts # src/package.json
…gate from createMessage - Move Responses API logic to private _handleResponsesFlavor - Preserve streaming, retries, conversation continuity, reasoning/verbosity, and usage - All existing tests pass
| @daniel-lxs Thank you for your feedback, and sorry for late reply. 
 Please take another look and let me know if you want any further changes. | 
…nuity (previous_response_id/store), temp/verbosity gating, and image support (input_image/output_text)
…nscript for text-only, array for multimodal; retry-on-verbosity; continuity handling
Feature/integrate OpenAI recent update
…am fails before id (store: true default)
| I found conversation history in the session lost after retrying, so integrated upstream (openai-native.ts) changes from #7067. | 
| Is there any chance to get this merged soonish? I have been using my own build based on the PR and it works fine for me. | 
| I'm not too sure about this PR. It would be best to have 2 clear paths in the code when the Responses API is enabled or disabled. Maybe we can base it on the OpenAI native provider, which was migrated to the Responses API recently. The idea would be to have a checkbox to enable the Responses API in the provider, in which case the path with the Response API logic would be used. I'm closing this PR for now. I'll try to scope the issue. Feel free to continue the discussion. | 
| Thank you for the review and discussion. I also felt this implementation became more complex than necessary. I think we should: 
 This should reduce duplication and make the codebase more maintainable in future. Note: For those urgently need responses API with Azure OpenAI implementation now, you can clone, install and build this branch with  | 

Related GitHub Issue
Closes: #6862
Roo Code Task Context (Optional)
N/A
Description
This PR adds full Responses API support to the OpenAI Compatible provider while preserving all existing Chat Completions behavior. It addresses the “400 Unsupported parameter: 'messages'” error when users target the Responses endpoints (Azure and OpenAI) by building the correct payload and selecting the appropriate endpoint automatically.
Note that the manual toggle of the API style (
autoor override withresponsesorchat completions) from settings was discussed in the original issue #6862 and I once implemented it, but I do not think that feature is required and removed. (Settings UI should be kept clean)Key technical points:
Files Modified
Test Procedure
Unit Tests (Vitest)
Pre-Submission Checklist
400 Unsupported parameter: 'messages'.error on OpenAI Compatible Azure deployment of GPT-5 #6862Screenshots / Videos
N/A (provider change; unit tests cover logic)
Documentation Updates
N/A
Additional Notes
Get in Touch
Discord: lagyu
Important
Adds Responses API support to OpenAI Compatible Provider with automatic endpoint selection and Azure-specific configurations.
OpenAiHandler, auto-selecting endpoint based on URL path.apiVersiontopreview._resolveApiFlavor(),_formatResponsesInput(),_normalizeAzureResponsesBaseUrlAndVersion()added toopenai.tsfor API selection and payload formatting._yieldResponsesResult()and_extractResponsesText()handle Responses API output.openai.spec.tsto test Responses API support, including URL normalization and payload verification.This description was created by for f05544b. You can customize this summary. It will automatically update as commits are pushed.
 for f05544b. You can customize this summary. It will automatically update as commits are pushed.