This package supports some API Methods, which are grouped into 16 API Handlers.
See the table below for a full list of API Handlers and Methods.
API Handler Class and Method Name | Description | API Verb and URL |
AudioTranscriptions::create() | Transcribes audio into the input language. | POST /audio/transcriptions |
AudioTranslations::create() | Translates audio into into English. | POST /audio/translations |
ChatCompletions::create() | Creates a completion for the chat message | POST /chat/completions |
Completions::create() | Creates a completion for the provided prompt and parameters | POST /completions |
Edits::create() | Creates a new edit for the provided input, instruction, and parameters. | POST /edits |
Embeddings::create() | Creates an embedding vector representing the input text. | POST /embeddings |
Files::list() | Returns a list of files that belong to the user’s organization. | GET /files |
Files::create() | 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 us if you need to increase the storage limit. | POST /files |
Files::retrieve() | Returns information about a specific file. | GET /files/{file_id} |
Files::delete() | Delete a file. | DELETE /files/{file_id} |
FilesContent::download() | Returns the contents of the specified file | GET /files/{file_id}/content |
FineTunes::list() | List your organization’s fine-tuning jobs | GET /fine-tunes |
FineTunes::create() | 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. Learn more about Fine-tuning | POST /fine-tunes |
FineTunes::retrieve() | Gets info about the fine-tune job. Learn more about Fine-tuning | GET /fine-tunes/{fine_tune_id} |
FineTunesCancel::cancelFineTune() | Immediately cancel a fine-tune job | POST /fine-tunes/{fine_tune_id}/cancel |
FineTunesEvents::listFineTune() | Get fine-grained status updates for a fine-tune job. | GET /fine-tunes/{fine_tune_id}/events |
ImagesEdits::createImage() | Creates an edited or extended image given an original image and a prompt. | POST /images/edits |
ImagesGenerations::create() | Creates an image given a prompt | POST /images/generations |
ImagesVariations::createImage() | Creates a variation of a given image. | POST /images/variations |
Models::list() | Lists the currently available models, and provides basic information about each one such as the owner and availability. | GET /models |
Models::retrieve() | Retrieves a model instance, providing basic information about the model such as the owner and permissioning | GET /models/{model} |
Models::delete() | Delete a fine-tuned model. You must have the Owner role in your organization. | DELETE /models/{model} |
Moderations::create() | Classifies if text violates OpenAI’s Content Policy | POST /moderations |
Method: AudioTranscriptions::create()
Audio Resource
method may accept the following parameters:
- $audio_file: The path or URL of the audio file to be transcribed.
- $language: The language of the audio file, such as “en-US” for American English, “es-ES” for Spanish from Spain, etc.
- $format: The format of the audio file, such as “mp3”, “wav”, “ogg”, etc.
- $options: An array of optional parameters that may include:
- “model”: The name or ID of the speech recognition model to be used for transcription.
- “timestamps”: A boolean value indicating whether to include timestamps for each word in the transcription.
- “profanity_filter”: A boolean value indicating whether to filter out profanity from the transcription.
- “max_alternatives”: The maximum number of alternative transcriptions to be returned.
- “word_confidence”: A boolean value indicating whether to include confidence scores for each word in the transcription.
- “speech_contexts”: An array of speech context objects that can be used to improve transcription accuracy.
Transcribes audio into the input language.
$response = $client->audio()->transcribe([
'model' => 'whisper-1', // parameters
'file' => fopen('audio.mp3', 'r'), // parameters
'response_format' => 'verbose_json', // parameters
]);
Parameters
{
"file": "audio.mp3",
"model": "whisper-1"
}
Url : POST https://api.openai.com/v1/audio/transcriptions
Method: AudioTranslations::create()
Translate
Translates audio into English.
The method accepts the following parameters:
- $model: The name or ID of the model to use for the transcription. (Optional)
- $audio: The audio file or URL to transcribe. This can be a path to a local audio file, a URL to an audio file, or a binary audio file. (Required)
- $format: The audio format of the audio file. The supported audio formats are: “mp3”, “wav”, “m4a”, “flac”, “opus”, and “ogg”. (Optional)
- $language: The language of the audio file. The supported languages are: “en” (English), “fr” (French), “de” (German), “es” (Spanish), and “it” (Italian). (Optional)
- $model_config: An object containing additional configuration options for the model. (Optional)
- $request_id: A unique identifier for the request. (Optional)
$response = $client->audio()->translate([
'model' => 'whisper-1', // parameters
'file' => fopen('german.mp3', 'r'), // parameters
'response_format' => 'verbose_json', // parameters
]);
Url: POST
https://api.openai.com/v1/audio/translations
Method=Models::list()
lists the currently available models, and provides basic information about each one such as the owner and availability.
The method accepts the following parameters:
- $modelType: An optional filter to restrict the list to models of a specific type. Valid values include “davinci”, “curie”, “babbage”, and “ada”. If not specified, the method will retrieve all available models. (Optional)
- $page: An optional page number for pagination. If not specified, the method will retrieve the first page of results. If specified, the method will retrieve the page with the given number. (Optional)
- $perPage: The maximum number of results to retrieve per page. The default value is 20. (Optional)
- $orderBy: An optional parameter to specify the order in which to return results. Valid values include “id”, “name”, and “created”. If not specified, the method will order the results by “created” in descending order. (Optional)
- $sort: An optional parameter to specify the sort direction for the “orderBy” parameter. Valid values include “asc” and “desc”. If not specified, the method will sort the results in descending order. (Optional)
- $response = $client->models()->list();
$response->object; // 'list'
foreach ($response->data as $result) {
$result->id; // 'text-davinci-003' // parameters
$result->object; // 'model' // parameters
}
$response->toArray(); // ['object' => 'list', 'data' => [...]]
Url: GET https://api.openai.com/v1/models
Method=Models::retrieve()
Retrieves a model instance, providing basic information about the model such as the owner and permissioning.
The method accepts the following parameters:
$modelId
: The ID of the model to retrieve details about. This parameter is required.$apiKey
: The API key or token required to access the OpenAI API. (Optional)
$response = $client->models()->retrieve('text-davinci-003');
Url: GET https://api.openai.com/v1/models/{model}
Method : ImagesGenerations::create()
Images Resource
create
The method may accept the following parameters:
- $prompt: The text description of the image to be generated.
- $apiKey: The API key or token required to access the DALL-E API.
- $model: The name or ID of the DALL-E model to be used for image generation. (Optional)
- $size: The size of the output image in pixels, specified as a width-height tuple. For example, “512×512”. (Optional)
- $n: The number of images to generate for the given text description. Defaults to 1 if not specified. (Optional)
- $response_format: The format of the response, either “json” or “image”. If “json” is selected, the method will return a JSON object containing the URL of the generated image(s). If “image” is selected, the method will download the image(s) to the specified directory. (Optional)
- $response_dir: The directory where the generated image(s) should be saved if the $response_format parameter is set to “image”. (Optional)
$response = $client->images()->create([
'prompt' => 'A cute baby sea otter',
'n' => 1,
'size' => '256x256',
'response_format' => 'url',
]);
parameter
{
"prompt": "A cute baby sea otter",
"n": 2,
"size": "1024x1024"
}
Url=POST https://api.openai.com/v1/images/generations
Method: ImagesEdits::createImage()
Edit
Creates an edited or extended image given an original image and a prompt.
The method may accept the following parameters:
- $image_url: The URL of the image to be edited.
- $attributes: An associative array of attribute keys and values that should be modified. For example, array(‘color’ => ‘red’, ‘texture’ => ‘smooth’). The available attributes depend on the DALL-E model being used.
- $apiKey: The API key or token required to access the DALL-E API.
- $model: The name or ID of the DALL-E model to be used for image editing. (Optional)
- $response_format: The format of the response, either “json” or “image”. If “json” is selected, the method will return a JSON object containing the URL of the edited image. If “image” is selected, the method will download the edited image to the specified directory. (Optional)
- $response_dir: The directory where the edited image should be saved if the $response_format parameter is set to “image”. (Optional)
$response = $client->images()->edit([
'image' => fopen('image_edit_original.png', 'r'), // parameter 1
'mask' => fopen('image_edit_mask.png', 'r'), // parameter 2
'prompt' => 'A sunlit indoor lounge area with a pool', // parameter 3
'n' => 1, // parameter 4
'size' => '256x256', // parameter 5
'response_format' => 'url', // parameter 6
]);
$response->created;
foreach ($response->data as $data) {
$data->url;
$data->b64_json;
}
$response->toArray();
Method : ImagesVariations::createImage()
Variation
Creates a variation of a given image.
The method may accept the following parameters:
- $image_url: The URL of the image to be varied.
- $variation_type: The type of variation to be applied to the image. Possible values are “zoom”, “rotate”, “shift”, “color”, “texture”, “pattern”, “jitter”, “brightness”, “contrast”, “saturation”, “noise”, and “blur”.
- $apiKey: The API key or token required to access the DALL-E API.
- $model: The name or ID of the DALL-E model to be used for image variation. (Optional)
- $response_format: The format of the response, either “json” or “image”. If “json” is selected, the method will return a JSON object containing the URL of the generated image(s). If “image” is selected, the method will download the generated image(s) to the specified directory. (Optional)
- $response_dir: The directory where the generated image(s) should be saved if the $response_format parameter is set to “image”. (Optional)
$response = $client->images()->variation([
'image' => fopen('image_edit_original.png', 'r'), //parameter 1
'n' => 1, //parameter 2
'size' => '256x256', //parameter 3
'response_format' => 'url', //parameter 4
]);
url = POST https://api.openai.com/v1/images/variations