Class OpenAiResponsesProvider

All Implemented Interfaces:
PropertyChangeSource, Rebindable

public class OpenAiResponsesProvider extends AbstractAiProvider
Clean-room provider for OpenAI, strictly utilizing the modern Responses API (/v1/responses).

This provider is designed for native agentic workflows, supporting built-in tools and stateful item-based history. It handles model discovery and API key management for the OpenAI platform.

Author:
anahata
  • Field Details

    • API_MAPPER

      private static final com.fasterxml.jackson.databind.ObjectMapper API_MAPPER
      Internal Jackson mapper for OpenAI API JSON processing.
    • verifiedOrganization

      private boolean verifiedOrganization
      Flag indicating if the configured API key belongs to a verified OpenAI organization.

      Verified organizations are permitted to use store: true and receive plain-text reasoning summaries in their responses without throwing a 400 parameter error on subsequent turns.

    • httpClient

      private transient HttpClient httpClient
      The HTTP client used for all communication with the OpenAI API.

      Marked as transient to prevent serialization of the networking stack.

  • Constructor Details

    • OpenAiResponsesProvider

      public OpenAiResponsesProvider()
      Constructs a new OpenAiProvider with the 'OpenAI' UUID and standard tokenizer settings.
    • OpenAiResponsesProvider

      public OpenAiResponsesProvider(String uuid)
      Constructs a new OpenAiProvider with a custom UUID.
      Parameters:
      uuid - the unique provider identifier.
  • Method Details

    • getHttpClient

      public HttpClient getHttpClient()
      Lazy-initializes and returns the HTTP client for this provider.

      Ensures standard timeouts and redirect policies are applied.

      Returns:
      The active HTTP client.
    • createRequestBuilder

      public HttpRequest.Builder createRequestBuilder(String endpoint)
      Creates an authorized HTTP Request Builder for the specified endpoint.
      Parameters:
      endpoint - the target sub-resource endpoint (e.g. "responses").
      Returns:
      a pre-configured, authorized HttpRequest Builder.
    • listModels

      public List<? extends AbstractModel> listModels()
      Fetches the list of all models available from the provider's remote API.

      Implementation details: Executes a GET request to the /models endpoint of the configured getBaseUrl(). Discovered models are filtered to include only those supported by the Responses API (gpt-4o and successor generations).

      Specified by:
      listModels in class AbstractAiProvider
      Returns:
      A list of provider-specific AbstractModel objects.
    • isRetryable

      public boolean isRetryable(int statusCode, String responseBody)
      Determines if an HTTP status code or response body indicates a transient failure that should trigger a retry or rotation.
      Parameters:
      statusCode - The HTTP status code returned by the server.
      responseBody - The raw response body string.
      Returns:
      true if the request can be retried, false otherwise.
    • getApiKeyHint

      public String getApiKeyHint()
      Gets a template or hint string to display when the API keys file is empty.

      Provides a template for the OpenAI api_keys.txt file.

      Specified by:
      getApiKeyHint in class AbstractAiProvider
      Returns:
      The API key hint text.