Skip to content

[Feature][Java] Add OpenAI Responses API integration#556

Open
addu390 wants to merge 6 commits intoapache:mainfrom
addu390:feature/openai-response-api
Open

[Feature][Java] Add OpenAI Responses API integration#556
addu390 wants to merge 6 commits intoapache:mainfrom
addu390:feature/openai-response-api

Conversation

@addu390
Copy link

@addu390 addu390 commented Feb 28, 2026

Linked issue: #132

Purpose of change

Adds support for OpenAI's Responses API as a new chat model integration alongside the existing Chat Completions integration.

The Responses API is OpenAI's recommended API. This initial implementation covers just the core functionality, similar to the existing Chat Completions integration.

The Setup class shares several parameters with OpenAIChatModelSetup. A shared base class could reduce duplication, happy to refactor in a follow-up if that's preferred.

Tests

Verified via the existing ChatModelIntegrationTest e2e integration test with a new OPENAI_RESPONSES parameterized variant. All tests pass.

API

Yes, adds two new public classes (OpenAIResponseModelConnection, OpenAIResponseModelSetup) and two new resource name constants. No changes to existing public APIs (intentionally left it as-is).

Documentation

  • doc-needed
  • doc-not-needed
  • doc-included

@github-actions github-actions bot added priority/major Default priority of the PR or issue. fixVersion/0.3.0 The feature or bug should be implemented/fixed in the 0.3.0 version. doc-needed Your PR changes impact docs. labels Feb 28, 2026
@addu390 addu390 changed the title Add OpenAI Responses API integration [Java] [Feature][Java] Add OpenAI Responses API integration Feb 28, 2026
Copy link
Collaborator

@wenjin272 wenjin272 left a comment

Choose a reason for hiding this comment

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

Hi, @addu390, thanks for your contribution, LGTM. Just some minor comments. Please take a look at your convenience @xintongsong.

I noticed that you explained the additional capabilities of the Response API compared to the Chat Completions API in your comments; however, these capabilities seems do not appear to be reflected in the current implementation. To demonstrate these capabilities, we may need to extend the existing APIs, which could require a significant amount of work. Therefore, I think we can wait until there are actual user requirements before proceeding.


private final ObjectMapper mapper = new ObjectMapper();
private final OpenAIClient client;
private final String defaultModel;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This field maybe not needed. The OpenAIResponseModelSetup will always pass a model name when calling chat.

Copy link
Author

Choose a reason for hiding this comment

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

True. Was following an existing pattern, as seen in AnthropicChatModelConnection and OpenAIChatModelConnection.

It could be useful, if the intention was to choose the default at connection and not set-up.


private static final TypeReference<Map<String, Object>> MAP_TYPE = new TypeReference<>() {};

private final ObjectMapper mapper = new ObjectMapper();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Because ObjectMapper is thread safe, this could be a static field.

@addu390
Copy link
Author

addu390 commented Mar 4, 2026

I noticed that you explained the additional capabilities of the Response API compared to the Chat Completions API in your comments; however, these capabilities seems do not appear to be reflected in the current implementation. To demonstrate these capabilities, we may need to extend the existing APIs, which could require a significant amount of work. Therefore, I think we can wait until there are actual user requirements before proceeding.

@wenjin272 Agreed, I removed the comment, the PR already does not cover any new capabilities of responses API.

return ResourceDescriptor.Builder.newBuilder(ResourceName.ChatModel.OPENAI_CONNECTION)
.addInitialArgument("api_key", apiKey)
.build();
} else if (provider.equals("OPENAI_RESPONSE")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
} else if (provider.equals("OPENAI_RESPONSE")) {
} else if (provider.equals("OPENAI_RESPONSES")) {

"org.apache.flink.agents.integrations.chatmodels.openai.OpenAIResponseModelConnection";
public static final String OPENAI_RESPONSE_SETUP =
"org.apache.flink.agents.integrations.chatmodels.openai.OpenAIResponseModelSetup";

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. According to the documents, the formal name of the API is "Responses API". Let's make it consistent and use RESPONSES (rather than RESPONSE) for the constants and class names.

  2. I'd suggest to also change OPENAI_CONNECTION to OPENAI_COMPLETIONS_CONNECTION, as well as the class names, to avoid confusion.

  3. There are some string constants for referencing java integrations from python codes in resource.py, which should also be updated.

Copy link
Author

@addu390 addu390 Mar 5, 2026

Choose a reason for hiding this comment

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

Missed those in resource.py, I made the changes to fix naming across the code-base.

Should we also rename OpenAIChatModelConnection to OpenAICompletionsConnection, OpenAIChatModelSetup to OpenAICompletionsSetup for consistency in naming?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we also rename OpenAIChatModelConnection to OpenAICompletionsConnection, OpenAIChatModelSetup to OpenAICompletionsSetup for consistency in naming?

Yes, I think we should also change the class names to avoid confusion, as well as the resource.py.

Copy link
Author

Choose a reason for hiding this comment

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

I think so too! Updated the class names and the references.

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

Labels

doc-needed Your PR changes impact docs. fixVersion/0.3.0 The feature or bug should be implemented/fixed in the 0.3.0 version. priority/major Default priority of the PR or issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants