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 Name | Type | Description | Optional |
---|---|---|---|
apiKey | Text | Your OpenAI API Key. | No for OpenAI |
baseURL | Text | Base URL for OpenAI API requests. | Yes |
organization | Text | Your OpenAI Organization ID. | Yes |
project | Text | Your OpenAI Project ID. | Yes |
Additional HTTP properties
Property Name | Type | Description |
---|---|---|
timeout | Real | Time in seconds before timeout occurs. |
maxRetries | Real | Maximum number of retry attempts in case of failure. |
httpAgent | 4D.HTTPAgent | HTTP agent used for making requests. |
customHeaders | Real | Custom headers to be included in the HTTP requests. |
Class constructor
Create an instance of the OpenAI client class.
Argument Name | Type | Description |
---|---|---|
apiKey | Text or Object | apiKey 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 Name | Type | Description |
---|---|---|
models | OpenAIModelsAPI | Access to the Models API. |
chat | OpenAIChatAPI | Access to the Chat API. |
images | OpenAIImagesAPI | Access to the Images API. |
moderations | OpenAIModerationsAPI | Access to the Moderations API. |
Example Usage
$client.chat.completions.create(...)
$client.images.generate(...)
$client.model.lists(...)