Interface OpenAIClientAsync
-
- All Implemented Interfaces:
public interface OpenAIClientAsync
A client for interacting with the OpenAI REST API asynchronously. You can also switch to synchronous execution via the sync 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interface
OpenAIClientAsync.WithRawResponse
A view of OpenAIClientAsync that provides access to raw HTTP responses for each method.
-
Method Summary
Modifier and Type Method Description abstract OpenAIClient
sync()
Returns a version of this client that uses synchronous execution. abstract OpenAIClientAsync.WithRawResponse
withRawResponse()
Returns a view of this service that provides access to raw HTTP responses for each method. abstract OpenAIClientAsync
withOptions(Consumer<ClientOptions.Builder> modifier)
Returns a view of this service with the given option modifications applied. abstract CompletionServiceAsync
completions()
abstract ChatServiceAsync
chat()
abstract EmbeddingServiceAsync
embeddings()
abstract FileServiceAsync
files()
abstract ImageServiceAsync
images()
abstract AudioServiceAsync
audio()
abstract ModerationServiceAsync
moderations()
abstract ModelServiceAsync
models()
abstract FineTuningServiceAsync
fineTuning()
abstract GraderServiceAsync
graders()
abstract VectorStoreServiceAsync
vectorStores()
abstract BetaServiceAsync
beta()
abstract BatchServiceAsync
batches()
abstract UploadServiceAsync
uploads()
abstract ResponseServiceAsync
responses()
abstract EvalServiceAsync
evals()
abstract ContainerServiceAsync
containers()
abstract Unit
close()
Closes this client, relinquishing any underlying resources. -
-
Method Detail
-
sync
abstract OpenAIClient sync()
Returns a version of this client that uses synchronous execution.
The returned client shares its resources, like its connection pool and thread pools, with this client.
-
withRawResponse
abstract OpenAIClientAsync.WithRawResponse withRawResponse()
Returns a view of this service that provides access to raw HTTP responses for each method.
-
withOptions
abstract OpenAIClientAsync withOptions(Consumer<ClientOptions.Builder> modifier)
Returns a view of this service with the given option modifications applied.
The original service is not modified.
-
completions
abstract CompletionServiceAsync completions()
-
chat
abstract ChatServiceAsync chat()
-
embeddings
abstract EmbeddingServiceAsync embeddings()
-
files
abstract FileServiceAsync files()
-
images
abstract ImageServiceAsync images()
-
audio
abstract AudioServiceAsync audio()
-
moderations
abstract ModerationServiceAsync moderations()
-
models
abstract ModelServiceAsync models()
-
fineTuning
abstract FineTuningServiceAsync fineTuning()
-
graders
abstract GraderServiceAsync graders()
-
vectorStores
abstract VectorStoreServiceAsync vectorStores()
-
beta
abstract BetaServiceAsync beta()
-
batches
abstract BatchServiceAsync batches()
-
uploads
abstract UploadServiceAsync uploads()
-
responses
abstract ResponseServiceAsync responses()
-
evals
abstract EvalServiceAsync evals()
-
containers
abstract ContainerServiceAsync containers()
-
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.
-
-
-
-