Skip to main content
Version: Next

OpenAI

The OpenAI class provides a client for accessing various OpenAI API resources. It includes properties for managing API configurations and methods for performing HTTP requests to the OpenAI endpoints.

Configuration Properties

Property NameTypeDescriptionOptional
apiKeyTextYour OpenAI API Key.No for OpenAI
baseURLTextBase URL for OpenAI API requests.Yes
organizationTextYour OpenAI Organization ID.Yes
projectTextYour OpenAI Project ID.Yes

Additional HTTP properties

Property NameTypeDescription
timeoutRealTime in seconds before timeout occurs.
maxRetriesRealMaximum number of retry attempts in case of failure.
httpAgent4D.HTTPAgentHTTP agent used for making requests.
customHeadersRealCustom headers to be included in the HTTP requests.

Class constructor

Create an instance of the OpenAI client class.

Argument NameTypeDescription
apiKeyText or ObjectapiKey if Text as first argument and the second can be an Object of parameters.

API key

// as text
var $client:=cs.AIKit.OpenAI.new("your api key")
// as object
var $client:=cs.AIKit.OpenAI.new({apiKey: "your api key"})

Server URL

For a compatible provider API, you can configure the server URL.

var $client:=cs.AIKit.OpenAI.new({apiKey: "your api key"; baseURL: "https://server.ai"})

or after creating an instance

$client.baseURL:="https://server.ai"

API resources

The API provides access to multiple resources that allow seamless interaction with OpenAI's services. Each resource is encapsulated within a dedicated API class, offering a structured and intuitive way to interact with different functionalities.

Property NameTypeDescription
modelsOpenAIModelsAPIAccess to the Models API.
chatOpenAIChatAPIAccess to the Chat API.
imagesOpenAIImagesAPIAccess to the Images API.
moderationsOpenAIModerationsAPIAccess to the Moderations API.

Example Usage

$client.chat.completions.create(...)
$client.images.generate(...)
$client.model.lists(...)