Interface OpenAIClientAsync
-
- All Implemented Interfaces:
public interface OpenAIClientAsyncA 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 interfaceOpenAIClientAsync.WithRawResponseA view of OpenAIClientAsync that provides access to raw HTTP responses for each method.
-
Method Summary
Modifier and Type Method Description abstract OpenAIClientsync()Returns a version of this client that uses synchronous execution. abstract OpenAIClientAsync.WithRawResponsewithRawResponse()Returns a view of this service that provides access to raw HTTP responses for each method. abstract OpenAIClientAsyncwithOptions(Consumer<ClientOptions.Builder> modifier)Returns a view of this service with the given option modifications applied. abstract CompletionServiceAsynccompletions()Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position. abstract ChatServiceAsyncchat()abstract EmbeddingServiceAsyncembeddings()Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms. abstract FileServiceAsyncfiles()Files are used to upload documents that can be used with features like Assistants and Fine-tuning. abstract ImageServiceAsyncimages()Given a prompt and/or an input image, the model will generate a new image. abstract AudioServiceAsyncaudio()abstract ModerationServiceAsyncmoderations()Given text and/or image inputs, classifies if those inputs are potentially harmful. abstract ModelServiceAsyncmodels()List and describe the various models available in the API. abstract FineTuningServiceAsyncfineTuning()abstract GraderServiceAsyncgraders()abstract VectorStoreServiceAsyncvectorStores()abstract WebhookServiceAsyncwebhooks()abstract BetaServiceAsyncbeta()abstract BatchServiceAsyncbatches()Create large batches of API requests to run asynchronously. abstract UploadServiceAsyncuploads()Use Uploads to upload large files in multiple parts. abstract ResponseServiceAsyncresponses()abstract RealtimeServiceAsyncrealtime()abstract ConversationServiceAsyncconversations()Manage conversations and conversation items. abstract EvalServiceAsyncevals()Manage and run evals in the OpenAI platform. abstract ContainerServiceAsynccontainers()abstract SkillServiceAsyncskills()abstract VideoServiceAsyncvideos()abstract Unitclose()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()
Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.
-
chat
abstract ChatServiceAsync chat()
-
embeddings
abstract EmbeddingServiceAsync embeddings()
Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.
-
files
abstract FileServiceAsync files()
Files are used to upload documents that can be used with features like Assistants and Fine-tuning.
-
images
abstract ImageServiceAsync images()
Given a prompt and/or an input image, the model will generate a new image.
-
audio
abstract AudioServiceAsync audio()
-
moderations
abstract ModerationServiceAsync moderations()
Given text and/or image inputs, classifies if those inputs are potentially harmful.
-
models
abstract ModelServiceAsync models()
List and describe the various models available in the API.
-
fineTuning
abstract FineTuningServiceAsync fineTuning()
-
graders
abstract GraderServiceAsync graders()
-
vectorStores
abstract VectorStoreServiceAsync vectorStores()
-
webhooks
abstract WebhookServiceAsync webhooks()
-
beta
abstract BetaServiceAsync beta()
-
batches
abstract BatchServiceAsync batches()
Create large batches of API requests to run asynchronously.
-
uploads
abstract UploadServiceAsync uploads()
Use Uploads to upload large files in multiple parts.
-
responses
abstract ResponseServiceAsync responses()
-
realtime
abstract RealtimeServiceAsync realtime()
-
conversations
abstract ConversationServiceAsync conversations()
Manage conversations and conversation items.
-
evals
abstract EvalServiceAsync evals()
Manage and run evals in the OpenAI platform.
-
containers
abstract ContainerServiceAsync containers()
-
skills
abstract SkillServiceAsync skills()
-
videos
abstract VideoServiceAsync videos()
-
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.
-
-
-
-