OpenAIWebClient

OpenAIWebClient class

Build-in lightweight OpenAI web client

OpenAIWebClient

NameDescription
OpenAIWebClient(String, String, String)Creates instance of OpenAI Web client.

Parameters:

NameTypeDescription
modelStringOpenAI language model (gpt-4o, gpt-4o-mini, etc.)
apiKeyStringOpenAI API key
organizationIdStringOrganization ID (optional)

Returns: OpenAIWebClient

Error

ErrorCondition
IllegalArgumentExceptionif API key or model are null/empty

OpenAIWebClient

NameDescription
OpenAIWebClient(String, String, String, HttpURLConnection)

Returns: OpenAIWebClient


callChat

NameDescription
callChat (String)Sends a chat instruction to the AI model using an externally managed instance and returns response message to the given instruction.

Parameters:

NameTypeDescription
instructionStringThe instruction or message to be processed by the AI model

Returns: String

Error

ErrorCondition
com.aspose.ms.System.OperationCanceledExceptionIf the current thread was interrupted while waiting.

close

NameDescription
close ()

createConversation

NameDescription
createConversation ()Creates a conversation instance. Unlike regular AI calls, conversations retain the entire context.

Returns: OpenAIConversation