Saltar para o conteúdo principal
Versão: Próximo

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 NameTipoDescriçãoOpcional
apiKeyTextYour OpenAI API Key.No for OpenAI
baseURLTextBase URL for OpenAI API requests.Sim
organizationTextYour OpenAI Organization ID.Sim
projectTextYour OpenAI Project ID.Sim

Additional HTTP properties

Property NameTipoDescrição
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 NameTipoDescrição
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 NameTipoDescrição
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(...)