class

OpenAI::Client

Inherits Reference / Object

OpenAI client

Constructors

new(api_key : String | Nil = nil, proxy : ProxyConfig | Nil = nil)

Original signature — keeps backward compatibility

Source
new(api_key : String | Nil, api_base : String, proxy : ProxyConfig | Nil = nil)

Overload with explicit api_base (key always optional when api_base is provided)

Source

Class methods

azure(api_key : String | Nil, api_endpoint : String, proxy : ProxyConfig | Nil = nil)
Source

Instance methods

cancel_fine_tuning_job(job_id : String) : FineTuningJob

Immediately cancel a fine-tune job.

Source
chat_completion(req : ChatCompletionRequest) : ChatCompletionResponse

API call to Create a completion for the chat message.

Source
chat_completion_stream(req : ChatCompletionRequest) : ChatCompletionStream

API call to create a chat completion w/ streaming support. It sets whether to stream back partial progress. If set, tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.

Source
completion(req : CompletionRequest) : CompletionResponse

API call to create a completion. This is the main endpoint of the API. Returns new text as well as, if requested, the probabilities over each alternative token at each position.

If using a fine-tuned model, simply provide the model's ID in the CompletionRequest object, and the server will use the model's parameters to generate the completion.

Source
completion_stream(req : CompletionRequest) : CompletionStream

API call to create a completion w/ streaming support. It sets whether to stream back partial progress. If set, tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.

Source
config
Source
create_fine_tuning_job(job : FineTuningJobRequest) : FineTuningJob

Creates a job that fine-tunes a specified model from a given dataset.

Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete.

Source
create_image(req : ImageRequest) : ImageResponse

API call to create an image. This is the main endpoint of the DALL-E API.

Source
create_image_edit(req : ImageEditRequest) : ImageResponse

Creates an edited or extended image given an original image and a prompt.

Source
create_image_variation(req : ImageVariationRequest) : ImageResponse

Creates a variation of a given image.

Source
delete_file(file_id : String) : FileDeletionStatus

Delete a file

Source
embeddings(req : EmbeddingRequest) : EmbeddingResponse

Creates an embedding vector representing the input text.

Source
engine(id : String) : Engine

Retrieves an engine instance, providing basic information about such as the owner and availability.

Source
engines

Lists the currently available engines, and provides basic information about each option such as the owner and availability.

Source
get_file(file_id : String) : FileResponse

Retrieve a file

Source
get_file_contents(file_id : String) : IO

Returns the contents of the specified file.

Source
get_fine_tuning_job(job_id : String) : FineTuningJob

Get info about a fine-tuning job.

Source
list_files

Returns a list of files that belong to the user's organization.

Source
list_fine_tuning_events(job_id : String, after : String | Nil = nil, limit : Int32 = 20) : FineTuningJobEventList

Get status updates for a fine-tuning job. after : Identifier for the last job from the previous pagination request. limit : Number of fine-tuning jobs to retrieve.

Source
list_fine_tuning_jobs(after : String | Nil = nil, limit : Int32 = 20) : FineTuningJobEventList

List your organization's fine-tuning jobs after : Identifier for the last job from the previous pagination request. limit : Number of fine-tuning jobs to retrieve.

Source
model(id : String) : Model

Retrieves a model instance, providing basic information about the model

Source
models

Lists currently available models, and provide basic information about each model

Source
moderation(req : ModerationRequest) : ModerationResponse

Performs a moderation api call

Source
transcription(req : TranscriptionRequest) : TranscriptionResponse

API call to transcribe audio into the input language.

Source
translation(req : TranscriptionRequest) : TranscriptionResponse

API call to translate audio into English.

Source
upload_file(req : FileRequest) : FileResponse

Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact OpenAI if you need to increase the storage limit.

Source

Nested types