Interface OpenAIClient
-
- All Implemented Interfaces:
public interface OpenAIClient
A client for interacting with the OpenAI REST API synchronously. You can also switch to asynchronous execution via the async method.
This client performs best when you create a single instance and reuse it for all interactions with the REST API. This is because each client holds its own connection pool and thread pools. Reusing connections and threads reduces latency and saves memory. The client also handles rate limiting per client. This means that creating and using multiple instances at the same time will not respect rate limits.
The threads and connections that are held will be released automatically if they remain idle. But if you are writing an application that needs to aggressively release unused resources, then you may call close.
-
-
Method Summary
Modifier and Type Method Description abstract OpenAIClientAsync
async()
Returns a version of this client that uses asynchronous execution. abstract CompletionService
completions()
abstract ChatService
chat()
abstract EmbeddingService
embeddings()
abstract FileService
files()
abstract ImageService
images()
abstract ModerationService
moderations()
abstract ModelService
models()
abstract FineTuningService
fineTuning()
abstract BetaService
beta()
abstract BatchService
batches()
abstract UploadService
uploads()
abstract Unit
close()
Closes this client, relinquishing any underlying resources. -
-
Method Detail
-
async
abstract OpenAIClientAsync async()
Returns a version of this client that uses asynchronous execution.
The returned client shares its resources, like its connection pool and thread pools, with this client.
-
completions
abstract CompletionService completions()
-
chat
abstract ChatService chat()
-
embeddings
abstract EmbeddingService embeddings()
-
files
abstract FileService files()
-
images
abstract ImageService images()
-
moderations
abstract ModerationService moderations()
-
models
abstract ModelService models()
-
fineTuning
abstract FineTuningService fineTuning()
-
beta
abstract BetaService beta()
-
batches
abstract BatchService batches()
-
uploads
abstract UploadService uploads()
-
close
abstract Unit close()
Closes this client, relinquishing any underlying resources.
This is purposefully not inherited from AutoCloseable because the client is long-lived and usually should not be synchronously closed via try-with-resources.
It's also usually not necessary to call this method at all. the default HTTP client automatically releases threads and connections if they remain idle, but if you are writing an application that needs to aggressively release unused resources, then you may call this method.
-
-
-
-