diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index ea8ffb9..e33aa05 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -2,7 +2,7 @@ distribution = "2201.9.3" org = "ballerinax" name = "openai.finetunes" -version = "2.0.0" +version = "3.0.0" license = ["Apache-2.0"] authors = ["Ballerina"] keywords = ["AI/Fine-tunes", "OpenAI", "Cost/Paid", "Files", "Models", "Vendor/OpenAI"] diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 1834973..68ea7a3 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,12 +5,12 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.9.3" +distribution-version = "2201.12.2" [[package]] org = "ballerina" name = "auth" -version = "2.11.2" +version = "2.14.0" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "jballerina.java"}, @@ -22,7 +22,7 @@ dependencies = [ [[package]] org = "ballerina" name = "cache" -version = "3.8.0" +version = "3.10.0" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "jballerina.java"}, @@ -33,24 +33,39 @@ dependencies = [ [[package]] org = "ballerina" name = "constraint" -version = "1.5.0" +version = "1.7.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] +modules = [ + {org = "ballerina", packageName = "constraint", moduleName = "constraint"} +] [[package]] org = "ballerina" name = "crypto" -version = "2.7.2" +version = "2.9.0" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "time"} ] +[[package]] +org = "ballerina" +name = "data.jsondata" +version = "1.1.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] +modules = [ + {org = "ballerina", packageName = "data.jsondata", moduleName = "data.jsondata"} +] + [[package]] org = "ballerina" name = "file" -version = "1.9.0" +version = "1.12.0" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -61,12 +76,13 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.11.3" +version = "2.14.0" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "data.jsondata"}, {org = "ballerina", name = "file"}, {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -93,7 +109,7 @@ modules = [ [[package]] org = "ballerina" name = "io" -version = "1.6.1" +version = "1.8.0" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.value"} @@ -107,10 +123,11 @@ version = "0.0.0" [[package]] org = "ballerina" name = "jwt" -version = "2.12.1" +version = "2.15.0" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.int"}, {org = "ballerina", name = "lang.string"}, @@ -204,7 +221,7 @@ dependencies = [ [[package]] org = "ballerina" name = "log" -version = "2.9.0" +version = "2.12.0" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -218,11 +235,12 @@ modules = [ [[package]] org = "ballerina" name = "mime" -version = "2.9.0" +version = "2.12.0" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.int"} + {org = "ballerina", name = "lang.int"}, + {org = "ballerina", name = "log"} ] modules = [ {org = "ballerina", packageName = "mime", moduleName = "mime"} @@ -231,7 +249,7 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.11.0" +version = "2.14.0" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, @@ -244,7 +262,7 @@ dependencies = [ [[package]] org = "ballerina" name = "observe" -version = "1.2.3" +version = "1.5.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -252,7 +270,7 @@ dependencies = [ [[package]] org = "ballerina" name = "os" -version = "1.8.0" +version = "1.10.0" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"} @@ -264,7 +282,7 @@ modules = [ [[package]] org = "ballerina" name = "task" -version = "2.5.0" +version = "2.7.0" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "time"} @@ -287,7 +305,7 @@ modules = [ [[package]] org = "ballerina" name = "time" -version = "2.4.0" +version = "2.7.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -295,7 +313,7 @@ dependencies = [ [[package]] org = "ballerina" name = "url" -version = "2.4.0" +version = "2.6.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -318,8 +336,10 @@ modules = [ [[package]] org = "ballerinax" name = "openai.finetunes" -version = "2.0.0" +version = "3.0.0" dependencies = [ + {org = "ballerina", name = "constraint"}, + {org = "ballerina", name = "data.jsondata"}, {org = "ballerina", name = "http"}, {org = "ballerina", name = "log"}, {org = "ballerina", name = "mime"}, diff --git a/ballerina/client.bal b/ballerina/client.bal index 72c21eb..0342651 100644 --- a/ballerina/client.bal +++ b/ballerina/client.bal @@ -17,6 +17,7 @@ // specific language governing permissions and limitations // under the License. +import ballerina/data.jsondata; import ballerina/http; import ballerina/mime; @@ -25,139 +26,327 @@ public isolated client class Client { final http:Client clientEp; # Gets invoked to initialize the `connector`. # - # + config - The configurations to be used when initializing the `connector` - # + serviceUrl - URL of the target service - # + return - An error if connector initialization failed + # + config - The configurations to be used when initializing the `connector` + # + serviceUrl - URL of the target service + # + return - An error if connector initialization failed public isolated function init(ConnectionConfig config, string serviceUrl = "https://api.openai.com/v1") returns error? { - http:ClientConfiguration httpClientConfig = {auth: config.auth, httpVersion: config.httpVersion, timeout: config.timeout, forwarded: config.forwarded, poolConfig: config.poolConfig, compression: config.compression, circuitBreaker: config.circuitBreaker, retryConfig: config.retryConfig, validation: config.validation}; - do { - if config.http1Settings is ClientHttp1Settings { - ClientHttp1Settings settings = check config.http1Settings.ensureType(ClientHttp1Settings); - httpClientConfig.http1Settings = {...settings}; - } - if config.http2Settings is http:ClientHttp2Settings { - httpClientConfig.http2Settings = check config.http2Settings.ensureType(http:ClientHttp2Settings); - } - if config.cache is http:CacheConfig { - httpClientConfig.cache = check config.cache.ensureType(http:CacheConfig); - } - if config.responseLimits is http:ResponseLimitConfigs { - httpClientConfig.responseLimits = check config.responseLimits.ensureType(http:ResponseLimitConfigs); - } - if config.secureSocket is http:ClientSecureSocket { - httpClientConfig.secureSocket = check config.secureSocket.ensureType(http:ClientSecureSocket); - } - if config.proxy is http:ProxyConfig { - httpClientConfig.proxy = check config.proxy.ensureType(http:ProxyConfig); - } - } - http:Client httpEp = check new (serviceUrl, httpClientConfig); - self.clientEp = httpEp; - return; + http:ClientConfiguration httpClientConfig = {auth: config.auth, httpVersion: config.httpVersion, http1Settings: config.http1Settings, http2Settings: config.http2Settings, timeout: config.timeout, forwarded: config.forwarded, followRedirects: config.followRedirects, poolConfig: config.poolConfig, cache: config.cache, compression: config.compression, circuitBreaker: config.circuitBreaker, retryConfig: config.retryConfig, cookieConfig: config.cookieConfig, responseLimits: config.responseLimits, secureSocket: config.secureSocket, proxy: config.proxy, socketConfig: config.socketConfig, validation: config.validation, laxDataBinding: config.laxDataBinding}; + self.clientEp = check new (serviceUrl, httpClientConfig); } - # Delete a file. + # Creates a model response for the given chat conversation. # - # + file_id - The ID of the file to use for this request. - # + headers - Headers to be sent with the request - # + return - OK - resource isolated function delete files/[string file_id](map headers = {}) returns DeleteFileResponse|error { - string resourcePath = string `/files/${getEncodedUri(file_id)}`; - return self.clientEp->delete(resourcePath, headers = headers); + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post chat/completions(CreateChatCompletionRequest payload, map headers = {}) returns CreateChatCompletionResponse|error { + string resourcePath = string `/chat/completions`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); } - # Delete a fine-tuned model. You must have the Owner role in your organization to delete a model. + # Creates a completion for the provided prompt and parameters. # - # + model - The model to delete - # + headers - Headers to be sent with the request - # + return - OK - resource isolated function delete models/[string model](map headers = {}) returns DeleteModelResponse|error { - string resourcePath = string `/models/${getEncodedUri(model)}`; - return self.clientEp->delete(resourcePath, headers = headers); + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post completions(CreateCompletionRequest payload, map headers = {}) returns CreateCompletionResponse|error { + string resourcePath = string `/completions`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Creates an image given a prompt. + # + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post images/generations(CreateImageRequest payload, map headers = {}) returns ImagesResponse|error { + string resourcePath = string `/images/generations`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Creates an edited or extended image given an original image and a prompt. + # + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post images/edits(CreateImageEditRequest payload, map headers = {}) returns ImagesResponse|error { + string resourcePath = string `/images/edits`; + http:Request request = new; + mime:Entity[] bodyParts = check createBodyParts(payload); + request.setBodyParts(bodyParts); + return self.clientEp->post(resourcePath, request, headers); + } + + # Creates a variation of a given image. + # + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post images/variations(CreateImageVariationRequest payload, map headers = {}) returns ImagesResponse|error { + string resourcePath = string `/images/variations`; + http:Request request = new; + mime:Entity[] bodyParts = check createBodyParts(payload); + request.setBodyParts(bodyParts); + return self.clientEp->post(resourcePath, request, headers); + } + + # Creates an embedding vector representing the input text. + # + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post embeddings(CreateEmbeddingRequest payload, map headers = {}) returns CreateEmbeddingResponse|error { + string resourcePath = string `/embeddings`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Generates audio from the input text. + # + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post audio/speech(CreateSpeechRequest payload, map headers = {}) returns byte[]|error { + string resourcePath = string `/audio/speech`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Transcribes audio into the input language. + # + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post audio/transcriptions(CreateTranscriptionRequest payload, map headers = {}) returns InlineResponse200|error { + string resourcePath = string `/audio/transcriptions`; + http:Request request = new; + mime:Entity[] bodyParts = check createBodyParts(payload); + request.setBodyParts(bodyParts); + return self.clientEp->post(resourcePath, request, headers); + } + + # Translates audio into English. + # + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post audio/translations(CreateTranslationRequest payload, map headers = {}) returns InlineResponse2001|error { + string resourcePath = string `/audio/translations`; + http:Request request = new; + mime:Entity[] bodyParts = check createBodyParts(payload); + request.setBodyParts(bodyParts); + return self.clientEp->post(resourcePath, request, headers); } # Returns a list of files that belong to the user's organization. # - # + headers - Headers to be sent with the request - # + queries - Queries to be sent with the request - # + return - OK + # + headers - Headers to be sent with the request + # + queries - Queries to be sent with the request + # + return - OK resource isolated function get files(map headers = {}, *ListFilesQueries queries) returns ListFilesResponse|error { string resourcePath = string `/files`; resourcePath = resourcePath + check getPathForQueryParam(queries); return self.clientEp->get(resourcePath, headers); } + # Upload a file that can be used across various endpoints. Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB. + # + # The Assistants API supports files up to 2 million tokens and of specific file types. See the [Assistants Tools guide](/docs/assistants/tools) for details. + # + # The Fine-tuning API only supports `.jsonl` files. The input also has certain required formats for fine-tuning [chat](/docs/api-reference/fine-tuning/chat-input) or [completions](/docs/api-reference/fine-tuning/completions-input) models. + # + # The Batch API only supports `.jsonl` files up to 100 MB in size. The input also has a specific required [format](/docs/api-reference/batch/request-input). + # + # Please [contact us](https://help.openai.com/) if you need to increase these storage limits. + # + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post files(CreateFileRequest payload, map headers = {}) returns OpenAIFile|error { + string resourcePath = string `/files`; + http:Request request = new; + mime:Entity[] bodyParts = check createBodyParts(payload); + request.setBodyParts(bodyParts); + return self.clientEp->post(resourcePath, request, headers); + } + # Returns information about a specific file. # - # + file_id - The ID of the file to use for this request. - # + headers - Headers to be sent with the request - # + return - OK - resource isolated function get files/[string file_id](map headers = {}) returns OpenAIFile|error { - string resourcePath = string `/files/${getEncodedUri(file_id)}`; + # + fileId - The ID of the file to use for this request + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function get files/[string fileId](map headers = {}) returns OpenAIFile|error { + string resourcePath = string `/files/${getEncodedUri(fileId)}`; return self.clientEp->get(resourcePath, headers); } + # Delete a file. + # + # + fileId - The ID of the file to use for this request + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function delete files/[string fileId](map headers = {}) returns DeleteFileResponse|error { + string resourcePath = string `/files/${getEncodedUri(fileId)}`; + return self.clientEp->delete(resourcePath, headers = headers); + } + # Returns the contents of the specified file. # - # + file_id - The ID of the file to use for this request. - # + headers - Headers to be sent with the request - # + return - OK - resource isolated function get files/[string file_id]/content(map headers = {}) returns byte[]|error { - string resourcePath = string `/files/${getEncodedUri(file_id)}/content`; + # + fileId - The ID of the file to use for this request + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function get files/[string fileId]/content(map headers = {}) returns byte[]|error { + string resourcePath = string `/files/${getEncodedUri(fileId)}/content`; return self.clientEp->get(resourcePath, headers); } + # Creates an intermediate [Upload](/docs/api-reference/uploads/object) object that you can add [Parts](/docs/api-reference/uploads/part-object) to. Currently, an Upload can accept at most 8 GB in total and expires after an hour after you create it. + # + # Once you complete the Upload, we will create a [File](/docs/api-reference/files/object) object that contains all the parts you uploaded. This File is usable in the rest of our platform as a regular File object. + # + # For certain `purpose`s, the correct `mime_type` must be specified. Please refer to documentation for the supported MIME types for your use case: + # - [Assistants](/docs/assistants/tools/file-search/supported-files) + # + # For guidance on the proper filename extensions for each purpose, please follow the documentation on [creating a File](/docs/api-reference/files/create). + # + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post uploads(CreateUploadRequest payload, map headers = {}) returns Upload|error { + string resourcePath = string `/uploads`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Adds a [Part](/docs/api-reference/uploads/part-object) to an [Upload](/docs/api-reference/uploads/object) object. A Part represents a chunk of bytes from the file you are trying to upload. + # + # Each Part can be at most 64 MB, and you can add Parts until you hit the Upload maximum of 8 GB. + # + # It is possible to add multiple Parts in parallel. You can decide the intended order of the Parts when you [complete the Upload](/docs/api-reference/uploads/complete). + # + # + uploadId - The ID of the Upload + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post uploads/[string uploadId]/parts(AddUploadPartRequest payload, map headers = {}) returns UploadPart|error { + string resourcePath = string `/uploads/${getEncodedUri(uploadId)}/parts`; + http:Request request = new; + mime:Entity[] bodyParts = check createBodyParts(payload); + request.setBodyParts(bodyParts); + return self.clientEp->post(resourcePath, request, headers); + } + + # Completes the [Upload](/docs/api-reference/uploads/object). + # + # Within the returned Upload object, there is a nested [File](/docs/api-reference/files/object) object that is ready to use in the rest of the platform. + # + # You can specify the order of the Parts by passing in an ordered list of the Part IDs. + # + # The number of bytes uploaded upon completion must match the number of bytes initially specified when creating the Upload object. No Parts may be added after an Upload is completed. + # + # + uploadId - The ID of the Upload + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post uploads/[string uploadId]/complete(CompleteUploadRequest payload, map headers = {}) returns Upload|error { + string resourcePath = string `/uploads/${getEncodedUri(uploadId)}/complete`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Cancels the Upload. No Parts may be added after an Upload is cancelled. + # + # + uploadId - The ID of the Upload + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post uploads/[string uploadId]/cancel(map headers = {}) returns Upload|error { + string resourcePath = string `/uploads/${getEncodedUri(uploadId)}/cancel`; + http:Request request = new; + return self.clientEp->post(resourcePath, request, headers); + } + # List your organization's fine-tuning jobs # - # + headers - Headers to be sent with the request - # + queries - Queries to be sent with the request - # + return - OK + # + headers - Headers to be sent with the request + # + queries - Queries to be sent with the request + # + return - OK resource isolated function get fine_tuning/jobs(map headers = {}, *ListPaginatedFineTuningJobsQueries queries) returns ListPaginatedFineTuningJobsResponse|error { string resourcePath = string `/fine_tuning/jobs`; resourcePath = resourcePath + check getPathForQueryParam(queries); return self.clientEp->get(resourcePath, headers); } + # Creates a fine-tuning job which begins the process of creating a new 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](/docs/guides/fine-tuning) + # + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post fine_tuning/jobs(CreateFineTuningJobRequest payload, map headers = {}) returns FineTuningJob|error { + string resourcePath = string `/fine_tuning/jobs`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + # Get info about a fine-tuning job. - # + # # [Learn more about fine-tuning](/docs/guides/fine-tuning) # - # + fine_tuning_job_id - The ID of the fine-tuning job. - # + headers - Headers to be sent with the request - # + return - OK - resource isolated function get fine_tuning/jobs/[string fine_tuning_job_id](map headers = {}) returns FineTuningJob|error { - string resourcePath = string `/fine_tuning/jobs/${getEncodedUri(fine_tuning_job_id)}`; + # + fineTuningJobId - The ID of the fine-tuning job + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function get fine_tuning/jobs/[string fineTuningJobId](map headers = {}) returns FineTuningJob|error { + string resourcePath = string `/fine_tuning/jobs/${getEncodedUri(fineTuningJobId)}`; return self.clientEp->get(resourcePath, headers); } - # List checkpoints for a fine-tuning job. + # Get status updates for a fine-tuning job. # - # + fine_tuning_job_id - The ID of the fine-tuning job to get checkpoints for. - # + headers - Headers to be sent with the request - # + queries - Queries to be sent with the request - # + return - OK - resource isolated function get fine_tuning/jobs/[string fine_tuning_job_id]/checkpoints(map headers = {}, *ListFineTuningJobCheckpointsQueries queries) returns ListFineTuningJobCheckpointsResponse|error { - string resourcePath = string `/fine_tuning/jobs/${getEncodedUri(fine_tuning_job_id)}/checkpoints`; + # + fineTuningJobId - The ID of the fine-tuning job to get events for + # + headers - Headers to be sent with the request + # + queries - Queries to be sent with the request + # + return - OK + resource isolated function get fine_tuning/jobs/[string fineTuningJobId]/events(map headers = {}, *ListFineTuningEventsQueries queries) returns ListFineTuningJobEventsResponse|error { + string resourcePath = string `/fine_tuning/jobs/${getEncodedUri(fineTuningJobId)}/events`; resourcePath = resourcePath + check getPathForQueryParam(queries); return self.clientEp->get(resourcePath, headers); } - # Get status updates for a fine-tuning job. + # Immediately cancel a fine-tune job. # - # + fine_tuning_job_id - The ID of the fine-tuning job to get events for. - # + headers - Headers to be sent with the request - # + queries - Queries to be sent with the request - # + return - OK - resource isolated function get fine_tuning/jobs/[string fine_tuning_job_id]/events(map headers = {}, *ListFineTuningEventsQueries queries) returns ListFineTuningJobEventsResponse|error { - string resourcePath = string `/fine_tuning/jobs/${getEncodedUri(fine_tuning_job_id)}/events`; + # + fineTuningJobId - The ID of the fine-tuning job to cancel + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post fine_tuning/jobs/[string fineTuningJobId]/cancel(map headers = {}) returns FineTuningJob|error { + string resourcePath = string `/fine_tuning/jobs/${getEncodedUri(fineTuningJobId)}/cancel`; + http:Request request = new; + return self.clientEp->post(resourcePath, request, headers); + } + + # List checkpoints for a fine-tuning job. + # + # + fineTuningJobId - The ID of the fine-tuning job to get checkpoints for + # + headers - Headers to be sent with the request + # + queries - Queries to be sent with the request + # + return - OK + resource isolated function get fine_tuning/jobs/[string fineTuningJobId]/checkpoints(map headers = {}, *ListFineTuningJobCheckpointsQueries queries) returns ListFineTuningJobCheckpointsResponse|error { + string resourcePath = string `/fine_tuning/jobs/${getEncodedUri(fineTuningJobId)}/checkpoints`; resourcePath = resourcePath + check getPathForQueryParam(queries); return self.clientEp->get(resourcePath, headers); } # Lists the currently available models, and provides basic information about each one such as the owner and availability. # - # + headers - Headers to be sent with the request - # + return - OK + # + headers - Headers to be sent with the request + # + return - OK resource isolated function get models(map headers = {}) returns ListModelsResponse|error { string resourcePath = string `/models`; return self.clientEp->get(resourcePath, headers); @@ -166,56 +355,502 @@ public isolated client class Client { # Retrieves a model instance, providing basic information about the model such as the owner and permissioning. # # + model - The ID of the model to use for this request - # + headers - Headers to be sent with the request - # + return - OK + # + headers - Headers to be sent with the request + # + return - OK resource isolated function get models/[string model](map headers = {}) returns Model|error { string resourcePath = string `/models/${getEncodedUri(model)}`; return self.clientEp->get(resourcePath, headers); } - # Upload a file that can be used across various endpoints. Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB. - # - # The Assistants API supports files up to 2 million tokens and of specific file types. See the [Assistants Tools guide](/docs/assistants/tools) for details. - # - # The Fine-tuning API only supports `.jsonl` files. The input also has certain required formats for fine-tuning [chat](/docs/api-reference/fine-tuning/chat-input) or [completions](/docs/api-reference/fine-tuning/completions-input) models. - # - # The Batch API only supports `.jsonl` files up to 100 MB in size. The input also has a specific required [format](/docs/api-reference/batch/request-input). - # - # Please [contact us](https://help.openai.com/) if you need to increase these storage limits. + # Delete a fine-tuned model. You must have the Owner role in your organization to delete a model. # - # + headers - Headers to be sent with the request - # + return - OK - resource isolated function post files(CreateFileRequest payload, map headers = {}) returns OpenAIFile|error { - string resourcePath = string `/files`; + # + model - The model to delete + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function delete models/[string model](map headers = {}) returns DeleteModelResponse|error { + string resourcePath = string `/models/${getEncodedUri(model)}`; + return self.clientEp->delete(resourcePath, headers = headers); + } + + # Classifies if text is potentially harmful. + # + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post moderations(CreateModerationRequest payload, map headers = {}) returns CreateModerationResponse|error { + string resourcePath = string `/moderations`; http:Request request = new; - mime:Entity[] bodyParts = check createBodyParts(payload); - request.setBodyParts(bodyParts); + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); return self.clientEp->post(resourcePath, request, headers); } - # Creates a fine-tuning job which begins the process of creating a new 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](/docs/guides/fine-tuning) + # Returns a list of assistants. # - # + headers - Headers to be sent with the request - # + return - OK - resource isolated function post fine_tuning/jobs(CreateFineTuningJobRequest payload, map headers = {}) returns FineTuningJob|error { - string resourcePath = string `/fine_tuning/jobs`; + # + headers - Headers to be sent with the request + # + queries - Queries to be sent with the request + # + return - OK + resource isolated function get assistants(map headers = {}, *ListAssistantsQueries queries) returns ListAssistantsResponse|error { + string resourcePath = string `/assistants`; + resourcePath = resourcePath + check getPathForQueryParam(queries); + return self.clientEp->get(resourcePath, headers); + } + + # Create an assistant with a model and instructions. + # + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post assistants(CreateAssistantRequest payload, map headers = {}) returns AssistantObject|error { + string resourcePath = string `/assistants`; http:Request request = new; - json jsonBody = payload.toJson(); + json jsonBody = jsondata:toJson(payload); request.setPayload(jsonBody, "application/json"); return self.clientEp->post(resourcePath, request, headers); } - # Immediately cancel a fine-tune job. + # Retrieves an assistant. + # + # + assistantId - The ID of the assistant to retrieve + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function get assistants/[string assistantId](map headers = {}) returns AssistantObject|error { + string resourcePath = string `/assistants/${getEncodedUri(assistantId)}`; + return self.clientEp->get(resourcePath, headers); + } + + # Modifies an assistant. + # + # + assistantId - The ID of the assistant to modify + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post assistants/[string assistantId](ModifyAssistantRequest payload, map headers = {}) returns AssistantObject|error { + string resourcePath = string `/assistants/${getEncodedUri(assistantId)}`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Delete an assistant. + # + # + assistantId - The ID of the assistant to delete + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function delete assistants/[string assistantId](map headers = {}) returns DeleteAssistantResponse|error { + string resourcePath = string `/assistants/${getEncodedUri(assistantId)}`; + return self.clientEp->delete(resourcePath, headers = headers); + } + + # Create a thread. + # + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post threads(CreateThreadRequest payload, map headers = {}) returns ThreadObject|error { + string resourcePath = string `/threads`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Retrieves a thread. + # + # + threadId - The ID of the thread to retrieve + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function get threads/[string threadId](map headers = {}) returns ThreadObject|error { + string resourcePath = string `/threads/${getEncodedUri(threadId)}`; + return self.clientEp->get(resourcePath, headers); + } + + # Modifies a thread. + # + # + threadId - The ID of the thread to modify. Only the `metadata` can be modified + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post threads/[string threadId](ModifyThreadRequest payload, map headers = {}) returns ThreadObject|error { + string resourcePath = string `/threads/${getEncodedUri(threadId)}`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Delete a thread. + # + # + threadId - The ID of the thread to delete + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function delete threads/[string threadId](map headers = {}) returns DeleteThreadResponse|error { + string resourcePath = string `/threads/${getEncodedUri(threadId)}`; + return self.clientEp->delete(resourcePath, headers = headers); + } + + # Returns a list of messages for a given thread. + # + # + threadId - The ID of the [thread](/docs/api-reference/threads) the messages belong to + # + headers - Headers to be sent with the request + # + queries - Queries to be sent with the request + # + return - OK + resource isolated function get threads/[string threadId]/messages(map headers = {}, *ListMessagesQueries queries) returns ListMessagesResponse|error { + string resourcePath = string `/threads/${getEncodedUri(threadId)}/messages`; + resourcePath = resourcePath + check getPathForQueryParam(queries); + return self.clientEp->get(resourcePath, headers); + } + + # Create a message. + # + # + threadId - The ID of the [thread](/docs/api-reference/threads) to create a message for + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post threads/[string threadId]/messages(CreateMessageRequest payload, map headers = {}) returns MessageObject|error { + string resourcePath = string `/threads/${getEncodedUri(threadId)}/messages`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Retrieve a message. + # + # + threadId - The ID of the [thread](/docs/api-reference/threads) to which this message belongs + # + messageId - The ID of the message to retrieve + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function get threads/[string threadId]/messages/[string messageId](map headers = {}) returns MessageObject|error { + string resourcePath = string `/threads/${getEncodedUri(threadId)}/messages/${getEncodedUri(messageId)}`; + return self.clientEp->get(resourcePath, headers); + } + + # Modifies a message. + # + # + threadId - The ID of the thread to which this message belongs + # + messageId - The ID of the message to modify + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post threads/[string threadId]/messages/[string messageId](ModifyMessageRequest payload, map headers = {}) returns MessageObject|error { + string resourcePath = string `/threads/${getEncodedUri(threadId)}/messages/${getEncodedUri(messageId)}`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Deletes a message. + # + # + threadId - The ID of the thread to which this message belongs + # + messageId - The ID of the message to delete + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function delete threads/[string threadId]/messages/[string messageId](map headers = {}) returns DeleteMessageResponse|error { + string resourcePath = string `/threads/${getEncodedUri(threadId)}/messages/${getEncodedUri(messageId)}`; + return self.clientEp->delete(resourcePath, headers = headers); + } + + # Create a thread and run it in one request. + # + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post threads/runs(CreateThreadAndRunRequest payload, map headers = {}) returns RunObject|error { + string resourcePath = string `/threads/runs`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Returns a list of runs belonging to a thread. + # + # + threadId - The ID of the thread the run belongs to + # + headers - Headers to be sent with the request + # + queries - Queries to be sent with the request + # + return - OK + resource isolated function get threads/[string threadId]/runs(map headers = {}, *ListRunsQueries queries) returns ListRunsResponse|error { + string resourcePath = string `/threads/${getEncodedUri(threadId)}/runs`; + resourcePath = resourcePath + check getPathForQueryParam(queries); + return self.clientEp->get(resourcePath, headers); + } + + # Create a run. + # + # + threadId - The ID of the thread to run + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post threads/[string threadId]/runs(CreateRunRequest payload, map headers = {}) returns RunObject|error { + string resourcePath = string `/threads/${getEncodedUri(threadId)}/runs`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Retrieves a run. + # + # + threadId - The ID of the [thread](/docs/api-reference/threads) that was run + # + runId - The ID of the run to retrieve + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function get threads/[string threadId]/runs/[string runId](map headers = {}) returns RunObject|error { + string resourcePath = string `/threads/${getEncodedUri(threadId)}/runs/${getEncodedUri(runId)}`; + return self.clientEp->get(resourcePath, headers); + } + + # Modifies a run. + # + # + threadId - The ID of the [thread](/docs/api-reference/threads) that was run + # + runId - The ID of the run to modify + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post threads/[string threadId]/runs/[string runId](ModifyRunRequest payload, map headers = {}) returns RunObject|error { + string resourcePath = string `/threads/${getEncodedUri(threadId)}/runs/${getEncodedUri(runId)}`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # When a run has the `status: "requires_action"` and `required_action.type` is `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request. + # + # + threadId - The ID of the [thread](/docs/api-reference/threads) to which this run belongs + # + runId - The ID of the run that requires the tool output submission + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post threads/[string threadId]/runs/[string runId]/submit_tool_outputs(SubmitToolOutputsRunRequest payload, map headers = {}) returns RunObject|error { + string resourcePath = string `/threads/${getEncodedUri(threadId)}/runs/${getEncodedUri(runId)}/submit_tool_outputs`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Cancels a run that is `in_progress`. + # + # + threadId - The ID of the thread to which this run belongs + # + runId - The ID of the run to cancel + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post threads/[string threadId]/runs/[string runId]/cancel(map headers = {}) returns RunObject|error { + string resourcePath = string `/threads/${getEncodedUri(threadId)}/runs/${getEncodedUri(runId)}/cancel`; + http:Request request = new; + return self.clientEp->post(resourcePath, request, headers); + } + + # Returns a list of run steps belonging to a run. + # + # + threadId - The ID of the thread the run and run steps belong to + # + runId - The ID of the run the run steps belong to + # + headers - Headers to be sent with the request + # + queries - Queries to be sent with the request + # + return - OK + resource isolated function get threads/[string threadId]/runs/[string runId]/steps(map headers = {}, *ListRunStepsQueries queries) returns ListRunStepsResponse|error { + string resourcePath = string `/threads/${getEncodedUri(threadId)}/runs/${getEncodedUri(runId)}/steps`; + resourcePath = resourcePath + check getPathForQueryParam(queries); + return self.clientEp->get(resourcePath, headers); + } + + # Retrieves a run step. + # + # + threadId - The ID of the thread to which the run and run step belongs + # + runId - The ID of the run to which the run step belongs + # + stepId - The ID of the run step to retrieve + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function get threads/[string threadId]/runs/[string runId]/steps/[string stepId](map headers = {}) returns RunStepObject|error { + string resourcePath = string `/threads/${getEncodedUri(threadId)}/runs/${getEncodedUri(runId)}/steps/${getEncodedUri(stepId)}`; + return self.clientEp->get(resourcePath, headers); + } + + # Returns a list of vector stores. + # + # + headers - Headers to be sent with the request + # + queries - Queries to be sent with the request + # + return - OK + resource isolated function get vector_stores(map headers = {}, *ListVectorStoresQueries queries) returns ListVectorStoresResponse|error { + string resourcePath = string `/vector_stores`; + resourcePath = resourcePath + check getPathForQueryParam(queries); + return self.clientEp->get(resourcePath, headers); + } + + # Create a vector store. + # + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post vector_stores(CreateVectorStoreRequest payload, map headers = {}) returns VectorStoreObject|error { + string resourcePath = string `/vector_stores`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Retrieves a vector store. + # + # + vectorStoreId - The ID of the vector store to retrieve + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function get vector_stores/[string vectorStoreId](map headers = {}) returns VectorStoreObject|error { + string resourcePath = string `/vector_stores/${getEncodedUri(vectorStoreId)}`; + return self.clientEp->get(resourcePath, headers); + } + + # Modifies a vector store. + # + # + vectorStoreId - The ID of the vector store to modify + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post vector_stores/[string vectorStoreId](UpdateVectorStoreRequest payload, map headers = {}) returns VectorStoreObject|error { + string resourcePath = string `/vector_stores/${getEncodedUri(vectorStoreId)}`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Delete a vector store. + # + # + vectorStoreId - The ID of the vector store to delete + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function delete vector_stores/[string vectorStoreId](map headers = {}) returns DeleteVectorStoreResponse|error { + string resourcePath = string `/vector_stores/${getEncodedUri(vectorStoreId)}`; + return self.clientEp->delete(resourcePath, headers = headers); + } + + # Returns a list of vector store files. + # + # + vectorStoreId - The ID of the vector store that the files belong to + # + headers - Headers to be sent with the request + # + queries - Queries to be sent with the request + # + return - OK + resource isolated function get vector_stores/[string vectorStoreId]/files(map headers = {}, *ListVectorStoreFilesQueries queries) returns ListVectorStoreFilesResponse|error { + string resourcePath = string `/vector_stores/${getEncodedUri(vectorStoreId)}/files`; + resourcePath = resourcePath + check getPathForQueryParam(queries); + return self.clientEp->get(resourcePath, headers); + } + + # Create a vector store file by attaching a [File](/docs/api-reference/files) to a [vector store](/docs/api-reference/vector-stores/object). + # + # + vectorStoreId - The ID of the vector store for which to create a File + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post vector_stores/[string vectorStoreId]/files(CreateVectorStoreFileRequest payload, map headers = {}) returns VectorStoreFileObject|error { + string resourcePath = string `/vector_stores/${getEncodedUri(vectorStoreId)}/files`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Retrieves a vector store file. + # + # + vectorStoreId - The ID of the vector store that the file belongs to + # + fileId - The ID of the file being retrieved + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function get vector_stores/[string vectorStoreId]/files/[string fileId](map headers = {}) returns VectorStoreFileObject|error { + string resourcePath = string `/vector_stores/${getEncodedUri(vectorStoreId)}/files/${getEncodedUri(fileId)}`; + return self.clientEp->get(resourcePath, headers); + } + + # Delete a vector store file. This will remove the file from the vector store but the file itself will not be deleted. To delete the file, use the [delete file](/docs/api-reference/files/delete) endpoint. + # + # + vectorStoreId - The ID of the vector store that the file belongs to + # + fileId - The ID of the file to delete + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function delete vector_stores/[string vectorStoreId]/files/[string fileId](map headers = {}) returns DeleteVectorStoreFileResponse|error { + string resourcePath = string `/vector_stores/${getEncodedUri(vectorStoreId)}/files/${getEncodedUri(fileId)}`; + return self.clientEp->delete(resourcePath, headers = headers); + } + + # Create a vector store file batch. + # + # + vectorStoreId - The ID of the vector store for which to create a File Batch + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post vector_stores/[string vectorStoreId]/file_batches(CreateVectorStoreFileBatchRequest payload, map headers = {}) returns VectorStoreFileBatchObject|error { + string resourcePath = string `/vector_stores/${getEncodedUri(vectorStoreId)}/file_batches`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Retrieves a vector store file batch. + # + # + vectorStoreId - The ID of the vector store that the file batch belongs to + # + batchId - The ID of the file batch being retrieved + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function get vector_stores/[string vectorStoreId]/file_batches/[string batchId](map headers = {}) returns VectorStoreFileBatchObject|error { + string resourcePath = string `/vector_stores/${getEncodedUri(vectorStoreId)}/file_batches/${getEncodedUri(batchId)}`; + return self.clientEp->get(resourcePath, headers); + } + + # Cancel a vector store file batch. This attempts to cancel the processing of files in this batch as soon as possible. + # + # + vectorStoreId - The ID of the vector store that the file batch belongs to + # + batchId - The ID of the file batch to cancel + # + headers - Headers to be sent with the request + # + return - OK + resource isolated function post vector_stores/[string vectorStoreId]/file_batches/[string batchId]/cancel(map headers = {}) returns VectorStoreFileBatchObject|error { + string resourcePath = string `/vector_stores/${getEncodedUri(vectorStoreId)}/file_batches/${getEncodedUri(batchId)}/cancel`; + http:Request request = new; + return self.clientEp->post(resourcePath, request, headers); + } + + # Returns a list of vector store files in a batch. + # + # + vectorStoreId - The ID of the vector store that the files belong to + # + batchId - The ID of the file batch that the files belong to + # + headers - Headers to be sent with the request + # + queries - Queries to be sent with the request + # + return - OK + resource isolated function get vector_stores/[string vectorStoreId]/file_batches/[string batchId]/files(map headers = {}, *ListFilesInVectorStoreBatchQueries queries) returns ListVectorStoreFilesResponse|error { + string resourcePath = string `/vector_stores/${getEncodedUri(vectorStoreId)}/file_batches/${getEncodedUri(batchId)}/files`; + resourcePath = resourcePath + check getPathForQueryParam(queries); + return self.clientEp->get(resourcePath, headers); + } + + # List your organization's batches. + # + # + headers - Headers to be sent with the request + # + queries - Queries to be sent with the request + # + return - Batch listed successfully + resource isolated function get batches(map headers = {}, *ListBatchesQueries queries) returns ListBatchesResponse|error { + string resourcePath = string `/batches`; + resourcePath = resourcePath + check getPathForQueryParam(queries); + return self.clientEp->get(resourcePath, headers); + } + + # Creates and executes a batch from an uploaded file of requests + # + # + headers - Headers to be sent with the request + # + return - Batch created successfully + resource isolated function post batches(BatchesBody payload, map headers = {}) returns Batch|error { + string resourcePath = string `/batches`; + http:Request request = new; + json jsonBody = jsondata:toJson(payload); + request.setPayload(jsonBody, "application/json"); + return self.clientEp->post(resourcePath, request, headers); + } + + # Retrieves a batch. + # + # + batchId - The ID of the batch to retrieve + # + headers - Headers to be sent with the request + # + return - Batch retrieved successfully + resource isolated function get batches/[string batchId](map headers = {}) returns Batch|error { + string resourcePath = string `/batches/${getEncodedUri(batchId)}`; + return self.clientEp->get(resourcePath, headers); + } + + # Cancels an in-progress batch. The batch will be in status `cancelling` for up to 10 minutes, before changing to `cancelled`, where it will have partial results (if any) available in the output file. # - # + fine_tuning_job_id - The ID of the fine-tuning job to cancel. - # + headers - Headers to be sent with the request - # + return - OK - resource isolated function post fine_tuning/jobs/[string fine_tuning_job_id]/cancel(map headers = {}) returns FineTuningJob|error { - string resourcePath = string `/fine_tuning/jobs/${getEncodedUri(fine_tuning_job_id)}/cancel`; + # + batchId - The ID of the batch to cancel + # + headers - Headers to be sent with the request + # + return - Batch is cancelling. Returns the cancelling batch's details + resource isolated function post batches/[string batchId]/cancel(map headers = {}) returns Batch|error { + string resourcePath = string `/batches/${getEncodedUri(batchId)}/cancel`; http:Request request = new; return self.clientEp->post(resourcePath, request, headers); } diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal index 47f5b7e..75e98f4 100644 --- a/ballerina/tests/mock_service.bal +++ b/ballerina/tests/mock_service.bal @@ -36,7 +36,7 @@ http:Service mockService = service object { # Delete a fine-tuned model. You must have the Owner role in your organization to delete a model. # # + model - The model to delete - # + return - OK + # + return - OK resource function delete models/[string model]() returns DeleteModelResponse { DeleteModelResponse response = { @@ -51,33 +51,33 @@ http:Service mockService = service object { # Immediately cancel a fine-tune job. # # + fine_tuning_job_id - The ID of the fine-tuning job to cancel. - # + return - OK + # + return - OK resource function post fine_tuning/jobs/[string fine_tuning_job_id]/cancel() returns OkFineTuningJob { OkFineTuningJob response = { body: { - "object": "fine_tuning.job", - "id": fine_tuning_job_id, - "model": "gpt-3.5-turbo-0125", - "created_at": 1723110882, - "finished_at": null, - "fine_tuned_model": null, - "organization_id": "org-Gzp0rlPk9gw4JaNXmPqDJ1H4", - "result_files": [], - "status": "validating_files", - "validation_file": null, - "training_file": "file-JZMH9Xxnt7Hg2io6N2kzmlzM", - "hyperparameters": { - "n_epochs": "auto", - "batch_size": "auto", - "learning_rate_multiplier": "auto" + 'object: "fine_tuning.job", + id: fine_tuning_job_id, + model: "gpt-3.5-turbo-0125", + createdAt: 1723110882, + finishedAt: (), + fineTunedModel: (), + organizationId: "org-Gzp0rlPk9gw4JaNXmPqDJ1H4", + resultFiles: [], + status: "validating_files", + validationFile: (), + trainingFile: "file-JZMH9Xxnt7Hg2io6N2kzmlzM", + hyperparameters: { + nEpochs: "auto", + "batchSize": "auto", + "learningRateMultiplier": "auto" }, - "trained_tokens": null, - "error": {}, - "user_provided_suffix": null, - "seed": 1776549854, - "estimated_finish": null, - "integrations": [] + trainedTokens: (), + 'error: {}, + "userProvidedSuffix": (), + seed: 1776549854, + estimatedFinish: (), + integrations: [] }, headers: { "Content-Type": "application/json" @@ -90,7 +90,7 @@ http:Service mockService = service object { # Delete a file. # # + file_id - The ID of the file to use for this request. - # + return - OK + # + return - OK resource function delete files/[string file_id]() returns DeleteFileResponse { DeleteFileResponse response = { @@ -105,7 +105,7 @@ http:Service mockService = service object { # Returns a list of files that belong to the user's organization. # # + purpose - Only return files with the given purpose. - # + return - OK + # + return - OK resource function get files(string? purpose) returns ListFilesResponse { ListFilesResponse response = { @@ -119,7 +119,7 @@ http:Service mockService = service object { bytes: 71, created_at: 1723097702, status: "processed", - status_details: null + status_details: () }, { 'object: "file", @@ -129,7 +129,7 @@ http:Service mockService = service object { bytes: 71, created_at: 1723097702, status: "processed", - status_details: null + status_details: () } ] }; @@ -140,7 +140,7 @@ http:Service mockService = service object { # Returns information about a specific file. # # + file_id - The ID of the file to use for this request. - # + return - OK + # + return - OK resource function get files/[string file_id]() returns OpenAIFile { OpenAIFile response = { @@ -151,7 +151,7 @@ http:Service mockService = service object { bytes: 71, created_at: 1723097702, status: "processed", - status_details: null + status_details: () }; return response; @@ -160,7 +160,7 @@ http:Service mockService = service object { # Returns the contents of the specified file. # # + file_id - The ID of the file to use for this request. - # + return - OK + # + return - OK resource function get files/[string file_id]/content() returns byte[] { byte[] response = [123, 34, 116, 101, 120, 116, 34, 58, 34, 72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 34, 125]; @@ -172,42 +172,42 @@ http:Service mockService = service object { # # + after - Identifier for the last job from the previous pagination request. # + 'limit - Number of fine-tuning jobs to retrieve. - # + return - OK + # + return - OK resource function get fine_tuning/jobs(string? after, int 'limit = 20) returns ListPaginatedFineTuningJobsResponse { ListPaginatedFineTuningJobsResponse response = { - "object": "list", - "data": [ + 'object: "list", + data: [ { - "object": "fine_tuning.job", - "id": "ftjob-G0rwrYUnRwEWPjDRvxByxPxU", - "model": "gpt-3.5-turbo-0125", - "created_at": 1723097706, - "finished_at": null, - "fine_tuned_model": null, - "organization_id": "org-Gzp0rlPk9gw4JaNXmPqDJ1H4", - "result_files": [], - "status": "failed", - "validation_file": null, - "training_file": "file-JZMH9Xxnt7Hg2io6N2kzmlzM", - "hyperparameters": { - "n_epochs": "auto", - "batch_size": "auto", - "learning_rate_multiplier": "auto" + 'object: "fine_tuning.job", + id: "ftjob-G0rwrYUnRwEWPjDRvxByxPxU", + model: "gpt-3.5-turbo-0125", + createdAt: 1723097706, + finishedAt: (), + fineTunedModel: (), + organizationId: "org-Gzp0rlPk9gw4JaNXmPqDJ1H4", + resultFiles: [], + status: "failed", + validationFile: (), + trainingFile: "file-JZMH9Xxnt7Hg2io6N2kzmlzM", + hyperparameters: { + nEpochs: "auto", + "batchSize": "auto", + "learningRateMultiplier": "auto" }, - "trained_tokens": null, - "error": { - "code": "invalid_training_file", - "param": "training_file", - "message": "The job failed due to an invalid training file. Expected file to have JSONL format, where every line is a valid JSON dictionary. Line 1 is not a dictionary." + trainedTokens: (), + 'error: { + code: "invalid_training_file", + param: "training_file", + message: "The job failed due to an invalid training file. Expected file to have JSONL format, where every line is a valid JSON dictionary. Line 1 is not a dictionary." }, - "user_provided_suffix": null, - "seed": 1913581589, - "estimated_finish": null, - "integrations": [] + "userProvidedSuffix": (), + seed: 1913581589, + estimatedFinish: (), + integrations: [] } ], - "has_more": false + hasMore: false }; return response; @@ -218,36 +218,36 @@ http:Service mockService = service object { # [Learn more about fine-tuning](/docs/guides/fine-tuning) # # + fine_tuning_job_id - The ID of the fine-tuning job. - # + return - OK + # + return - OK resource function get fine_tuning/jobs/[string fine_tuning_job_id]() returns FineTuningJob { FineTuningJob response = { - "object": "fine_tuning.job", - "id": fine_tuning_job_id, - "model": "gpt-3.5-turbo-0125", - "created_at": 1723097706, - "finished_at": null, - "fine_tuned_model": null, - "organization_id": "org-Gzp0rlPk9gw4JaNXmPqDJ1H4", - "result_files": [], - "status": "failed", - "validation_file": null, - "training_file": "file-JZMH9Xxnt7Hg2io6N2kzmlzM", - "hyperparameters": { - "n_epochs": "auto", - "batch_size": "auto", - "learning_rate_multiplier": "auto" + 'object: "fine_tuning.job", + id: fine_tuning_job_id, + model: "gpt-3.5-turbo-0125", + createdAt: 1723097706, + finishedAt: (), + fineTunedModel: (), + organizationId: "org-Gzp0rlPk9gw4JaNXmPqDJ1H4", + resultFiles: [], + status: "failed", + validationFile: (), + trainingFile: "file-JZMH9Xxnt7Hg2io6N2kzmlzM", + hyperparameters: { + nEpochs: "auto", + "batchSize": "auto", + "learningRateMultiplier": "auto" }, - "trained_tokens": null, - "error": { - "code": "invalid_training_file", - "param": "training_file", - "message": "The job failed due to an invalid training file. Expected file to have JSONL format, where every line is a valid JSON dictionary. Line 1 is not a dictionary." + trainedTokens: (), + 'error: { + code: "invalid_training_file", + param: "training_file", + message: "The job failed due to an invalid training file. Expected file to have JSONL format, where every line is a valid JSON dictionary. Line 1 is not a dictionary." }, - "user_provided_suffix": null, - "seed": 1913581589, - "estimated_finish": null, - "integrations": [] + "userProvidedSuffix": (), + seed: 1913581589, + estimatedFinish: (), + integrations: [] }; return response; @@ -258,25 +258,25 @@ http:Service mockService = service object { # + fine_tuning_job_id - The ID of the fine-tuning job to get checkpoints for. # + after - Identifier for the last checkpoint ID from the previous pagination request. # + 'limit - Number of checkpoints to retrieve. - # + return - OK + # + return - OK resource function get fine_tuning/jobs/[string fine_tuning_job_id]/checkpoints(string? after, int 'limit = 10) returns ListFineTuningJobCheckpointsResponse { ListFineTuningJobCheckpointsResponse response = { - "object": "list", - "data": [ + 'object: "list", + data: [ { - "id": "checkpoint-1", - "created_at": 1723110882, - "object": "fine_tuning.job.checkpoint", - "fine_tuned_model_checkpoint": "gpt-3.5-turbo-0125-1", - "fine_tuning_job_id": fine_tuning_job_id, - "metrics": { - "step": 1 + id: "checkpoint-1", + createdAt: 1723110882, + 'object: "fine_tuning.job.checkpoint", + fineTunedModelCheckpoint: "gpt-3.5-turbo-0125-1", + fineTuningJobId: fine_tuning_job_id, + metrics: { + step: 1 }, - "step_number": 2 + stepNumber: 2 } ], - "has_more": false + hasMore: false }; return response; @@ -287,18 +287,18 @@ http:Service mockService = service object { # + fine_tuning_job_id - The ID of the fine-tuning job to get events for. # + after - Identifier for the last event from the previous pagination request. # + 'limit - Number of events to retrieve. - # + return - OK + # + return - OK resource function get fine_tuning/jobs/[string fine_tuning_job_id]/events(string? after, int 'limit = 20) returns ListFineTuningJobEventsResponse { ListFineTuningJobEventsResponse response = { "object": "list", "data": [ { - "id": fine_tuning_job_id, - "created_at": 1723110882, - "level": "warn", - "message": "Fine-tuning job started.", - "object": "fine_tuning.job.event" + id: fine_tuning_job_id, + createdAt: 1723110882, + level: "warn", + message: "Fine-tuning job started.", + 'object: "fine_tuning.job.event" } ] }; @@ -308,7 +308,7 @@ http:Service mockService = service object { # Lists the currently available models, and provides basic information about each one such as the owner and availability. # - # + return - OK + # + return - OK resource function get models() returns ListModelsResponse { ListModelsResponse response = { @@ -335,7 +335,7 @@ http:Service mockService = service object { # Retrieves a model instance, providing basic information about the model such as the owner and permissioning. # # + model - The ID of the model to use for this request - # + return - OK + # + return - OK resource function get models/[string model]() returns Model { Model response = { @@ -358,7 +358,7 @@ http:Service mockService = service object { # # Please [contact us](https://help.openai.com/) if you need to increase these storage limits. # - # + return - OK + # + return - OK resource function post files(http:Request request) returns OkOpenAIFile { OkOpenAIFile response = { @@ -370,7 +370,7 @@ http:Service mockService = service object { bytes: 71, created_at: 1723097702, status: "processed", - status_details: null + status_details: () }, headers: { "Content-Type": "application/json" @@ -386,33 +386,33 @@ http:Service mockService = service object { # # [Learn more about fine-tuning](/docs/guides/fine-tuning) # - # + return - OK + # + return - OK resource function post fine_tuning/jobs(@http:Payload CreateFineTuningJobRequest payload) returns OkFineTuningJob { OkFineTuningJob response = { body: { - "object": "fine_tuning.job", - "id": "ftjob-5NikxOY1BsPHxt8Z8YBm8AX1", - "model": "gpt-3.5-turbo-0125", - "created_at": 1723110882, - "finished_at": null, - "fine_tuned_model": null, - "organization_id": "org-Gzp0rlPk9gw4JaNXmPqDJ1H4", - "result_files": [], - "status": "validating_files", - "validation_file": null, - "training_file": "file-JZMH9Xxnt7Hg2io6N2kzmlzM", - "hyperparameters": { - "n_epochs": "auto", - "batch_size": "auto", - "learning_rate_multiplier": "auto" + 'object: "fine_tuning.job", + id: "ftjob-5NikxOY1BsPHxt8Z8YBm8AX1", + model: "gpt-3.5-turbo-0125", + createdAt: 1723110882, + finishedAt: (), + fineTunedModel: (), + organizationId: "org-Gzp0rlPk9gw4JaNXmPqDJ1H4", + resultFiles: [], + status: "validating_files", + validationFile: (), + trainingFile: "file-JZMH9Xxnt7Hg2io6N2kzmlzM", + hyperparameters: { + nEpochs: "auto", + "batchSize": "auto", + "learningRateMultiplier": "auto" }, - "trained_tokens": null, - "error": {}, - "user_provided_suffix": null, - "seed": 1776549854, - "estimated_finish": null, - "integrations": [] + trainedTokens: (), + 'error: {}, + "userProvidedSuffix": (), + seed: 1776549854, + estimatedFinish: (), + integrations: [] }, headers: { "Content-Type": "application/json" @@ -426,7 +426,7 @@ http:Service mockService = service object { function init() returns error? { if isLiveServer { - log:printInfo("Skiping mock server initialization as the tests are running on live server"); + log:printInfo("Skipping mock server initialization as the tests are running on live server"); return; } diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index c286cdd..1954a5d 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -134,7 +134,7 @@ function testListPaginatedFineTuningJobs() returns error? { function testCreateFineTuningJob() returns error? { CreateFineTuningJobRequest fineTuneRequest = { model: modelId, - training_file: fileId + trainingFile: fileId }; FineTuningJob fineTuneResponse = check openAIFinetunes->/fine_tuning/jobs.post(fineTuneRequest); diff --git a/ballerina/types.bal b/ballerina/types.bal index 093632d..584639c 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -17,169 +17,149 @@ // specific language governing permissions and limitations // under the License. +import ballerina/constraint; +import ballerina/data.jsondata; import ballerina/http; -# The `File` object represents a document that has been uploaded to OpenAI. -public type OpenAIFile record { - # The file identifier, which can be referenced in the API endpoints. - string id; - # The size of the file, in bytes. - int bytes; - # The Unix timestamp (in seconds) for when the file was created. - int created_at; - # The name of the file. - string filename; - # The object type, which is always `file`. - "file" 'object; - # The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results` and `vision`. - "assistants"|"assistants_output"|"batch"|"batch_output"|"fine-tune"|"fine-tune-results"|"vision" purpose; - # Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`. - # - # # Deprecated - @deprecated - "uploaded"|"processed"|"error" status; - # Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`. - string? status_details?; -}; - -public type CreateFineTuningJobRequest record { - # The name of the model to fine-tune. You can select one of the - # [supported models](/docs/guides/fine-tuning/what-models-can-be-fine-tuned). - string|"babbage-002"|"davinci-002"|"gpt-3.5-turbo" model; - # The ID of an uploaded file that contains training data. - # - # See [upload file](/docs/api-reference/files/create) for how to upload a file. - # - # Your dataset must be formatted as a JSONL file. Additionally, you must upload your file with the purpose `fine-tune`. - # - # The contents of the file should differ depending on if the model uses the [chat](/docs/api-reference/fine-tuning/chat-input) or [completions](/docs/api-reference/fine-tuning/completions-input) format. - # - # See the [fine-tuning guide](/docs/guides/fine-tuning) for more details. - string training_file; - CreateFineTuningJobRequest_hyperparameters hyperparameters?; - # A string of up to 18 characters that will be added to your fine-tuned model name. - # - # For example, a `suffix` of "custom-model-name" would produce a model name like `ft:gpt-3.5-turbo:openai:custom-model-name:7p4lURel`. - string? suffix?; - # The ID of an uploaded file that contains validation data. - # - # If you provide this file, the data is used to generate validation - # metrics periodically during fine-tuning. These metrics can be viewed in - # the fine-tuning results file. - # The same data should not be present in both train and validation files. - # - # Your dataset must be formatted as a JSONL file. You must upload your file with the purpose `fine-tune`. - # - # See the [fine-tuning guide](/docs/guides/fine-tuning) for more details. - string? validation_file?; - # A list of integrations to enable for your fine-tuning job. - CreateFineTuningJobRequest_integrations[]? integrations?; - # The seed controls the reproducibility of the job. Passing in the same seed and job parameters should produce the same results, but may differ in rare cases. - # If a seed is not specified, one will be generated for you. - int? seed?; +# The request counts for different statuses within the batch +public type BatchRequestCounts record { + # Total number of requests in the batch + int total; + # Number of requests that have been completed successfully + int completed; + # Number of requests that have failed + int failed; }; -# The `fine_tuning.job.checkpoint` object represents a model checkpoint for a fine-tuning job that is ready to use. +# The `fine_tuning.job.checkpoint` object represents a model checkpoint for a fine-tuning job that is ready to use public type FineTuningJobCheckpoint record { - # The checkpoint identifier, which can be referenced in the API endpoints. + # The step number that the checkpoint was created at + @jsondata:Name {value: "step_number"} + int stepNumber; + # The Unix timestamp (in seconds) for when the checkpoint was created + @jsondata:Name {value: "created_at"} + int createdAt; + # The name of the fine-tuning job that this checkpoint was created from + @jsondata:Name {value: "fine_tuning_job_id"} + string fineTuningJobId; + # The checkpoint identifier, which can be referenced in the API endpoints string id; - # The Unix timestamp (in seconds) for when the checkpoint was created. - int created_at; - # The name of the fine-tuned checkpoint model that is created. - string fine_tuned_model_checkpoint; - # The step number that the checkpoint was created at. - int step_number; - FineTuningJobCheckpoint_metrics metrics; - # The name of the fine-tuning job that this checkpoint was created from. - string fine_tuning_job_id; - # The object type, which is always "fine_tuning.job.checkpoint". + FineTuningJobCheckpointMetrics metrics; + # The name of the fine-tuned checkpoint model that is created + @jsondata:Name {value: "fine_tuned_model_checkpoint"} + string fineTunedModelCheckpoint; + # The object type, which is always "fine_tuning.job.checkpoint" "fine_tuning.job.checkpoint" 'object; }; -public type ListPaginatedFineTuningJobsResponse record { - FineTuningJob[] data; - boolean has_more; - "list" 'object; -}; - -# The hyperparameters used for the fine-tuning job. -public type CreateFineTuningJobRequest_hyperparameters record { - # Number of examples in each batch. A larger batch size means that model parameters - # are updated less frequently, but with lower variance. - "auto"|int batch_size = "auto"; - # Scaling factor for the learning rate. A smaller learning rate may be useful to avoid - # overfitting. - "auto"|decimal learning_rate_multiplier = "auto"; - # The number of epochs to train the model for. An epoch refers to one full cycle - # through the training dataset. - "auto"|int n_epochs = "auto"; -}; +# `none` means the model will not call any tools and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `required` means the model must call one or more tools before responding to the user +public type AssistantsApiToolChoiceOptionOneOf1 "none"|"auto"|"required"; -# Represents the Queries record for the operation: listFineTuningEvents -public type ListFineTuningEventsQueries record { - # Number of events to retrieve. - int 'limit = 20; - # Identifier for the last event from the previous pagination request. - string after?; +public type ListRunsResponse record { + @jsondata:Name {value: "first_id"} + string firstId; + RunObject[] data; + @jsondata:Name {value: "last_id"} + string lastId; + @jsondata:Name {value: "has_more"} + boolean hasMore; + string 'object; }; -# Represents the Queries record for the operation: listFineTuningJobCheckpoints -public type ListFineTuningJobCheckpointsQueries record { - # Number of checkpoints to retrieve. - int 'limit = 10; - # Identifier for the last checkpoint ID from the previous pagination request. - string after?; -}; +# Specifies the format that the model must output. Compatible with [GPT-4o](/docs/models/gpt-4o), [GPT-4 Turbo](/docs/models/gpt-4-turbo-and-gpt-4), and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`. +# +# Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is valid JSON. +# +# **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length +public type AssistantsApiResponseFormatOption AssistantsApiResponseFormatOptionOneOf1|AssistantsApiResponseFormat; -# The settings for your integration with Weights and Biases. This payload specifies the project that -# metrics will be sent to. Optionally, you can set an explicit display name for your run, add tags -# to your run, and set a default entity (team, username, etc) to be associated with your run. -public type CreateFineTuningJobRequest_wandb record { - # The name of the project that the new run will be created under. - string project; - # A display name to set for the run. If not set, we will use the Job ID as the name. - string? name?; - # The entity to use for the run. This allows you to set the team or username of the WandB user that you would - # like associated with the run. If not set, the default entity for the registered WandB API key is used. - string? entity?; - # A list of tags to be attached to the newly created run. These tags are passed through directly to WandB. Some - # default tags are generated by OpenAI: "openai/finetune", "openai/{base-model}", "openai/{ftjob-abcdef}". - string[] tags?; +public type RunStepDetailsToolCallsFunctionObject record { + RunStepDetailsToolCallsFunctionObjectFunction 'function; + # The ID of the tool call object + string id; + # The type of tool call. This is always going to be `function` for this type of tool call + "function" 'type; }; -# The hyperparameters used for the fine-tuning job. See the [fine-tuning guide](/docs/guides/fine-tuning) for more details. -public type FineTuningJob_hyperparameters record { - # The number of epochs to train the model for. An epoch refers to one full cycle through the training dataset. - # "auto" decides the optimal number of epochs based on the size of the dataset. If setting the number manually, we support any number between 1 and 50 epochs. - "auto"|int n_epochs; -}; +public type CreateRunRequest record {| + # Overrides the [instructions](/docs/api-reference/assistants/createAssistant) of the assistant. This is useful for modifying the behavior on a per-run basis + string? instructions?; + # Appends additional instructions at the end of the instructions for the run. This is useful for modifying the behavior on a per-run basis without overriding other instructions + @jsondata:Name {value: "additional_instructions"} + string? additionalInstructions?; + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata?; + # The ID of the [assistant](/docs/api-reference/assistants) to use to execute this run + @jsondata:Name {value: "assistant_id"} + string assistantId; + # Adds additional messages to the thread before creating the run + @jsondata:Name {value: "additional_messages"} + CreateMessageRequest[]? additionalMessages?; + # Override the tools the assistant can use for this run. This is useful for modifying the behavior on a per-run basis + CreateRunRequestTools[]? tools?; + @jsondata:Name {value: "truncation_strategy"} + TruncationObject truncationStrategy?; + # An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + # + # We generally recommend altering this or temperature but not both + @jsondata:Name {value: "top_p"} + decimal? topP = 1; + # The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort to use only the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of completion tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info + @jsondata:Name {value: "max_completion_tokens"} + int? maxCompletionTokens?; + @jsondata:Name {value: "response_format"} + AssistantsApiResponseFormatOption responseFormat?; + @jsondata:Name {value: "parallel_tool_calls"} + ParallelToolCalls parallelToolCalls?; + # If `true`, returns a stream of events that happen during the Run as server-sent events, terminating when the Run enters a terminal state with a `data: [DONE]` message + boolean? 'stream?; + # What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic + decimal? temperature = 1; + @jsondata:Name {value: "tool_choice"} + AssistantsApiToolChoiceOption toolChoice?; + # The ID of the [Model](/docs/api-reference/models) to be used to execute this run. If a value is provided here, it will override the model associated with the assistant. If not, the model associated with the assistant will be used + string|"gpt-4o"|"gpt-4o-2024-05-13"|"gpt-4o-mini"|"gpt-4o-mini-2024-07-18"|"gpt-4-turbo"|"gpt-4-turbo-2024-04-09"|"gpt-4-0125-preview"|"gpt-4-turbo-preview"|"gpt-4-1106-preview"|"gpt-4-vision-preview"|"gpt-4"|"gpt-4-0314"|"gpt-4-0613"|"gpt-4-32k"|"gpt-4-32k-0314"|"gpt-4-32k-0613"|"gpt-3.5-turbo"|"gpt-3.5-turbo-16k"|"gpt-3.5-turbo-0613"|"gpt-3.5-turbo-1106"|"gpt-3.5-turbo-0125"|"gpt-3.5-turbo-16k-0613"? model?; + # The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info + @jsondata:Name {value: "max_prompt_tokens"} + int? maxPromptTokens?; +|}; -# Represents the Queries record for the operation: listFiles -public type ListFilesQueries record { - # Only return files with the given purpose. - string purpose?; -}; +public type InputItemsArray int[]; public type ListFineTuningJobCheckpointsResponse record { + @jsondata:Name {value: "first_id"} + string? firstId?; FineTuningJobCheckpoint[] data; + @jsondata:Name {value: "last_id"} + string? lastId?; + @jsondata:Name {value: "has_more"} + boolean hasMore; "list" 'object; - string? first_id?; - string? last_id?; - boolean has_more; }; -public type DeleteModelResponse record { - string id; - boolean deleted; - string 'object; -}; +# Controls which (if any) tool is called by the model. +# `none` means the model will not call any tool and instead generates a message. +# `auto` means the model can pick between generating a message or calling one or more tools. +# `required` means the model must call one or more tools. +# Specifying a particular tool via `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that tool. +# +# `none` is the default when no tools are present. `auto` is the default if tools are present +public type ChatCompletionToolChoiceOption ChatCompletionToolChoiceOptionOneOf1|ChatCompletionNamedToolChoice; -public type FineTuningIntegration record { - # The type of the integration being enabled for the fine-tuning job - "wandb" 'type; - CreateFineTuningJobRequest_wandb wandb; +# Details on the action required to continue the run. Will be `null` if no action is required +public type RunObjectRequiredAction record { + @jsondata:Name {value: "submit_tool_outputs"} + RunObjectRequiredActionSubmitToolOutputs submitToolOutputs; + # For now, this is always `submit_tool_outputs` + "submit_tool_outputs" 'type; }; +# The default strategy. This strategy currently uses a `max_chunk_size_tokens` of `800` and `chunk_overlap_tokens` of `400` +public type AutoChunkingStrategyRequestParam record {| + # Always `auto` + "auto" 'type; +|}; + # Provides a set of configurations for controlling the behaviours when communicating with a remote HTTP endpoint. @display {label: "Connection Config"} public type ConnectionConfig record {| @@ -188,174 +168,2522 @@ public type ConnectionConfig record {| # The HTTP version understood by the client http:HttpVersion httpVersion = http:HTTP_2_0; # Configurations related to HTTP/1.x protocol - ClientHttp1Settings http1Settings?; + http:ClientHttp1Settings http1Settings = {}; # Configurations related to HTTP/2 protocol - http:ClientHttp2Settings http2Settings?; + http:ClientHttp2Settings http2Settings = {}; # The maximum time to wait (in seconds) for a response before closing the connection - decimal timeout = 60; + decimal timeout = 30; # The choice of setting `forwarded`/`x-forwarded` header string forwarded = "disable"; + # Configurations associated with Redirection + http:FollowRedirects followRedirects?; # Configurations associated with request pooling http:PoolConfiguration poolConfig?; # HTTP caching related configurations - http:CacheConfig cache?; + http:CacheConfig cache = {}; # Specifies the way of handling compression (`accept-encoding`) header http:Compression compression = http:COMPRESSION_AUTO; # Configurations associated with the behaviour of the Circuit Breaker http:CircuitBreakerConfig circuitBreaker?; # Configurations associated with retrying http:RetryConfig retryConfig?; + # Configurations associated with cookies + http:CookieConfig cookieConfig?; # Configurations associated with inbound response size limits - http:ResponseLimitConfigs responseLimits?; + http:ResponseLimitConfigs responseLimits = {}; # SSL/TLS-related options http:ClientSecureSocket secureSocket?; # Proxy server related options http:ProxyConfig proxy?; + # Provides settings related to client socket configuration + http:ClientSocketConfig socketConfig = {}; # Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default boolean validation = true; + # Enables relaxed data binding on the client side. When enabled, `nil` values are treated as optional, + # and absent fields are handled as `nilable` types. Enabled by default. + boolean laxDataBinding = true; |}; -# Metrics at the step number during the fine-tuning job. -public type FineTuningJobCheckpoint_metrics record { - decimal step?; - decimal train_loss?; - decimal train_mean_token_accuracy?; - decimal valid_loss?; - decimal valid_mean_token_accuracy?; - decimal full_valid_loss?; - decimal full_valid_mean_token_accuracy?; +public type AssistantToolsFileSearchTypeOnly record { + # The type of tool being defined: `file_search` + "file_search" 'type; }; -public type CreateFileRequest record {| - # The File object (not file name) to be uploaded. - record {byte[] fileContent; string fileName;} file; +public type AssistantToolsFileSearch record { + @jsondata:Name {value: "file_search"} + AssistantToolsFileSearchFileSearch fileSearch?; + # The type of tool being defined: `file_search` + "file_search" 'type; +}; + +public type CreateMessageRequestAttachments record { + # The ID of the file to attach to the message + @jsondata:Name {value: "file_id"} + string fileId?; + # The tools to add this file to + CreateMessageRequestTools[] tools?; +}; + +# The tool calls generated by the model, such as function calls +public type ChatCompletionMessageToolCalls ChatCompletionMessageToolCall[]; + +public type CreateEmbeddingRequest record {| + # Input text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays. The input must not exceed the max input tokens for the model (8192 tokens for `text-embedding-ada-002`), cannot be an empty string, and any array must be 2048 dimensions or less. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens + string|string[]|int[]|InputItemsArray[] input; + # The format to return the embeddings in. Can be either `float` or [`base64`](https://pypi.org/project/pybase64/) + @jsondata:Name {value: "encoding_format"} + "float"|"base64" encodingFormat = "float"; + # ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](/docs/models/overview) for descriptions of them + string|"text-embedding-ada-002"|"text-embedding-3-small"|"text-embedding-3-large" model; + # A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids) + string user?; + # The number of dimensions the resulting output embeddings should have. Only supported in `text-embedding-3` and later models + @constraint:Int {minValue: 1} + int dimensions?; +|}; + +# Represents the Queries record for the operation: listVectorStoreFiles +public type ListVectorStoreFilesQueries record { + # Filter by file status. One of `in_progress`, `completed`, `failed`, `cancelled` + "in_progress"|"completed"|"failed"|"cancelled" filter?; + # A cursor for use in pagination. `before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list + string before?; + # A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20 + int 'limit = 20; + # A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list + string after?; + # Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order + "asc"|"desc" 'order = "desc"; +}; + +public type ChatCompletionTokenLogprobTopLogprobs record { + # The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value `-9999.0` is used to signify that the token is very unlikely + decimal logprob; + # A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be `null` if there is no bytes representation for the token + int[]? bytes; + # The token + string token; +}; + +# Whether to enable [parallel function calling](/docs/guides/function-calling/parallel-function-calling) during tool use +public type ParallelToolCalls boolean; + +public type CreateModerationRequest record { + # The input text to classify + string|string[] input; + # Two content moderations models are available: `text-moderation-stable` and `text-moderation-latest`. + # + # The default is `text-moderation-latest` which will be automatically upgraded over time. This ensures you are always using our most accurate model. If you use `text-moderation-stable`, we will provide advanced notice before updating the model. Accuracy of `text-moderation-stable` may be slightly lower than for `text-moderation-latest` + string|"text-moderation-latest"|"text-moderation-stable" model = "text-moderation-latest"; +}; + +public type CreateUploadRequest record {| + # The name of the file to upload + string filename; # The intended purpose of the uploaded file. # - # Use "assistants" for [Assistants](/docs/api-reference/assistants) and [Message](/docs/api-reference/messages) files, "vision" for Assistants image file inputs, "batch" for [Batch API](/docs/guides/batch), and "fine-tune" for [Fine-tuning](/docs/api-reference/fine-tuning). + # See the [documentation on File purposes](/docs/api-reference/files/create#files-create-purpose) "assistants"|"batch"|"fine-tune"|"vision" purpose; + # The MIME type of the file. + # + # This must fall within the supported MIME types for your file purpose. See the supported MIME types for assistants and vision + @jsondata:Name {value: "mime_type"} + string mimeType; + # The number of bytes in the file you are uploading + int bytes; |}; -# The `fine_tuning.job` object represents a fine-tuning job that has been created through the API. -public type FineTuningJob record { - # The object identifier, which can be referenced in the API endpoints. - string id; - # The Unix timestamp (in seconds) for when the fine-tuning job was created. - int created_at; - FineTuningJob_error? 'error; - # The name of the fine-tuned model that is being created. The value will be null if the fine-tuning job is still running. - string? fine_tuned_model; - # The Unix timestamp (in seconds) for when the fine-tuning job was finished. The value will be null if the fine-tuning job is still running. - int? finished_at; - FineTuningJob_hyperparameters hyperparameters; - # The base model that is being fine-tuned. - string model; - # The object type, which is always "fine_tuning.job". - "fine_tuning.job" 'object; - # The organization that owns the fine-tuning job. - string organization_id; - # The compiled results file ID(s) for the fine-tuning job. You can retrieve the results with the [Files API](/docs/api-reference/files/retrieve-contents). - string[] result_files; - # The current status of the fine-tuning job, which can be either `validating_files`, `queued`, `running`, `succeeded`, `failed`, or `cancelled`. - "validating_files"|"queued"|"running"|"succeeded"|"failed"|"cancelled" status; - # The total number of billable tokens processed by this fine-tuning job. The value will be null if the fine-tuning job is still running. - int? trained_tokens; - # The file ID used for training. You can retrieve the training data with the [Files API](/docs/api-reference/files/retrieve-contents). - string training_file; - # The file ID used for validation. You can retrieve the validation results with the [Files API](/docs/api-reference/files/retrieve-contents). - string? validation_file; - # A list of integrations to enable for this fine-tuning job. - (FineTuningIntegration)[]? integrations?; - # The seed used for the fine-tuning job. - int seed; - # The Unix timestamp (in seconds) for when the fine-tuning job is estimated to finish. The value will be null if the fine-tuning job is not running. - int? estimated_finish?; -}; - -# Proxy server configurations to be used with the HTTP client endpoint. -public type ProxyConfig record {| - # Host name of the proxy server - string host = ""; - # Proxy server port - int port = 0; - # Proxy server username - string userName = ""; - # Proxy server password - @display {label: "", kind: "password"} - string password = ""; +public type TranscriptionWord record { + # Start time of the word in seconds + float 'start; + # End time of the word in seconds + float end; + # The text content of the word + string word; +}; + +public type CreateSpeechRequest record {| + # The voice to use when generating the audio. Supported voices are `alloy`, `echo`, `fable`, `onyx`, `nova`, and `shimmer`. Previews of the voices are available in the [Text to speech guide](/docs/guides/text-to-speech/voice-options) + "alloy"|"echo"|"fable"|"onyx"|"nova"|"shimmer" voice; + # The text to generate audio for. The maximum length is 4096 characters + @constraint:String {maxLength: 4096} + string input; + # The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`, `wav`, and `pcm` + @jsondata:Name {value: "response_format"} + "mp3"|"opus"|"aac"|"flac"|"wav"|"pcm" responseFormat = "mp3"; + # One of the available [TTS models](/docs/models/tts): `tts-1` or `tts-1-hd` + string|"tts-1"|"tts-1-hd" model; + # The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is the default + @constraint:Number {minValue: 0.25, maxValue: 4.0} + decimal speed = 1.0; |}; -# For fine-tuning jobs that have `failed`, this will contain more information on the cause of the failure. -public type FineTuningJob_error record { - # A machine-readable error code. - string code?; - # A human-readable error message. - string message?; - # The parameter that was invalid, usually `training_file` or `validation_file`. This field will be null if the failure was not parameter-specific. - string? param?; +# A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs +public type AssistantObjectToolResources record { + @jsondata:Name {value: "code_interpreter"} + AssistantObjectToolResourcesCodeInterpreter codeInterpreter?; + @jsondata:Name {value: "file_search"} + AssistantObjectToolResourcesFileSearch fileSearch?; }; -public type CreateFineTuningJobRequest_integrations record { - # The type of integration to enable. Currently, only "wandb" (Weights and Biases) is supported. - "wandb" 'type; - CreateFineTuningJobRequest_wandb wandb; +public type CreateVectorStoreFileRequest record {| + @jsondata:Name {value: "chunking_strategy"} + ChunkingStrategyRequestParam chunkingStrategy?; + # A [File](/docs/api-reference/files) ID that the vector store should use. Useful for tools like `file_search` that can access files + @jsondata:Name {value: "file_id"} + string fileId; +|}; + +public type CreateMessageRequestTools AssistantToolsCode|AssistantToolsFileSearchTypeOnly; + +public type ChatCompletionRequestMessageContentPartText record { + # The text content + string text; + # The type of the content part + "text" 'type; }; -public type ListModelsResponse record { - "list" 'object; - Model[] data; +public type ModifyThreadRequest record {| + @jsondata:Name {value: "tool_resources"} + ModifyThreadRequestToolResources? toolResources?; + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata?; +|}; + +# The text content that is part of a message +public type MessageContentTextObject record { + MessageContentTextObjectText text; + # Always `text` + "text" 'type; }; -# Fine-tuning job event object -public type FineTuningJobEvent record { +public type DeleteMessageResponse record { + boolean deleted; string id; - int created_at; - "info"|"warn"|"error" level; - string message; - "fine_tuning.job.event" 'object; + "thread.message.deleted" 'object; }; -public type DeleteFileResponse record { +# Represents the Queries record for the operation: listMessages +public type ListMessagesQueries record { + # Filter messages by the run ID that generated them + @http:Query {name: "run_id"} + string runId?; + # A cursor for use in pagination. `before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list + string before?; + # A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20 + int 'limit = 20; + # A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list + string after?; + # Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order + "asc"|"desc" 'order = "desc"; +}; + +public type AssistantsNamedToolChoiceFunction record { + # The name of the function to call + string name; +}; + +# Represents an embedding vector returned by embedding endpoint +public type Embedding record { + # The index of the embedding in the list of embeddings + int index; + # The embedding vector, which is a list of floats. The length of vector depends on the model as listed in the [embedding guide](/docs/guides/embeddings) + decimal[] embedding; + # The object type, which is always "embedding" + "embedding" 'object; +}; + +# Represents the Queries record for the operation: listFineTuningEvents +public type ListFineTuningEventsQueries record { + # Number of events to retrieve + int 'limit = 20; + # Identifier for the last event from the previous pagination request + string after?; +}; + +public type RunStepDetailsMessageCreationObjectMessageCreation record { + # The ID of the message that was created by this run step + @jsondata:Name {value: "message_id"} + string messageId; +}; + +public type CreateChatCompletionRequest record { + # An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. `logprobs` must be set to `true` if this parameter is used + @jsondata:Name {value: "top_logprobs"} + int? topLogprobs?; + # Modify the likelihood of specified tokens appearing in the completion. + # + # Accepts a JSON object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token + @jsondata:Name {value: "logit_bias"} + record {|int...;|}? logitBias?; + # This feature is in Beta. + # If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result. + # Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend + int? seed?; + # Deprecated in favor of `tools`. + # + # A list of functions the model may generate JSON inputs for + # + # # Deprecated + @constraint:Array {maxLength: 128, minLength: 1} + @deprecated + ChatCompletionFunctions[] functions?; + # The maximum number of [tokens](/tokenizer) that can be generated in the chat completion. + # + # The total length of input tokens and generated tokens is limited by the model's context length. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens + @jsondata:Name {value: "max_tokens"} + int? maxTokens?; + # Deprecated in favor of `tool_choice`. + # + # Controls which (if any) function is called by the model. + # `none` means the model will not call a function and instead generates a message. + # `auto` means the model can pick between generating a message or calling a function. + # Specifying a particular function via `{"name": "my_function"}` forces the model to call that function. + # + # `none` is the default when no functions are present. `auto` is the default if functions are present + # + # # Deprecated + @jsondata:Name {value: "function_call"} + @deprecated + "none"|"auto"|ChatCompletionFunctionCallOption functionCall?; + # Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. + # + # [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) + @jsondata:Name {value: "presence_penalty"} + decimal? presencePenalty = 0; + # A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported + ChatCompletionTool[] tools?; + # How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep `n` as `1` to minimize costs + int? n = 1; + # Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the `content` of `message` + boolean? logprobs = false; + # An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + # + # We generally recommend altering this or `temperature` but not both + @jsondata:Name {value: "top_p"} + decimal? topP = 1; + # Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. + # + # [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) + @jsondata:Name {value: "frequency_penalty"} + decimal? frequencyPenalty = 0; + @jsondata:Name {value: "response_format"} + CreateChatCompletionRequestResponseFormat responseFormat?; + # Up to 4 sequences where the API will stop generating further tokens + string|string[]? stop?; + @jsondata:Name {value: "parallel_tool_calls"} + ParallelToolCalls parallelToolCalls?; + # If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) as they become available, with the stream terminated by a `data: [DONE]` message. [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions) + boolean? 'stream = false; + # What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. + # + # We generally recommend altering this or `top_p` but not both + decimal? temperature = 1; + # A list of messages comprising the conversation so far. [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models) + @constraint:Array {minLength: 1} + ChatCompletionRequestMessage[] messages; + @jsondata:Name {value: "tool_choice"} + ChatCompletionToolChoiceOption toolChoice?; + # ID of the model to use. See the [model endpoint compatibility](/docs/models/model-endpoint-compatibility) table for details on which models work with the Chat API + string|"gpt-4o"|"gpt-4o-2024-05-13"|"gpt-4o-mini"|"gpt-4o-mini-2024-07-18"|"gpt-4-turbo"|"gpt-4-turbo-2024-04-09"|"gpt-4-0125-preview"|"gpt-4-turbo-preview"|"gpt-4-1106-preview"|"gpt-4-vision-preview"|"gpt-4"|"gpt-4-0314"|"gpt-4-0613"|"gpt-4-32k"|"gpt-4-32k-0314"|"gpt-4-32k-0613"|"gpt-3.5-turbo"|"gpt-3.5-turbo-16k"|"gpt-3.5-turbo-0301"|"gpt-3.5-turbo-0613"|"gpt-3.5-turbo-1106"|"gpt-3.5-turbo-0125"|"gpt-3.5-turbo-16k-0613" model; + # Specifies the latency tier to use for processing the request. This parameter is relevant for customers subscribed to the scale tier service: + # - If set to 'auto', the system will utilize scale tier credits until they are exhausted. + # - If set to 'default', the request will be processed using the default service tier with a lower uptime SLA and no latency guarentee. + # - When not set, the default behavior is 'auto'. + # + # When this parameter is set, the response body will include the `service_tier` utilized + @jsondata:Name {value: "service_tier"} + "auto"|"default"? serviceTier?; + @jsondata:Name {value: "stream_options"} + ChatCompletionStreamOptions? streamOptions?; + # A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids) + string user?; +}; + +# A list of the categories, and whether they are flagged or not +public type CreateModerationResponseCategories record { + # Content where the speaker expresses that they are engaging or intend to engage in acts of self-harm, such as suicide, cutting, and eating disorders + @jsondata:Name {value: "self-harm/intent"} + boolean selfHarmIntent; + # Hateful content that also includes violence or serious harm towards the targeted group based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste + @jsondata:Name {value: "hate/threatening"} + boolean hateThreatening; + # Content that encourages performing acts of self-harm, such as suicide, cutting, and eating disorders, or that gives instructions or advice on how to commit such acts + @jsondata:Name {value: "self-harm/instructions"} + boolean selfHarmInstructions; + # Sexual content that includes an individual who is under 18 years old + @jsondata:Name {value: "sexual/minors"} + boolean sexualMinors; + # Harassment content that also includes violence or serious harm towards any target + @jsondata:Name {value: "harassment/threatening"} + boolean harassmentThreatening; + # Content that expresses, incites, or promotes hate based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste. Hateful content aimed at non-protected groups (e.g., chess players) is harassment + boolean hate; + # Content that promotes, encourages, or depicts acts of self-harm, such as suicide, cutting, and eating disorders + @jsondata:Name {value: "self-harm"} + boolean selfHarm; + # Content that expresses, incites, or promotes harassing language towards any target + boolean harassment; + # Content meant to arouse sexual excitement, such as the description of sexual activity, or that promotes sexual services (excluding sex education and wellness) + boolean sexual; + # Content that depicts death, violence, or physical injury in graphic detail + @jsondata:Name {value: "violence/graphic"} + boolean violenceGraphic; + # Content that depicts death, violence, or physical injury + boolean violence; +}; + +# A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs +public type ModifyAssistantRequestToolResources record { + @jsondata:Name {value: "code_interpreter"} + ModifyAssistantRequestToolResourcesCodeInterpreter codeInterpreter?; + @jsondata:Name {value: "file_search"} + ModifyAssistantRequestToolResourcesFileSearch fileSearch?; +}; + +# Usage statistics for the completion request +public type CompletionUsage record { + # Number of tokens in the generated completion + @jsondata:Name {value: "completion_tokens"} + int completionTokens; + # Number of tokens in the prompt + @jsondata:Name {value: "prompt_tokens"} + int promptTokens; + # Total number of tokens used in the request (prompt + completion) + @jsondata:Name {value: "total_tokens"} + int totalTokens; +}; + +# Tool call objects +public type RunToolCallObject record { + RunToolCallObjectFunction 'function; + # The ID of the tool call. This ID must be referenced when you submit the tool outputs in using the [Submit tool outputs to run](/docs/api-reference/runs/submitToolOutputs) endpoint string id; - "file" 'object; - boolean deleted; + # The type of tool call the output is required for. For now, this is always `function` + "function" 'type; }; -# Provides settings related to HTTP/1.x protocol. -public type ClientHttp1Settings record {| - # Specifies whether to reuse a connection for multiple requests - http:KeepAlive keepAlive = http:KEEPALIVE_AUTO; - # The chunking behaviour of the request - http:Chunking chunking = http:CHUNKING_AUTO; - # Proxy server related options - ProxyConfig proxy?; -|}; +# Details of the tool call +public type RunStepDetailsToolCallsObject record { + # An array of tool calls the run step was involved in. These can be associated with one of three types of tools: `code_interpreter`, `file_search`, or `function` + @jsondata:Name {value: "tool_calls"} + RunStepDetailsToolCallsObjectToolCalls[] toolCalls; + # Always `tool_calls` + "tool_calls" 'type; +}; -# Describes an OpenAI model offering that can be used with the API. -public type Model record { - # The model identifier, which can be referenced in the API endpoints. +# A vector store is a collection of processed files can be used by the `file_search` tool +public type VectorStoreObject record { + @jsondata:Name {value: "file_counts"} + VectorStoreObjectFileCounts fileCounts; + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata; + # The Unix timestamp (in seconds) for when the vector store will expire + @jsondata:Name {value: "expires_at"} + int? expiresAt?; + @jsondata:Name {value: "expires_after"} + VectorStoreExpirationAfter expiresAfter?; + # The Unix timestamp (in seconds) for when the vector store was last active + @jsondata:Name {value: "last_active_at"} + int? lastActiveAt; + # The total number of bytes used by the files in the vector store + @jsondata:Name {value: "usage_bytes"} + int usageBytes; + # The name of the vector store + string name; + # The Unix timestamp (in seconds) for when the vector store was created + @jsondata:Name {value: "created_at"} + int createdAt; + # The identifier, which can be referenced in API endpoints string id; - # The Unix timestamp (in seconds) when the model was created. + # The object type, which is always `vector_store` + "vector_store" 'object; + # The status of the vector store, which can be either `expired`, `in_progress`, or `completed`. A status of `completed` indicates that the vector store is ready for use + "expired"|"in_progress"|"completed" status; +}; + +# The function definition +public type RunToolCallObjectFunction record { + # The name of the function + string name; + # The arguments that the model expects you to pass to the function + string arguments; +}; + +public type ModifyThreadRequestToolResourcesCodeInterpreter record { + # A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool + @jsondata:Name {value: "file_ids"} + string[] fileIds = []; +}; + +public type CreateCompletionRequest record { + # Modify the likelihood of specified tokens appearing in the completion. + # + # Accepts a JSON object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100. You can use this [tokenizer tool](/tokenizer?view=bpe) to convert text to token IDs. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token. + # + # As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being generated + @jsondata:Name {value: "logit_bias"} + record {|int...;|}? logitBias?; + # If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result. + # + # Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend + int? seed?; + # The maximum number of [tokens](/tokenizer) that can be generated in the completion. + # + # The token count of your prompt plus `max_tokens` cannot exceed the model's context length. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens + @jsondata:Name {value: "max_tokens"} + int? maxTokens = 16; + # Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. + # + # [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) + @jsondata:Name {value: "presence_penalty"} + decimal? presencePenalty = 0; + # Echo back the prompt in addition to the completion + boolean? echo = false; + # The suffix that comes after a completion of inserted text. + # + # This parameter is only supported for `gpt-3.5-turbo-instruct` + string? suffix?; + # How many completions to generate for each prompt. + # + # **Note:** Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop` + int? n = 1; + # Include the log probabilities on the `logprobs` most likely output tokens, as well the chosen tokens. For example, if `logprobs` is 5, the API will return a list of the 5 most likely tokens. The API will always return the `logprob` of the sampled token, so there may be up to `logprobs+1` elements in the response. + # + # The maximum value for `logprobs` is 5 + int? logprobs?; + # An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + # + # We generally recommend altering this or `temperature` but not both + @jsondata:Name {value: "top_p"} + decimal? topP = 1; + # Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. + # + # [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) + @jsondata:Name {value: "frequency_penalty"} + decimal? frequencyPenalty = 0; + # Generates `best_of` completions server-side and returns the "best" (the one with the highest log probability per token). Results cannot be streamed. + # + # When used with `n`, `best_of` controls the number of candidate completions and `n` specifies how many to return – `best_of` must be greater than `n`. + # + # **Note:** Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop` + @jsondata:Name {value: "best_of"} + int? bestOf = 1; + # Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence + string|string[]?? stop?; + # Whether to stream back partial progress. If set, tokens will be sent as data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) as they become available, with the stream terminated by a `data: [DONE]` message. [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions) + boolean? 'stream = false; + # What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. + # + # We generally recommend altering this or `top_p` but not both + decimal? temperature = 1; + # ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](/docs/models/overview) for descriptions of them + string|"gpt-3.5-turbo-instruct"|"davinci-002"|"babbage-002" model; + @jsondata:Name {value: "stream_options"} + ChatCompletionStreamOptions? streamOptions?; + # The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays. + # + # Note that <|endoftext|> is the document separator that the model sees during training, so if a prompt is not specified the model will generate as if from the beginning of a new document + string|string[]|int[]|PromptItemsArray[]? prompt = "<|endoftext|>"; + # A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids) + string user?; +}; + +# Represents a completion response from the API. Note: both the streamed and non-streamed response objects share the same shape (unlike the chat endpoint) +public type CreateCompletionResponse record { + # The Unix timestamp (in seconds) of when the completion was created int created; - # The object type, which is always "model". - "model" 'object; - # The organization that owns the model. - string owned_by; + CompletionUsage usage?; + # The model used for completion + string model; + # A unique identifier for the completion + string id; + # The list of completion choices the model generated for the input prompt + CreateCompletionResponseChoices[] choices; + # This fingerprint represents the backend configuration that the model runs with. + # + # Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism + @jsondata:Name {value: "system_fingerprint"} + string systemFingerprint?; + # The object type, which is always "text_completion" + "text_completion" 'object; }; -public type ListFineTuningJobEventsResponse record { - FineTuningJobEvent[] data; - "list" 'object; +public type AssistantToolsFunction record { + FunctionObject 'function; + # The type of tool being defined: `function` + "function" 'type; }; -public type ListFilesResponse record { - OpenAIFile[] data; - "list" 'object; +# Log probability information for the choice +public type CreateChatCompletionResponseLogprobs record { + # A list of message content tokens with log probability information + ChatCompletionTokenLogprob[]? content; }; -# Represents the Queries record for the operation: listPaginatedFineTuningJobs -public type ListPaginatedFineTuningJobsQueries record { - # Number of fine-tuning jobs to retrieve. +public type PromptItemsArray int[]; + +# Controls for how a thread will be truncated prior to the run. Use this to control the intial context window of the run +public type TruncationObject record { + # The number of most recent messages from the thread when constructing the context for the run + @jsondata:Name {value: "last_messages"} + int? lastMessages?; + # The truncation strategy to use for the thread. The default is `auto`. If set to `last_messages`, the thread will be truncated to the n most recent messages in the thread. When set to `auto`, messages in the middle of the thread will be dropped to fit the context length of the model, `max_prompt_tokens` + "auto"|"last_messages" 'type; +}; + +# Represents the Queries record for the operation: listVectorStores +public type ListVectorStoresQueries record { + # A cursor for use in pagination. `before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list + string before?; + # A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20 int 'limit = 20; - # Identifier for the last job from the previous pagination request. + # A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list string after?; + # Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order + "asc"|"desc" 'order = "desc"; +}; + +# An object describing the expected output of the model. If `json_object` only `function` type `tools` are allowed to be passed to the Run. If `text` the model can return text or any value needed +public type AssistantsApiResponseFormat record { + # Must be one of `text` or `json_object` + "text"|"json_object" 'type = "text"; +}; + +public type RunStepDetailsToolCallsObjectToolCalls RunStepDetailsToolCallsCodeObject|RunStepDetailsToolCallsFileSearchObject|RunStepDetailsToolCallsFunctionObject; + +public type VectorStoreObjectFileCounts record { + # The number of files that are currently being processed + @jsondata:Name {value: "in_progress"} + int inProgress; + # The total number of files + int total; + # The number of files that were cancelled + int cancelled; + # The number of files that have been successfully processed + int completed; + # The number of files that have failed to process + int failed; +}; + +public type ListMessagesResponse record { + string 'object; + MessageObject[] data; + string first_id; + string last_id; + boolean has_more; +}; + +# An object specifying the format that the model must output. Compatible with [GPT-4 Turbo](/docs/models/gpt-4-and-gpt-4-turbo) and all GPT-3.5 Turbo models newer than `gpt-3.5-turbo-1106`. +# +# Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is valid JSON. +# +# **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length +public type CreateChatCompletionRequestResponseFormat record { + # Must be one of `text` or `json_object` + "text"|"json_object" 'type = "text"; +}; + +# The hyperparameters used for the fine-tuning job. See the [fine-tuning guide](/docs/guides/fine-tuning) for more details +public type FineTuningJobHyperparameters record { + # The number of epochs to train the model for. An epoch refers to one full cycle through the training dataset. + # "auto" decides the optimal number of epochs based on the size of the dataset. If setting the number manually, we support any number between 1 and 50 epochs + @jsondata:Name {value: "n_epochs"} + "auto"|int nEpochs = "auto"; +}; + +public type ChatCompletionNamedToolChoiceFunction record { + # The name of the function to call + string name; +}; + +public type ListAssistantsResponse record { + @jsondata:Name {value: "first_id"} + string firstId; + AssistantObject[] data; + @jsondata:Name {value: "last_id"} + string lastId; + @jsondata:Name {value: "has_more"} + boolean hasMore; + string 'object; +}; + +# A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs +public type ThreadObjectToolResources record { + @jsondata:Name {value: "code_interpreter"} + ThreadObjectToolResourcesCodeInterpreter codeInterpreter?; + @jsondata:Name {value: "file_search"} + ThreadObjectToolResourcesFileSearch fileSearch?; +}; + +public type CreateThreadAndRunRequestToolResourcesFileSearch record { + # The ID of the [vector store](/docs/api-reference/vector-stores/object) attached to this assistant. There can be a maximum of 1 vector store attached to the assistant + @jsondata:Name {value: "vector_store_ids"} + string[] vectorStoreIds?; +}; + +public type InlineResponse2001 CreateTranslationResponseJson|CreateTranslationResponseVerboseJson; + +# The text content that is part of a message +public type MessageRequestContentTextObject record { + # Text content to be sent to the model + string text; + # Always `text` + "text" 'type; +}; + +public type CreateThreadAndRunRequestTools AssistantToolsCode|AssistantToolsFileSearch|AssistantToolsFunction; + +# Represents the Queries record for the operation: listRuns +public type ListRunsQueries record { + # A cursor for use in pagination. `before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list + string before?; + # A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20 + int 'limit = 20; + # A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list + string after?; + # Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order + "asc"|"desc" 'order = "desc"; +}; + +public type RunStepDetailsToolCallsCodeObjectCodeInterpreterOutputs RunStepDetailsToolCallsCodeOutputLogsObject|RunStepDetailsToolCallsCodeOutputImageObject; + +# Represents a transcription response returned by model, based on the provided input +public type CreateTranscriptionResponseJson record { + # The transcribed text + string text; +}; + +# Usage statistics related to the run step. This value will be `null` while the run step's status is `in_progress` +public type RunStepCompletionUsage record { + # Number of completion tokens used over the course of the run step + @jsondata:Name {value: "completion_tokens"} + int completionTokens; + # Number of prompt tokens used over the course of the run step + @jsondata:Name {value: "prompt_tokens"} + int promptTokens; + # Total number of tokens used (prompt + completion) + @jsondata:Name {value: "total_tokens"} + int totalTokens; +}; + +public type TranscriptionSegment record { + # Start time of the segment in seconds + float 'start; + # Temperature parameter used for generating the segment + float temperature; + # Average logprob of the segment. If the value is lower than -1, consider the logprobs failed + @jsondata:Name {value: "avg_logprob"} + float avgLogprob; + # Probability of no speech in the segment. If the value is higher than 1.0 and the `avg_logprob` is below -1, consider this segment silent + @jsondata:Name {value: "no_speech_prob"} + float noSpeechProb; + # End time of the segment in seconds + float end; + # Array of token IDs for the text content + int[] tokens; + # Unique identifier of the segment + int id; + # Text content of the segment + string text; + # Seek offset of the segment + int seek; + # Compression ratio of the segment. If the value is greater than 2.4, consider the compression failed + @jsondata:Name {value: "compression_ratio"} + float compressionRatio; +}; + +public type DeleteVectorStoreFileResponse record { + boolean deleted; + string id; + "vector_store.file.deleted" 'object; +}; + +public type CreateImageRequest record { + # The format in which the generated images are returned. Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes after the image has been generated + @jsondata:Name {value: "response_format"} + "url"|"b64_json"? responseFormat = "url"; + # The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`. Must be one of `1024x1024`, `1792x1024`, or `1024x1792` for `dall-e-3` models + "256x256"|"512x512"|"1024x1024"|"1792x1024"|"1024x1792"? size = "1024x1024"; + # The model to use for image generation + string|"dall-e-2"|"dall-e-3"? model = "dall-e-2"; + # The style of the generated images. Must be one of `vivid` or `natural`. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images. This param is only supported for `dall-e-3` + "vivid"|"natural"? style = "vivid"; + # A text description of the desired image(s). The maximum length is 1000 characters for `dall-e-2` and 4000 characters for `dall-e-3` + string prompt; + # A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids) + string user?; + # The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only `n=1` is supported + int? n = 1; + # The quality of the image that will be generated. `hd` creates images with finer details and greater consistency across the image. This param is only supported for `dall-e-3` + "standard"|"hd" quality = "standard"; +}; + +public type BatchErrors record { + BatchErrorsData[] data?; + # The object type, which is always `list` + string 'object?; +}; + +# `none` means the model will not call any tool and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `required` means the model must call one or more tools +public type ChatCompletionToolChoiceOptionOneOf1 "none"|"auto"|"required"; + +public type ModifyThreadRequestToolResourcesFileSearch record { + # The [vector store](/docs/api-reference/vector-stores/object) attached to this thread. There can be a maximum of 1 vector store attached to the thread + @jsondata:Name {value: "vector_store_ids"} + string[] vectorStoreIds?; +}; + +# Details on the tool outputs needed for this run to continue +public type RunObjectRequiredActionSubmitToolOutputs record { + # A list of the relevant tool calls + @jsondata:Name {value: "tool_calls"} + RunToolCallObject[] toolCalls; +}; + +public type CreateTranscriptionRequest record {| + # The timestamp granularities to populate for this transcription. `response_format` must be set `verbose_json` to use timestamp granularities. Either or both of these options are supported: `word`, or `segment`. Note: There is no additional latency for segment timestamps, but generating word timestamps incurs additional latency + @jsondata:Name {value: "timestamp_granularities[]"} + ("word"|"segment")[] timestampGranularities = ["segment"]; + # The audio file object (not file name) to transcribe, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm + record {byte[] fileContent; string fileName;} file; + # The format of the transcript output, in one of these options: `json`, `text`, `srt`, `verbose_json`, or `vtt` + @jsondata:Name {value: "response_format"} + "json"|"text"|"srt"|"verbose_json"|"vtt" responseFormat = "json"; + # The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit + decimal temperature = 0; + # ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2 model) is currently available + string|"whisper-1" model; + # The language of the input audio. Supplying the input language in [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) format will improve accuracy and latency + string language?; + # An optional text to guide the model's style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text/prompting) should match the audio language + string prompt?; +|}; + +# Details on why the run is incomplete. Will be `null` if the run is not incomplete +public type RunObjectIncompleteDetails record { + # The reason why the run is incomplete. This will point to which specific token limit was reached over the course of the run + "max_completion_tokens"|"max_prompt_tokens" reason?; +}; + +public type MessageContentTextAnnotationsFileCitationObjectFileCitation record { + # The ID of the specific File the citation is from + @jsondata:Name {value: "file_id"} + string fileId; +}; + +public type SubmitToolOutputsRunRequestToolOutputs record { + # The output of the tool call to be submitted to continue the run + string output?; + # The ID of the tool call in the `required_action` object within the run object the output is being submitted for + @jsondata:Name {value: "tool_call_id"} + string toolCallId?; +}; + +public type ListBatchesResponse record { + @jsondata:Name {value: "first_id"} + string firstId?; + Batch[] data; + @jsondata:Name {value: "last_id"} + string lastId?; + @jsondata:Name {value: "has_more"} + boolean hasMore; + "list" 'object; +}; + +public type CreateEmbeddingResponse record { + # The list of embeddings generated by the model + Embedding[] data; + CreateEmbeddingResponseUsage usage; + # The name of the model used to generate the embedding + string model; + # The object type, which is always "list" + "list" 'object; +}; + +public type BatchErrorsData record { + # An error code identifying the error type + string code?; + # The name of the parameter that caused the error, if applicable + string? param?; + # The line number of the input file where the error occurred, if applicable + int? line?; + # A human-readable message providing more details about the error + string message?; +}; + +# A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs +public type CreateThreadRequestToolResources record { + @jsondata:Name {value: "code_interpreter"} + CreateThreadRequestToolResourcesCodeInterpreter codeInterpreter?; + @jsondata:Name {value: "file_search"} + CreateThreadRequestToolResourcesFileSearch fileSearch?; +}; + +# Represents the Queries record for the operation: listRunSteps +public type ListRunStepsQueries record { + # A cursor for use in pagination. `before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list + string before?; + # A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20 + int 'limit = 20; + # A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list + string after?; + # Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order + "asc"|"desc" 'order = "desc"; +}; + +# Represents an execution run on a [thread](/docs/api-reference/threads) +public type RunObject record { + # The Unix timestamp (in seconds) for when the run was cancelled + @jsondata:Name {value: "cancelled_at"} + int? cancelledAt; + # The instructions that the [assistant](/docs/api-reference/assistants) used for this run + string instructions; + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata; + # The ID of the [assistant](/docs/api-reference/assistants) used for execution of this run + @jsondata:Name {value: "assistant_id"} + string assistantId; + @jsondata:Name {value: "required_action"} + RunObjectRequiredAction? requiredAction; + RunCompletionUsage? usage; + # The Unix timestamp (in seconds) for when the run was created + @jsondata:Name {value: "created_at"} + int createdAt; + # The list of tools that the [assistant](/docs/api-reference/assistants) used for this run + @constraint:Array {maxLength: 20} + RunObjectTools[] tools = []; + # The nucleus sampling value used for this run. If not set, defaults to 1 + @jsondata:Name {value: "top_p"} + decimal? topP?; + # The maximum number of completion tokens specified to have been used over the course of the run + @jsondata:Name {value: "max_completion_tokens"} + int? maxCompletionTokens; + # The ID of the [thread](/docs/api-reference/threads) that was executed on as a part of this run + @jsondata:Name {value: "thread_id"} + string threadId; + # The Unix timestamp (in seconds) for when the run will expire + @jsondata:Name {value: "expires_at"} + int? expiresAt; + @jsondata:Name {value: "response_format"} + AssistantsApiResponseFormatOption responseFormat; + # The sampling temperature used for this run. If not set, defaults to 1 + decimal? temperature?; + @jsondata:Name {value: "tool_choice"} + AssistantsApiToolChoiceOption toolChoice; + # The model that the [assistant](/docs/api-reference/assistants) used for this run + string model; + # The identifier, which can be referenced in API endpoints + string id; + @jsondata:Name {value: "last_error"} + RunObjectLastError? lastError; + @jsondata:Name {value: "incomplete_details"} + RunObjectIncompleteDetails? incompleteDetails; + @jsondata:Name {value: "truncation_strategy"} + TruncationObject truncationStrategy; + # The Unix timestamp (in seconds) for when the run was completed + @jsondata:Name {value: "completed_at"} + int? completedAt; + @jsondata:Name {value: "parallel_tool_calls"} + ParallelToolCalls parallelToolCalls; + # The Unix timestamp (in seconds) for when the run was started + @jsondata:Name {value: "started_at"} + int? startedAt; + # The Unix timestamp (in seconds) for when the run failed + @jsondata:Name {value: "failed_at"} + int? failedAt; + # The maximum number of prompt tokens specified to have been used over the course of the run + @jsondata:Name {value: "max_prompt_tokens"} + int? maxPromptTokens; + # The object type, which is always `thread.run` + "thread.run" 'object; + # The status of the run, which can be either `queued`, `in_progress`, `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`, `incomplete`, or `expired` + "queued"|"in_progress"|"requires_action"|"cancelling"|"cancelled"|"failed"|"completed"|"incomplete"|"expired" status; +}; + +public type ChatCompletionRequestUserMessage record { + # The role of the messages author, in this case `user` + "user" role; + # An optional name for the participant. Provides the model information to differentiate between participants of the same role + string name?; + # The contents of the user message + string|ChatCompletionRequestMessageContentPart[] content; +}; + +public type ModifyAssistantRequestToolResourcesCodeInterpreter record { + # Overrides the list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool + @jsondata:Name {value: "file_ids"} + string[] fileIds = []; +}; + +public type ChatCompletionTool record { + FunctionObject 'function; + # The type of the tool. Currently, only `function` is supported + "function" 'type; +}; + +# Represents the Queries record for the operation: listFilesInVectorStoreBatch +public type ListFilesInVectorStoreBatchQueries record { + # Filter by file status. One of `in_progress`, `completed`, `failed`, `cancelled` + "in_progress"|"completed"|"failed"|"cancelled" filter?; + # A cursor for use in pagination. `before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list + string before?; + # A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20 + int 'limit = 20; + # A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list + string after?; + # Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order + "asc"|"desc" 'order = "desc"; +}; + +# The expiration policy for a vector store +public type VectorStoreExpirationAfter record { + # Anchor timestamp after which the expiration policy applies. Supported anchors: `last_active_at` + "last_active_at" anchor; + # The number of days after the anchor time that the vector store will expire + @constraint:Int {minValue: 1, maxValue: 365} + int days; +}; + +public type CreateThreadAndRunRequestToolResourcesCodeInterpreter record { + # A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool + @jsondata:Name {value: "file_ids"} + string[] fileIds = []; +}; + +public type ModifyMessageRequest record {| + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata?; +|}; + +# Controls which (if any) tool is called by the model. +# `none` means the model will not call any tools and instead generates a message. +# `auto` is the default value and means the model can pick between generating a message or calling one or more tools. +# `required` means the model must call one or more tools before responding to the user. +# Specifying a particular tool like `{"type": "file_search"}` or `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that tool +public type AssistantsApiToolChoiceOption AssistantsApiToolChoiceOptionOneOf1|AssistantsNamedToolChoice; + +public type RunStepDetailsToolCallsCodeOutputImageObject record { + RunStepDetailsToolCallsCodeOutputImageObjectImage image; + # Always `image` + "image" 'type; +}; + +# The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation about the format. +# +# Omitting `parameters` defines a function with an empty parameter list +public type FunctionParameters record { +}; + +# The `File` object represents a document that has been uploaded to OpenAI +public type OpenAIFile record { + # The file identifier, which can be referenced in the API endpoints. + string id; + # The size of the file, in bytes. + int bytes; + # The Unix timestamp (in seconds) for when the file was created. + int created_at; + # The name of the file. + string filename; + # The object type, which is always `file`. + "file" 'object; + # The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results` and `vision`. + "assistants"|"assistants_output"|"batch"|"batch_output"|"fine-tune"|"fine-tune-results"|"vision" purpose; + # Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`. + # + # # Deprecated + @deprecated + "uploaded"|"processed"|"error" status; + # Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`. + string? status_details?; +}; + +public type ModifyAssistantRequestTools AssistantToolsCode|AssistantToolsFileSearch|AssistantToolsFunction; + +# Represents the Queries record for the operation: listBatches +public type ListBatchesQueries record { + # A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20 + int 'limit = 20; + # A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list + string after?; +}; + +public type ListVectorStoreFilesResponse record { + string 'object; + VectorStoreFileObject[] data; + string first_id; + string last_id; + boolean has_more; +}; + +public type RunStepDetailsToolCallsCodeOutputImageObjectImage record { + # The [file](/docs/api-reference/files) ID of the image + @jsondata:Name {value: "file_id"} + string fileId; +}; + +public type ChatCompletionRequestMessageContentPart ChatCompletionRequestMessageContentPartText|ChatCompletionRequestMessageContentPartImage; + +public type Batch record { + # The Unix timestamp (in seconds) for when the batch was cancelled + @jsondata:Name {value: "cancelled_at"} + int cancelledAt?; + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata?; + @jsondata:Name {value: "request_counts"} + BatchRequestCounts requestCounts?; + # The ID of the input file for the batch + @jsondata:Name {value: "input_file_id"} + string inputFileId; + # The ID of the file containing the outputs of successfully executed requests + @jsondata:Name {value: "output_file_id"} + string outputFileId?; + # The ID of the file containing the outputs of requests with errors + @jsondata:Name {value: "error_file_id"} + string errorFileId?; + # The Unix timestamp (in seconds) for when the batch was created + @jsondata:Name {value: "created_at"} + int createdAt; + # The Unix timestamp (in seconds) for when the batch started processing + @jsondata:Name {value: "in_progress_at"} + int inProgressAt?; + # The Unix timestamp (in seconds) for when the batch expired + @jsondata:Name {value: "expired_at"} + int expiredAt?; + # The Unix timestamp (in seconds) for when the batch started finalizing + @jsondata:Name {value: "finalizing_at"} + int finalizingAt?; + # The Unix timestamp (in seconds) for when the batch was completed + @jsondata:Name {value: "completed_at"} + int completedAt?; + # The OpenAI API endpoint used by the batch + string endpoint; + # The Unix timestamp (in seconds) for when the batch will expire + @jsondata:Name {value: "expires_at"} + int expiresAt?; + # The Unix timestamp (in seconds) for when the batch started cancelling + @jsondata:Name {value: "cancelling_at"} + int cancellingAt?; + # The time frame within which the batch should be processed + @jsondata:Name {value: "completion_window"} + string completionWindow; + string id; + # The Unix timestamp (in seconds) for when the batch failed + @jsondata:Name {value: "failed_at"} + int failedAt?; + BatchErrors errors?; + # The object type, which is always `batch` + "batch" 'object; + # The current status of the batch + "validating"|"failed"|"in_progress"|"finalizing"|"completed"|"expired"|"cancelling"|"cancelled" status; +}; + +public type StaticChunkingStrategy record {| + # The maximum number of tokens in each chunk. The default value is `800`. The minimum value is `100` and the maximum value is `4096` + @jsondata:Name {value: "max_chunk_size_tokens"} + int maxChunkSizeTokens; + # The number of tokens that overlap between chunks. The default value is `400`. + # + # Note that the overlap must not exceed half of `max_chunk_size_tokens` + @jsondata:Name {value: "chunk_overlap_tokens"} + int chunkOverlapTokens; +|}; + +public type CompleteUploadRequest record {| + # The ordered list of Part IDs + @jsondata:Name {value: "part_ids"} + string[] partIds; + # The optional md5 checksum for the file contents to verify if the bytes uploaded matches what you expect + string md5?; +|}; + +public type AssistantObjectToolResourcesCodeInterpreter record { + # A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter`` tool. There can be a maximum of 20 files associated with the tool + @jsondata:Name {value: "file_ids"} + string[] fileIds = []; +}; + +# References an image [File](/docs/api-reference/files) in the content of a message +public type MessageContentImageFileObject record { + @jsondata:Name {value: "image_file"} + MessageContentImageFileObjectImageFile imageFile; + # Always `image_file` + "image_file" 'type; +}; + +public type ThreadObjectToolResourcesFileSearch record { + # The [vector store](/docs/api-reference/vector-stores/object) attached to this thread. There can be a maximum of 1 vector store attached to the thread + @jsondata:Name {value: "vector_store_ids"} + string[] vectorStoreIds?; +}; + +# Represents an `assistant` that can call the model and use tools +public type AssistantObject record { + # The system instructions that the assistant uses. The maximum length is 256,000 characters + string? instructions; + @jsondata:Name {value: "tool_resources"} + AssistantObjectToolResources? toolResources?; + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata; + # The Unix timestamp (in seconds) for when the assistant was created + @jsondata:Name {value: "created_at"} + int createdAt; + # The description of the assistant. The maximum length is 512 characters + string? description; + # A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `file_search`, or `function` + @constraint:Array {maxLength: 128} + AssistantObjectTools[] tools = []; + # An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + # + # We generally recommend altering this or temperature but not both + @jsondata:Name {value: "top_p"} + decimal? topP = 1; + @jsondata:Name {value: "response_format"} + AssistantsApiResponseFormatOption responseFormat?; + # The name of the assistant. The maximum length is 256 characters + string? name; + # What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic + decimal? temperature = 1; + # ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](/docs/models/overview) for descriptions of them + string model; + # The identifier, which can be referenced in API endpoints + string id; + # The object type, which is always `assistant` + "assistant" 'object; +}; + +@deprecated +public type ChatCompletionRequestFunctionMessage record { + # The role of the messages author, in this case `function` + "function" role; + # The name of the function to call + string name; + # The contents of the function message + string? content; +}; + +public type CreateFileRequest record {| + # The File object (not file name) to be uploaded + record {byte[] fileContent; string fileName;} file; + # The intended purpose of the uploaded file. + # + # Use "assistants" for [Assistants](/docs/api-reference/assistants) and [Message](/docs/api-reference/messages) files, "vision" for Assistants image file inputs, "batch" for [Batch API](/docs/guides/batch), and "fine-tune" for [Fine-tuning](/docs/api-reference/fine-tuning) + "assistants"|"batch"|"fine-tune"|"vision" purpose; +|}; + +# The function that the model called +public type ChatCompletionMessageToolCallFunction record { + # The name of the function to call + string name; + # The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function + string arguments; +}; + +# A URL for the file that's generated when the assistant used the `code_interpreter` tool to generate a file +public type MessageContentTextAnnotationsFilePathObject record { + @jsondata:Name {value: "file_path"} + MessageContentTextAnnotationsFilePathObjectFilePath filePath; + @jsondata:Name {value: "start_index"} + int startIndex; + @jsondata:Name {value: "end_index"} + int endIndex; + # The text in the message content that needs to be replaced + string text; + # Always `file_path` + "file_path" 'type; +}; + +public type CreateThreadAndRunRequest record {| + # Override the default system message of the assistant. This is useful for modifying the behavior on a per-run basis + string? instructions?; + @jsondata:Name {value: "tool_resources"} + CreateThreadAndRunRequestToolResources? toolResources?; + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata?; + # The ID of the [assistant](/docs/api-reference/assistants) to use to execute this run + @jsondata:Name {value: "assistant_id"} + string assistantId; + CreateThreadRequest thread?; + # Override the tools the assistant can use for this run. This is useful for modifying the behavior on a per-run basis + CreateThreadAndRunRequestTools[]? tools?; + @jsondata:Name {value: "truncation_strategy"} + TruncationObject truncationStrategy?; + # An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + # + # We generally recommend altering this or temperature but not both + @jsondata:Name {value: "top_p"} + decimal? topP = 1; + # The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort to use only the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of completion tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info + @jsondata:Name {value: "max_completion_tokens"} + int? maxCompletionTokens?; + @jsondata:Name {value: "response_format"} + AssistantsApiResponseFormatOption responseFormat?; + @jsondata:Name {value: "parallel_tool_calls"} + ParallelToolCalls parallelToolCalls?; + # If `true`, returns a stream of events that happen during the Run as server-sent events, terminating when the Run enters a terminal state with a `data: [DONE]` message + boolean? 'stream?; + # What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic + decimal? temperature = 1; + @jsondata:Name {value: "tool_choice"} + AssistantsApiToolChoiceOption toolChoice?; + # The ID of the [Model](/docs/api-reference/models) to be used to execute this run. If a value is provided here, it will override the model associated with the assistant. If not, the model associated with the assistant will be used + string|"gpt-4o"|"gpt-4o-2024-05-13"|"gpt-4o-mini"|"gpt-4o-mini-2024-07-18"|"gpt-4-turbo"|"gpt-4-turbo-2024-04-09"|"gpt-4-0125-preview"|"gpt-4-turbo-preview"|"gpt-4-1106-preview"|"gpt-4-vision-preview"|"gpt-4"|"gpt-4-0314"|"gpt-4-0613"|"gpt-4-32k"|"gpt-4-32k-0314"|"gpt-4-32k-0613"|"gpt-3.5-turbo"|"gpt-3.5-turbo-16k"|"gpt-3.5-turbo-0613"|"gpt-3.5-turbo-1106"|"gpt-3.5-turbo-0125"|"gpt-3.5-turbo-16k-0613"? model?; + # The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info + @jsondata:Name {value: "max_prompt_tokens"} + int? maxPromptTokens?; +|}; + +public type CreateThreadRequestToolResourcesCodeInterpreter record { + # A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool + @jsondata:Name {value: "file_ids"} + string[] fileIds = []; +}; + +# Fine-tuning job event object +public type FineTuningJobEvent record { + "info"|"warn"|"error" level; + @jsondata:Name {value: "created_at"} + int createdAt; + string id; + string message; + "fine_tuning.job.event" 'object; +}; + +# The settings for your integration with Weights and Biases. This payload specifies the project that +# metrics will be sent to. Optionally, you can set an explicit display name for your run, add tags +# to your run, and set a default entity (team, username, etc) to be associated with your run +public type FineTuningIntegrationWandb record { + # A display name to set for the run. If not set, we will use the Job ID as the name + string? name?; + # The name of the project that the new run will be created under + string project; + # The entity to use for the run. This allows you to set the team or username of the WandB user that you would + # like associated with the run. If not set, the default entity for the registered WandB API key is used + string? entity?; + # A list of tags to be attached to the newly created run. These tags are passed through directly to WandB. Some + # default tags are generated by OpenAI: "openai/finetune", "openai/{base-model}", "openai/{ftjob-abcdef}" + string[] tags?; +}; + +# Specifies a tool the model should use. Use to force the model to call a specific tool +public type AssistantsNamedToolChoice record { + AssistantsNamedToolChoiceFunction 'function?; + # The type of the tool. If type is `function`, the function name must be set + "function"|"code_interpreter"|"file_search" 'type; +}; + +public type ListRunStepsResponse record { + string 'object; + RunStepObject[] data; + string first_id; + string last_id; + boolean has_more; +}; + +# Represents a message within a [thread](/docs/api-reference/threads) +public type MessageObject record { + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata; + # The entity that produced the message. One of `user` or `assistant` + "user"|"assistant" role; + # If applicable, the ID of the [assistant](/docs/api-reference/assistants) that authored this message + @jsondata:Name {value: "assistant_id"} + string? assistantId; + # The ID of the [run](/docs/api-reference/runs) associated with the creation of this message. Value is `null` when messages are created manually using the create message or create thread endpoints + @jsondata:Name {value: "run_id"} + string? runId; + # A list of files attached to the message, and the tools they were added to + MessageObjectAttachments[]? attachments; + # The Unix timestamp (in seconds) for when the message was created + @jsondata:Name {value: "created_at"} + int createdAt; + # The content of the message in array of text and/or images + MessageObjectContent[] content; + # The Unix timestamp (in seconds) for when the message was completed + @jsondata:Name {value: "completed_at"} + int? completedAt; + # The [thread](/docs/api-reference/threads) ID that this message belongs to + @jsondata:Name {value: "thread_id"} + string threadId; + # The identifier, which can be referenced in API endpoints + string id; + # The Unix timestamp (in seconds) for when the message was marked as incomplete + @jsondata:Name {value: "incomplete_at"} + int? incompleteAt; + @jsondata:Name {value: "incomplete_details"} + MessageObjectIncompleteDetails? incompleteDetails; + # The object type, which is always `thread.message` + "thread.message" 'object; + # The status of the message, which can be either `in_progress`, `incomplete`, or `completed` + "in_progress"|"incomplete"|"completed" status; +}; + +public type CreateFineTuningJobRequest record { + # The ID of an uploaded file that contains training data. + # + # See [upload file](/docs/api-reference/files/create) for how to upload a file. + # + # Your dataset must be formatted as a JSONL file. Additionally, you must upload your file with the purpose `fine-tune`. + # + # The contents of the file should differ depending on if the model uses the [chat](/docs/api-reference/fine-tuning/chat-input) or [completions](/docs/api-reference/fine-tuning/completions-input) format. + # + # See the [fine-tuning guide](/docs/guides/fine-tuning) for more details + @jsondata:Name {value: "training_file"} + string trainingFile; + # The seed controls the reproducibility of the job. Passing in the same seed and job parameters should produce the same results, but may differ in rare cases. + # If a seed is not specified, one will be generated for you + int? seed?; + # The ID of an uploaded file that contains validation data. + # + # If you provide this file, the data is used to generate validation + # metrics periodically during fine-tuning. These metrics can be viewed in + # the fine-tuning results file. + # The same data should not be present in both train and validation files. + # + # Your dataset must be formatted as a JSONL file. You must upload your file with the purpose `fine-tune`. + # + # See the [fine-tuning guide](/docs/guides/fine-tuning) for more details + @jsondata:Name {value: "validation_file"} + string? validationFile?; + CreateFineTuningJobRequestHyperparameters hyperparameters?; + # The name of the model to fine-tune. You can select one of the + # [supported models](/docs/guides/fine-tuning/what-models-can-be-fine-tuned) + string|"babbage-002"|"davinci-002"|"gpt-3.5-turbo" model; + # A string of up to 18 characters that will be added to your fine-tuned model name. + # + # For example, a `suffix` of "custom-model-name" would produce a model name like `ft:gpt-3.5-turbo:openai:custom-model-name:7p4lURel` + string? suffix?; + # A list of integrations to enable for your fine-tuning job + CreateFineTuningJobRequestIntegrations[]? integrations?; +}; + +public type MessageContentImageUrlObjectImageUrl record { + # Specifies the detail level of the image. `low` uses fewer tokens, you can opt in to high resolution using `high`. Default value is `auto` + "auto"|"low"|"high" detail = "auto"; + # The external URL of the image, must be a supported image types: jpeg, jpg, png, gif, webp + string url; +}; + +public type CreateFineTuningJobRequestIntegrations record { + CreateFineTuningJobRequestWandb wandb; + # The type of integration to enable. Currently, only "wandb" (Weights and Biases) is supported + "wandb" 'type; +}; + +public type ChatCompletionTokenLogprob record { + # List of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested `top_logprobs` returned + @jsondata:Name {value: "top_logprobs"} + ChatCompletionTokenLogprobTopLogprobs[] topLogprobs; + # The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value `-9999.0` is used to signify that the token is very unlikely + decimal logprob; + # A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be `null` if there is no bytes representation for the token + int[]? bytes; + # The token + string token; +}; + +# `auto` is the default value +public type AssistantsApiResponseFormatOptionOneOf1 "none"|"auto"; + +public type ChatCompletionRequestMessage ChatCompletionRequestSystemMessage|ChatCompletionRequestUserMessage|ChatCompletionRequestAssistantMessage|ChatCompletionRequestToolMessage|ChatCompletionRequestFunctionMessage; + +# Represents the url or the content of an image generated by the OpenAI API +public type Image record { + # The prompt that was used to generate the image, if there was any revision to the prompt + @jsondata:Name {value: "revised_prompt"} + string revisedPrompt?; + # The base64-encoded JSON of the generated image, if `response_format` is `b64_json` + @jsondata:Name {value: "b64_json"} + string b64Json?; + # The URL of the generated image, if `response_format` is `url` (default) + string url?; +}; + +# The hyperparameters used for the fine-tuning job +public type CreateFineTuningJobRequestHyperparameters record { + # Number of examples in each batch. A larger batch size means that model parameters + # are updated less frequently, but with lower variance + @jsondata:Name {value: "batch_size"} + "auto"|int batchSize = "auto"; + # The number of epochs to train the model for. An epoch refers to one full cycle + # through the training dataset + @jsondata:Name {value: "n_epochs"} + "auto"|int nEpochs = "auto"; + # Scaling factor for the learning rate. A smaller learning rate may be useful to avoid + # overfitting + @jsondata:Name {value: "learning_rate_multiplier"} + "auto"|decimal learningRateMultiplier = "auto"; +}; + +# The last error associated with this run. Will be `null` if there are no errors +public type RunObjectLastError record { + # One of `server_error`, `rate_limit_exceeded`, or `invalid_prompt` + "server_error"|"rate_limit_exceeded"|"invalid_prompt" code; + # A human-readable description of the error + string message; +}; + +public type CreateAssistantRequestTools AssistantToolsCode|AssistantToolsFileSearch|AssistantToolsFunction; + +# Represents a verbose json transcription response returned by model, based on the provided input +public type CreateTranscriptionResponseVerboseJson record { + # The duration of the input audio + string duration; + # Extracted words and their corresponding timestamps + TranscriptionWord[] words?; + # The language of the input audio + string language; + # The transcribed text + string text; + # Segments of the transcribed text and their corresponding details + TranscriptionSegment[] segments?; +}; + +public type CreateRunRequestTools AssistantToolsCode|AssistantToolsFileSearch|AssistantToolsFunction; + +public type CreateTranslationRequest record {| + # The audio file object (not file name) translate, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm + record {byte[] fileContent; string fileName;} file; + # The format of the transcript output, in one of these options: `json`, `text`, `srt`, `verbose_json`, or `vtt` + @jsondata:Name {value: "response_format"} + string responseFormat = "json"; + # The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit + decimal temperature = 0; + # ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2 model) is currently available + string|"whisper-1" model; + # An optional text to guide the model's style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text/prompting) should be in English + string prompt?; +|}; + +public type UpdateVectorStoreRequest record {| + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata?; + @jsondata:Name {value: "expires_after"} + VectorStoreExpirationAfter expiresAfter?; + # The name of the vector store + string? name?; +|}; + +# The settings for your integration with Weights and Biases. This payload specifies the project that +# metrics will be sent to. Optionally, you can set an explicit display name for your run, add tags +# to your run, and set a default entity (team, username, etc) to be associated with your run +public type CreateFineTuningJobRequestWandb record { + # A display name to set for the run. If not set, we will use the Job ID as the name + string? name?; + # The name of the project that the new run will be created under + string project; + # The entity to use for the run. This allows you to set the team or username of the WandB user that you would + # like associated with the run. If not set, the default entity for the registered WandB API key is used + string? entity?; + # A list of tags to be attached to the newly created run. These tags are passed through directly to WandB. Some + # default tags are generated by OpenAI: "openai/finetune", "openai/{base-model}", "openai/{ftjob-abcdef}" + string[] tags?; +}; + +@deprecated +public type ChatCompletionFunctions record { + # The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64 + string name; + # A description of what the function does, used by the model to choose when and how to call the function + string description?; + FunctionParameters parameters?; +}; + +public type AddUploadPartRequest record {| + # The chunk of bytes for this Part + record {byte[] fileContent; string fileName;} data; +|}; + +# The usage information for the request +public type CreateEmbeddingResponseUsage record { + # The number of tokens used by the prompt + @jsondata:Name {value: "prompt_tokens"} + int promptTokens; + # The total number of tokens used by the request + @jsondata:Name {value: "total_tokens"} + int totalTokens; +}; + +public type AssistantToolsCode record { + # The type of tool being defined: `code_interpreter` + "code_interpreter" 'type; +}; + +# This is returned when the chunking strategy is unknown. Typically, this is because the file was indexed before the `chunking_strategy` concept was introduced in the API +public type OtherChunkingStrategyResponseParam record {| + # Always `other` + "other" 'type; +|}; + +public type ChatCompletionRequestMessageContentPartImage record { + @jsondata:Name {value: "image_url"} + ChatCompletionRequestMessageContentPartImageImageUrl imageUrl; + # The type of the content part + "image_url" 'type; +}; + +public type AssistantObjectToolResourcesFileSearch record { + # The ID of the [vector store](/docs/api-reference/vector-stores/object) attached to this assistant. There can be a maximum of 1 vector store attached to the assistant + @jsondata:Name {value: "vector_store_ids"} + string[] vectorStoreIds?; +}; + +public type BatchesBody record { + # The endpoint to be used for all requests in the batch. Currently `/v1/chat/completions`, `/v1/embeddings`, and `/v1/completions` are supported. Note that `/v1/embeddings` batches are also restricted to a maximum of 50,000 embedding inputs across all requests in the batch + "/v1/chat/completions"|"/v1/embeddings"|"/v1/completions" endpoint; + # Optional custom metadata for the batch + record {|string...;|}? metadata?; + # The ID of an uploaded file that contains requests for the new batch. + # + # See [upload file](/docs/api-reference/files/create) for how to upload a file. + # + # Your input file must be formatted as a [JSONL file](/docs/api-reference/batch/request-input), and must be uploaded with the purpose `batch`. The file can contain up to 50,000 requests, and can be up to 100 MB in size + @jsondata:Name {value: "input_file_id"} + string inputFileId; + # The time frame within which the batch should be processed. Currently only `24h` is supported + @jsondata:Name {value: "completion_window"} + "24h" completionWindow; +}; + +# A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs +public type ModifyThreadRequestToolResources record { + @jsondata:Name {value: "code_interpreter"} + ModifyThreadRequestToolResourcesCodeInterpreter codeInterpreter?; + @jsondata:Name {value: "file_search"} + ModifyThreadRequestToolResourcesFileSearch fileSearch?; +}; + +public type CreateVectorStoreFileBatchRequest record {| + @jsondata:Name {value: "chunking_strategy"} + ChunkingStrategyRequestParam chunkingStrategy?; + # A list of [File](/docs/api-reference/files) IDs that the vector store should use. Useful for tools like `file_search` that can access files + @jsondata:Name {value: "file_ids"} + string[] fileIds; +|}; + +# The Code Interpreter tool call definition +public type RunStepDetailsToolCallsCodeObjectCodeInterpreter record { + # The outputs from the Code Interpreter tool call. Code Interpreter can output one or more items, including text (`logs`) or images (`image`). Each of these are represented by a different object type + RunStepDetailsToolCallsCodeObjectCodeInterpreterOutputs[] outputs; + # The input to the Code Interpreter tool call + string input; +}; + +public type CreateThreadRequest record {| + @jsondata:Name {value: "tool_resources"} + CreateThreadRequestToolResources? toolResources?; + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata?; + # A list of [messages](/docs/api-reference/messages) to start the thread with + CreateMessageRequest[] messages?; +|}; + +public type ModifyAssistantRequestToolResourcesFileSearch record { + # Overrides the [vector store](/docs/api-reference/vector-stores/object) attached to this assistant. There can be a maximum of 1 vector store attached to the assistant + @jsondata:Name {value: "vector_store_ids"} + string[] vectorStoreIds?; +}; + +# On an incomplete message, details about why the message is incomplete +public type MessageObjectIncompleteDetails record { + # The reason the message is incomplete + "content_filter"|"max_tokens"|"run_cancelled"|"run_expired"|"run_failed" reason; +}; + +public type StaticChunkingStrategyRequestParam record {| + StaticChunkingStrategy static; + # Always `static` + "static" 'type; +|}; + +# A list of files attached to a vector store +public type VectorStoreFileObject record { + # The strategy used to chunk the file + @jsondata:Name {value: "chunking_strategy"} + StaticChunkingStrategyResponseParam|OtherChunkingStrategyResponseParam chunkingStrategy?; + # The total vector store usage in bytes. Note that this may be different from the original file size + @jsondata:Name {value: "usage_bytes"} + int usageBytes; + # The Unix timestamp (in seconds) for when the vector store file was created + @jsondata:Name {value: "created_at"} + int createdAt; + # The identifier, which can be referenced in API endpoints + string id; + @jsondata:Name {value: "last_error"} + VectorStoreFileObjectLastError? lastError; + # The object type, which is always `vector_store.file` + "vector_store.file" 'object; + # The ID of the [vector store](/docs/api-reference/vector-stores/object) that the [File](/docs/api-reference/files) is attached to + @jsondata:Name {value: "vector_store_id"} + string vectorStoreId; + # The status of the vector store file, which can be either `in_progress`, `completed`, `cancelled`, or `failed`. The status `completed` indicates that the vector store file is ready for use + "in_progress"|"completed"|"cancelled"|"failed" status; +}; + +public type CreateThreadRequestToolResourcesFileSearch anydata; + +# The Upload object can accept byte chunks in the form of Parts +public type Upload record { + # The name of the file to be uploaded + string filename; + # The Unix timestamp (in seconds) for when the Upload was created + @jsondata:Name {value: "expires_at"} + int expiresAt; + OpenAIFile file?; + # The intended purpose of the file. [Please refer here](/docs/api-reference/files/object#files/object-purpose) for acceptable values + string purpose; + # The intended number of bytes to be uploaded + int bytes; + # The Unix timestamp (in seconds) for when the Upload was created + @jsondata:Name {value: "created_at"} + int createdAt; + # The Upload unique identifier, which can be referenced in API endpoints + string id; + # The status of the Upload + "pending"|"completed"|"cancelled"|"expired" status; + # The object type, which is always "upload" + "upload" 'object?; +}; + +# The last error associated with this vector store file. Will be `null` if there are no errors +public type VectorStoreFileObjectLastError record { + # One of `server_error` or `rate_limit_exceeded` + "internal_error"|"file_not_found"|"parsing_error"|"unhandled_mime_type" code; + # A human-readable description of the error + string message; +}; + +# For fine-tuning jobs that have `failed`, this will contain more information on the cause of the failure +public type FineTuningJobError record { + # A machine-readable error code + string code?; + # The parameter that was invalid, usually `training_file` or `validation_file`. This field will be null if the failure was not parameter-specific + string? param?; + # A human-readable error message + string message?; +}; + +# The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy +public type ChunkingStrategyRequestParam AutoChunkingStrategyRequestParam|StaticChunkingStrategyRequestParam; + +# A list of the categories along with their scores as predicted by model +public type CreateModerationResponseCategoryScores record { + # The score for the category 'self-harm/intent' + @jsondata:Name {value: "self-harm/intent"} + decimal selfHarmIntent; + # The score for the category 'hate/threatening' + @jsondata:Name {value: "hate/threatening"} + decimal hateThreatening; + # The score for the category 'self-harm/instructions' + @jsondata:Name {value: "self-harm/instructions"} + decimal selfHarmInstructions; + # The score for the category 'sexual/minors' + @jsondata:Name {value: "sexual/minors"} + decimal sexualMinors; + # The score for the category 'harassment/threatening' + @jsondata:Name {value: "harassment/threatening"} + decimal harassmentThreatening; + # The score for the category 'hate' + decimal hate; + # The score for the category 'self-harm' + @jsondata:Name {value: "self-harm"} + decimal selfHarm; + # The score for the category 'harassment' + decimal harassment; + # The score for the category 'sexual' + decimal sexual; + # The score for the category 'violence/graphic' + @jsondata:Name {value: "violence/graphic"} + decimal violenceGraphic; + # The score for the category 'violence' + decimal violence; +}; + +# Usage statistics related to the run. This value will be `null` if the run is not in a terminal state (i.e. `in_progress`, `queued`, etc.) +public type RunCompletionUsage record { + # Number of completion tokens used over the course of the run + @jsondata:Name {value: "completion_tokens"} + int completionTokens; + # Number of prompt tokens used over the course of the run + @jsondata:Name {value: "prompt_tokens"} + int promptTokens; + # Total number of tokens used (prompt + completion) + @jsondata:Name {value: "total_tokens"} + int totalTokens; +}; + +# Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model +# +# # Deprecated +@deprecated +public type ChatCompletionResponseMessageFunctionCall record { + # The name of the function to call + string name; + # The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function + string arguments; +}; + +# References an image URL in the content of a message +public type MessageContentImageUrlObject record { + @jsondata:Name {value: "image_url"} + MessageContentImageUrlObjectImageUrl imageUrl; + # The type of the content part + "image_url" 'type; +}; + +public type CreateCompletionResponseChoices record { + # The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence, + # `length` if the maximum number of tokens specified in the request was reached, + # or `content_filter` if content was omitted due to a flag from our content filters + @jsondata:Name {value: "finish_reason"} + "stop"|"length"|"content_filter" finishReason; + int index; + string text; + CreateCompletionResponseLogprobs? logprobs; +}; + +public type ImagesResponse record { + int created; + Image[] data; +}; + +public type DeleteModelResponse record { + boolean deleted; + string id; + string 'object; +}; + +public type ChatCompletionMessageToolCall record { + ChatCompletionMessageToolCallFunction 'function; + # The ID of the tool call + string id; + # The type of the tool. Currently, only `function` is supported + "function" 'type; +}; + +public type VectorStoreFileBatchObjectFileCounts record { + # The number of files that are currently being processed + @jsondata:Name {value: "in_progress"} + int inProgress; + # The total number of files + int total; + # The number of files that where cancelled + int cancelled; + # The number of files that have been processed + int completed; + # The number of files that have failed to process + int failed; +}; + +public type CreateImageEditRequest record { + # The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask + record {byte[] fileContent; string fileName;} image; + # The format in which the generated images are returned. Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes after the image has been generated + @jsondata:Name {value: "response_format"} + "url"|"b64_json"? responseFormat = "url"; + # The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024` + "256x256"|"512x512"|"1024x1024"? size = "1024x1024"; + # The model to use for image generation. Only `dall-e-2` is supported at this time + string|"dall-e-2"? model = "dall-e-2"; + # A text description of the desired image(s). The maximum length is 1000 characters + string prompt; + # A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids) + string user?; + # The number of images to generate. Must be between 1 and 10 + int? n = 1; + # An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where `image` should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as `image` + record {byte[] fileContent; string fileName;} mask?; +}; + +# Overrides for the file search tool +public type AssistantToolsFileSearchFileSearch record { + # The maximum number of results the file search tool should output. The default is 20 for gpt-4* models and 5 for gpt-3.5-turbo. This number should be between 1 and 50 inclusive. + # + # Note that the file search tool may output fewer than `max_num_results` results. See the [file search tool documentation](/docs/assistants/tools/file-search/number-of-chunks-returned) for more information + @jsondata:Name {value: "max_num_results"} + int maxNumResults?; +}; + +public type ListModelsResponse record { + Model[] data; + "list" 'object; +}; + +public type AssistantObjectTools AssistantToolsCode|AssistantToolsFileSearch|AssistantToolsFunction; + +# Describes an OpenAI model offering that can be used with the API +public type Model record { + # The model identifier, which can be referenced in the API endpoints. + string id; + # The Unix timestamp (in seconds) when the model was created. + int created; + # The object type, which is always "model". + "model" 'object; + # The organization that owns the model. + string owned_by; +}; + +public type ListFilesResponse record { + OpenAIFile[] data; + "list" 'object; +}; + +public type CreateVectorStoreRequest record {| + # The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy. Only applicable if `file_ids` is non-empty + @jsondata:Name {value: "chunking_strategy"} + AutoChunkingStrategyRequestParam|StaticChunkingStrategyRequestParam chunkingStrategy?; + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata?; + @jsondata:Name {value: "expires_after"} + VectorStoreExpirationAfter expiresAfter?; + # A list of [File](/docs/api-reference/files) IDs that the vector store should use. Useful for tools like `file_search` that can access files + @jsondata:Name {value: "file_ids"} + string[] fileIds?; + # The name of the vector store + string name?; +|}; + +public type CreateChatCompletionResponseChoices record { + # The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence, + # `length` if the maximum number of tokens specified in the request was reached, + # `content_filter` if content was omitted due to a flag from our content filters, + # `tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function + @jsondata:Name {value: "finish_reason"} + "stop"|"length"|"tool_calls"|"content_filter"|"function_call" finishReason; + # The index of the choice in the list of choices + int index; + ChatCompletionResponseMessage message; + CreateChatCompletionResponseLogprobs? logprobs; +}; + +# Represents a thread that contains [messages](/docs/api-reference/messages) +public type ThreadObject record { + @jsondata:Name {value: "tool_resources"} + ThreadObjectToolResources? toolResources; + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata; + # The Unix timestamp (in seconds) for when the thread was created + @jsondata:Name {value: "created_at"} + int createdAt; + # The identifier, which can be referenced in API endpoints + string id; + # The object type, which is always `thread` + "thread" 'object; +}; + +# Options for streaming response. Only set this when you set `stream: true` +public type ChatCompletionStreamOptions record { + # If set, an additional chunk will be streamed before the `data: [DONE]` message. The `usage` field on this chunk shows the token usage statistics for the entire request, and the `choices` field will always be an empty array. All other chunks will also include a `usage` field, but with a null value + @jsondata:Name {value: "include_usage"} + boolean includeUsage?; +}; + +# A citation within the message that points to a specific quote from a specific File associated with the assistant or the message. Generated when the assistant uses the "file_search" tool to search files +public type MessageContentTextAnnotationsFileCitationObject record { + @jsondata:Name {value: "start_index"} + int startIndex; + @jsondata:Name {value: "file_citation"} + MessageContentTextAnnotationsFileCitationObjectFileCitation fileCitation; + @jsondata:Name {value: "end_index"} + int endIndex; + # The text in the message content that needs to be replaced + string text; + # Always `file_citation` + "file_citation" 'type; +}; + +public type ListPaginatedFineTuningJobsResponse record { + FineTuningJob[] data; + @jsondata:Name {value: "has_more"} + boolean hasMore; + "list" 'object; +}; + +public type ModifyAssistantRequest record {| + # An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + # + # We generally recommend altering this or temperature but not both + @jsondata:Name {value: "top_p"} + decimal? topP = 1; + # The system instructions that the assistant uses. The maximum length is 256,000 characters + string? instructions?; + @jsondata:Name {value: "tool_resources"} + ModifyAssistantRequestToolResources? toolResources?; + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata?; + @jsondata:Name {value: "response_format"} + AssistantsApiResponseFormatOption responseFormat?; + # The name of the assistant. The maximum length is 256 characters + string? name?; + # What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic + decimal? temperature = 1; + # The description of the assistant. The maximum length is 512 characters + string? description?; + # ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](/docs/models/overview) for descriptions of them + string model?; + # A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `file_search`, or `function` + @constraint:Array {maxLength: 128} + ModifyAssistantRequestTools[] tools = []; +|}; + +# Metrics at the step number during the fine-tuning job +public type FineTuningJobCheckpointMetrics record { + @jsondata:Name {value: "full_valid_mean_token_accuracy"} + decimal fullValidMeanTokenAccuracy?; + @jsondata:Name {value: "valid_loss"} + decimal validLoss?; + @jsondata:Name {value: "full_valid_loss"} + decimal fullValidLoss?; + @jsondata:Name {value: "train_mean_token_accuracy"} + decimal trainMeanTokenAccuracy?; + @jsondata:Name {value: "valid_mean_token_accuracy"} + decimal validMeanTokenAccuracy?; + @jsondata:Name {value: "train_loss"} + decimal trainLoss?; + decimal step?; +}; + +public type MessageContentTextObjectTextAnnotations MessageContentTextAnnotationsFileCitationObject|MessageContentTextAnnotationsFilePathObject; + +public type ChatCompletionRequestAssistantMessage record { + # The role of the messages author, in this case `assistant` + "assistant" role; + @jsondata:Name {value: "function_call"} + ChatCompletionRequestAssistantMessageFunctionCall? functionCall?; + # An optional name for the participant. Provides the model information to differentiate between participants of the same role + string name?; + @jsondata:Name {value: "tool_calls"} + ChatCompletionMessageToolCalls toolCalls?; + # The contents of the assistant message. Required unless `tool_calls` or `function_call` is specified + string? content?; +}; + +# The last error associated with this run step. Will be `null` if there are no errors +public type RunStepObjectLastError record { + # One of `server_error` or `rate_limit_exceeded` + "server_error"|"rate_limit_exceeded" code; + # A human-readable description of the error + string message; +}; + +public type ListVectorStoresResponse record { + string 'object; + VectorStoreObject[] data; + string first_id; + string last_id; + boolean has_more; +}; + +public type RunObjectTools AssistantToolsCode|AssistantToolsFileSearch|AssistantToolsFunction; + +# Details of the Code Interpreter tool call the run step was involved in +public type RunStepDetailsToolCallsCodeObject record { + @jsondata:Name {value: "code_interpreter"} + RunStepDetailsToolCallsCodeObjectCodeInterpreter codeInterpreter; + # The ID of the tool call + string id; + # The type of tool call. This is always going to be `code_interpreter` for this type of tool call + "code_interpreter" 'type; +}; + +# Represents if a given text input is potentially harmful +public type CreateModerationResponse record { + # The model used to generate the moderation results + string model; + # The unique identifier for the moderation request + string id; + # A list of moderation objects + CreateModerationResponseResults[] results; +}; + +public type FineTuningIntegration record { + FineTuningIntegrationWandb wandb; + # The type of the integration being enabled for the fine-tuning job + "wandb" 'type; +}; + +public type SubmitToolOutputsRunRequest record {| + # If `true`, returns a stream of events that happen during the Run as server-sent events, terminating when the Run enters a terminal state with a `data: [DONE]` message + boolean? 'stream?; + # A list of tools for which the outputs are being submitted + @jsondata:Name {value: "tool_outputs"} + SubmitToolOutputsRunRequestToolOutputs[] toolOutputs; +|}; + +# A batch of files attached to a vector store +public type VectorStoreFileBatchObject record { + @jsondata:Name {value: "file_counts"} + VectorStoreFileBatchObjectFileCounts fileCounts; + # The Unix timestamp (in seconds) for when the vector store files batch was created + @jsondata:Name {value: "created_at"} + int createdAt; + # The identifier, which can be referenced in API endpoints + string id; + # The object type, which is always `vector_store.file_batch` + "vector_store.files_batch" 'object; + # The ID of the [vector store](/docs/api-reference/vector-stores/object) that the [File](/docs/api-reference/files) is attached to + @jsondata:Name {value: "vector_store_id"} + string vectorStoreId; + # The status of the vector store files batch, which can be either `in_progress`, `completed`, `cancelled` or `failed` + "in_progress"|"completed"|"cancelled"|"failed" status; +}; + +public type MessageContentTextAnnotationsFilePathObjectFilePath record { + # The ID of the file that was generated + @jsondata:Name {value: "file_id"} + string fileId; +}; + +# A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs +public type CreateThreadAndRunRequestToolResources record { + @jsondata:Name {value: "code_interpreter"} + CreateThreadAndRunRequestToolResourcesCodeInterpreter codeInterpreter?; + @jsondata:Name {value: "file_search"} + CreateThreadAndRunRequestToolResourcesFileSearch fileSearch?; +}; + +public type ModifyRunRequest record {| + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata?; +|}; + +# Specifying a particular function via `{"name": "my_function"}` forces the model to call that function +public type ChatCompletionFunctionCallOption record { + # The name of the function to call + string name; +}; + +# The `fine_tuning.job` object represents a fine-tuning job that has been created through the API +public type FineTuningJob record { + # The file ID used for training. You can retrieve the training data with the [Files API](/docs/api-reference/files/retrieve-contents) + @jsondata:Name {value: "training_file"} + string trainingFile; + # The compiled results file ID(s) for the fine-tuning job. You can retrieve the results with the [Files API](/docs/api-reference/files/retrieve-contents) + @jsondata:Name {value: "result_files"} + string[] resultFiles; + # The Unix timestamp (in seconds) for when the fine-tuning job was finished. The value will be null if the fine-tuning job is still running + @jsondata:Name {value: "finished_at"} + int? finishedAt; + # The seed used for the fine-tuning job + int seed; + # The name of the fine-tuned model that is being created. The value will be null if the fine-tuning job is still running + @jsondata:Name {value: "fine_tuned_model"} + string? fineTunedModel; + # The file ID used for validation. You can retrieve the validation results with the [Files API](/docs/api-reference/files/retrieve-contents) + @jsondata:Name {value: "validation_file"} + string? validationFile; + # The Unix timestamp (in seconds) for when the fine-tuning job was created + @jsondata:Name {value: "created_at"} + int createdAt; + FineTuningJobError? 'error; + # The Unix timestamp (in seconds) for when the fine-tuning job is estimated to finish. The value will be null if the fine-tuning job is not running + @jsondata:Name {value: "estimated_finish"} + int? estimatedFinish?; + # The organization that owns the fine-tuning job + @jsondata:Name {value: "organization_id"} + string organizationId; + FineTuningJobHyperparameters hyperparameters; + # The base model that is being fine-tuned + string model; + # The object identifier, which can be referenced in the API endpoints + string id; + # The total number of billable tokens processed by this fine-tuning job. The value will be null if the fine-tuning job is still running + @jsondata:Name {value: "trained_tokens"} + int? trainedTokens; + # A list of integrations to enable for this fine-tuning job + FineTuningJobIntegrations[]? integrations?; + # The object type, which is always "fine_tuning.job" + "fine_tuning.job" 'object; + # The current status of the fine-tuning job, which can be either `validating_files`, `queued`, `running`, `succeeded`, `failed`, or `cancelled` + "validating_files"|"queued"|"running"|"succeeded"|"failed"|"cancelled" status; +}; + +public type ChatCompletionRequestSystemMessage record { + # The role of the messages author, in this case `system` + "system" role; + # An optional name for the participant. Provides the model information to differentiate between participants of the same role + string name?; + # The contents of the system message + string content; +}; + +public type CreateTranslationResponseVerboseJson record { + # The duration of the input audio + string duration; + # The language of the output translation (always `english`) + string language; + # The translated text + string text; + # Segments of the translated text and their corresponding details + TranscriptionSegment[] segments?; +}; + +# Represents the Queries record for the operation: listAssistants +public type ListAssistantsQueries record { + # A cursor for use in pagination. `before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list + string before?; + # A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20 + int 'limit = 20; + # A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list + string after?; + # Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order + "asc"|"desc" 'order = "desc"; +}; + +public type MessageContentTextObjectText record { + MessageContentTextObjectTextAnnotations[] annotations; + # The data that makes up the text + string value; +}; + +public type MessageObjectAttachments record { + # The ID of the file to attach to the message + @jsondata:Name {value: "file_id"} + string fileId?; + # The tools to add this file to + MessageObjectTools[] tools?; +}; + +public type CreateCompletionResponseLogprobs record { + @jsondata:Name {value: "top_logprobs"} + record {||}[] topLogprobs?; + @jsondata:Name {value: "token_logprobs"} + decimal[] tokenLogprobs?; + string[] tokens?; + @jsondata:Name {value: "text_offset"} + int[] textOffset?; +}; + +public type FineTuningJobIntegrations FineTuningIntegration; + +public type DeleteFileResponse record { + boolean deleted; + string id; + "file" 'object; +}; + +public type ListFineTuningJobEventsResponse record { + FineTuningJobEvent[] data; + "list" 'object; +}; + +public type CreateMessageRequest record {| + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata?; + # The role of the entity that is creating the message. Allowed values include: + # - `user`: Indicates the message is sent by an actual user and should be used in most cases to represent user-generated messages. + # - `assistant`: Indicates the message is generated by the assistant. Use this value to insert messages from the assistant into the conversation + "user"|"assistant" role; + # A list of files attached to the message, and the tools they should be added to + CreateMessageRequestAttachments[]? attachments?; + string|(MessageContentImageFileObject|MessageContentImageUrlObject|MessageRequestContentTextObject)[] content; +|}; + +public type CreateAssistantRequestToolResourcesFileSearch anydata; + +# Represents a step in execution of a run +public type RunStepObject record { + # The Unix timestamp (in seconds) for when the run step was cancelled + @jsondata:Name {value: "cancelled_at"} + int? cancelledAt; + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata; + # The ID of the [assistant](/docs/api-reference/assistants) associated with the run step + @jsondata:Name {value: "assistant_id"} + string assistantId; + # The ID of the [run](/docs/api-reference/runs) that this run step is a part of + @jsondata:Name {value: "run_id"} + string runId; + RunStepCompletionUsage? usage; + # The Unix timestamp (in seconds) for when the run step was created + @jsondata:Name {value: "created_at"} + int createdAt; + # The Unix timestamp (in seconds) for when the run step expired. A step is considered expired if the parent run is expired + @jsondata:Name {value: "expired_at"} + int? expiredAt; + # The type of run step, which can be either `message_creation` or `tool_calls` + "message_creation"|"tool_calls" 'type; + # The details of the run step + @jsondata:Name {value: "step_details"} + RunStepDetailsMessageCreationObject|RunStepDetailsToolCallsObject stepDetails; + # The Unix timestamp (in seconds) for when the run step completed + @jsondata:Name {value: "completed_at"} + int? completedAt; + # The ID of the [thread](/docs/api-reference/threads) that was run + @jsondata:Name {value: "thread_id"} + string threadId; + # The identifier of the run step, which can be referenced in API endpoints + string id; + @jsondata:Name {value: "last_error"} + RunStepObjectLastError? lastError; + # The Unix timestamp (in seconds) for when the run step failed + @jsondata:Name {value: "failed_at"} + int? failedAt; + # The object type, which is always `thread.run.step` + "thread.run.step" 'object; + # The status of the run step, which can be either `in_progress`, `cancelled`, `failed`, `completed`, or `expired` + "in_progress"|"cancelled"|"failed"|"completed"|"expired" status; +}; + +# Specifies a tool the model should use. Use to force the model to call a specific function +public type ChatCompletionNamedToolChoice record { + ChatCompletionNamedToolChoiceFunction 'function; + # The type of the tool. Currently, only `function` is supported + "function" 'type; +}; + +public type CreateModerationResponseResults record { + @jsondata:Name {value: "category_scores"} + CreateModerationResponseCategoryScores categoryScores; + # Whether any of the below categories are flagged + boolean flagged; + CreateModerationResponseCategories categories; +}; + +public type MessageObjectContent MessageContentImageFileObject|MessageContentImageUrlObject|MessageContentTextObject; + +public type InlineResponse200 CreateTranscriptionResponseJson|CreateTranscriptionResponseVerboseJson; + +# The definition of the function that was called +public type RunStepDetailsToolCallsFunctionObjectFunction record { + # The output of the function. This will be `null` if the outputs have not been [submitted](/docs/api-reference/runs/submitToolOutputs) yet + string? output; + # The name of the function + string name; + # The arguments passed to the function + string arguments; +}; + +public type FunctionObject record { + # The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64 + string name; + # A description of what the function does, used by the model to choose when and how to call the function + string description?; + FunctionParameters parameters?; +}; + +# Represents the Queries record for the operation: listFineTuningJobCheckpoints +public type ListFineTuningJobCheckpointsQueries record { + # Number of checkpoints to retrieve + int 'limit = 10; + # Identifier for the last checkpoint ID from the previous pagination request + string after?; +}; + +# A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs +public type CreateAssistantRequestToolResources record { + @jsondata:Name {value: "code_interpreter"} + CreateAssistantRequestToolResourcesCodeInterpreter codeInterpreter?; + @jsondata:Name {value: "file_search"} + CreateAssistantRequestToolResourcesFileSearch fileSearch?; +}; + +# Represents the Queries record for the operation: listFiles +public type ListFilesQueries record { + # Only return files with the given purpose + string purpose?; +}; + +public type CreateAssistantRequest record {| + # An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + # + # We generally recommend altering this or temperature but not both + @jsondata:Name {value: "top_p"} + decimal? topP = 1; + # The system instructions that the assistant uses. The maximum length is 256,000 characters + string? instructions?; + @jsondata:Name {value: "tool_resources"} + CreateAssistantRequestToolResources? toolResources?; + # Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + record {}? metadata?; + @jsondata:Name {value: "response_format"} + AssistantsApiResponseFormatOption responseFormat?; + # The name of the assistant. The maximum length is 256 characters + string? name?; + # What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic + decimal? temperature = 1; + # The description of the assistant. The maximum length is 512 characters + string? description?; + # ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](/docs/models/overview) for descriptions of them + string|"gpt-4o"|"gpt-4o-2024-05-13"|"gpt-4o-mini"|"gpt-4o-mini-2024-07-18"|"gpt-4-turbo"|"gpt-4-turbo-2024-04-09"|"gpt-4-0125-preview"|"gpt-4-turbo-preview"|"gpt-4-1106-preview"|"gpt-4-vision-preview"|"gpt-4"|"gpt-4-0314"|"gpt-4-0613"|"gpt-4-32k"|"gpt-4-32k-0314"|"gpt-4-32k-0613"|"gpt-3.5-turbo"|"gpt-3.5-turbo-16k"|"gpt-3.5-turbo-0613"|"gpt-3.5-turbo-1106"|"gpt-3.5-turbo-0125"|"gpt-3.5-turbo-16k-0613" model; + # A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `file_search`, or `function` + @constraint:Array {maxLength: 128} + CreateAssistantRequestTools[] tools = []; +|}; + +public type DeleteVectorStoreResponse record { + boolean deleted; + string id; + "vector_store.deleted" 'object; +}; + +public type DeleteAssistantResponse record { + boolean deleted; + string id; + "assistant.deleted" 'object; +}; + +public type CreateAssistantRequestToolResourcesCodeInterpreter record { + # A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool + @jsondata:Name {value: "file_ids"} + string[] fileIds = []; +}; + +public type RunStepDetailsToolCallsFileSearchObject record { + # For now, this is always going to be an empty object + @jsondata:Name {value: "file_search"} + record {} fileSearch; + # The ID of the tool call object + string id; + # The type of tool call. This is always going to be `file_search` for this type of tool call + "file_search" 'type; +}; + +# The upload Part represents a chunk of bytes we can add to an Upload object +public type UploadPart record { + # The ID of the Upload object that this Part was added to + @jsondata:Name {value: "upload_id"} + string uploadId; + # The Unix timestamp (in seconds) for when the Part was created + @jsondata:Name {value: "created_at"} + int createdAt; + # The upload Part unique identifier, which can be referenced in API endpoints + string id; + # The object type, which is always `upload.part` + "upload.part" 'object; +}; + +# Represents a chat completion response returned by model, based on the provided input +public type CreateChatCompletionResponse record { + # The Unix timestamp (in seconds) of when the chat completion was created + int created; + CompletionUsage usage?; + # The model used for the chat completion + string model; + # The service tier used for processing the request. This field is only included if the `service_tier` parameter is specified in the request + @jsondata:Name {value: "service_tier"} + "scale"|"default"? serviceTier?; + # A unique identifier for the chat completion + string id; + # A list of chat completion choices. Can be more than one if `n` is greater than 1 + CreateChatCompletionResponseChoices[] choices; + # This fingerprint represents the backend configuration that the model runs with. + # + # Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism + @jsondata:Name {value: "system_fingerprint"} + string systemFingerprint?; + # The object type, which is always `chat.completion` + "chat.completion" 'object; +}; + +# Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model +# +# # Deprecated +@deprecated +public type ChatCompletionRequestAssistantMessageFunctionCall record { + # The name of the function to call + string name; + # The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function + string arguments; +}; + +public type ChatCompletionRequestToolMessage record { + # The role of the messages author, in this case `tool` + "tool" role; + # Tool call that this message is responding to + @jsondata:Name {value: "tool_call_id"} + string toolCallId; + # The contents of the tool message + string content; +}; + +public type CreateTranslationResponseJson record { + string text; +}; + +public type ChatCompletionRequestMessageContentPartImageImageUrl record { + # Specifies the detail level of the image. Learn more in the [Vision guide](/docs/guides/vision/low-or-high-fidelity-image-understanding) + "auto"|"low"|"high" detail = "auto"; + # Either a URL of the image or the base64 encoded image data + string url; +}; + +public type CreateImageVariationRequest record { + # The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square + record {byte[] fileContent; string fileName;} image; + # The format in which the generated images are returned. Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes after the image has been generated + @jsondata:Name {value: "response_format"} + "url"|"b64_json"? responseFormat = "url"; + # The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024` + "256x256"|"512x512"|"1024x1024"? size = "1024x1024"; + # The model to use for image generation. Only `dall-e-2` is supported at this time + string|"dall-e-2"? model = "dall-e-2"; + # A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids) + string user?; + # The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only `n=1` is supported + int? n = 1; +}; + +# A chat completion message generated by the model +public type ChatCompletionResponseMessage record { + # The role of the author of this message + "assistant" role; + @jsondata:Name {value: "function_call"} + ChatCompletionResponseMessageFunctionCall functionCall?; + @jsondata:Name {value: "tool_calls"} + ChatCompletionMessageToolCalls toolCalls?; + # The contents of the message + string? content; +}; + +public type DeleteThreadResponse record { + boolean deleted; + string id; + "thread.deleted" 'object; +}; + +public type MessageObjectTools AssistantToolsCode|AssistantToolsFileSearchTypeOnly; + +# Text output from the Code Interpreter tool call as part of a run step +public type RunStepDetailsToolCallsCodeOutputLogsObject record { + # Always `logs` + "logs" 'type; + # The text output from the Code Interpreter tool call + string logs; +}; + +public type StaticChunkingStrategyResponseParam record {| + StaticChunkingStrategy static; + # Always `static` + "static" 'type; +|}; + +# Details of the message creation by the run step +public type RunStepDetailsMessageCreationObject record { + @jsondata:Name {value: "message_creation"} + RunStepDetailsMessageCreationObjectMessageCreation messageCreation; + # Always `message_creation` + "message_creation" 'type; +}; + +# Represents the Queries record for the operation: listPaginatedFineTuningJobs +public type ListPaginatedFineTuningJobsQueries record { + # Number of fine-tuning jobs to retrieve + int 'limit = 20; + # Identifier for the last job from the previous pagination request + string after?; +}; + +public type MessageContentImageFileObjectImageFile record { + # The [File](/docs/api-reference/files) ID of the image in the message content. Set `purpose="vision"` when uploading the File if you need to later display the file content + @jsondata:Name {value: "file_id"} + string fileId; + # Specifies the detail level of the image if specified by the user. `low` uses fewer tokens, you can opt in to high resolution using `high` + "auto"|"low"|"high" detail = "auto"; +}; + +public type ThreadObjectToolResourcesCodeInterpreter record { + # A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool + @jsondata:Name {value: "file_ids"} + string[] fileIds = []; }; diff --git a/ballerina/utils.bal b/ballerina/utils.bal index 0ce7ca0..b764319 100644 --- a/ballerina/utils.bal +++ b/ballerina/utils.bal @@ -17,6 +17,7 @@ // specific language governing permissions and limitations // under the License. +import ballerina/http; import ballerina/mime; import ballerina/url; @@ -187,12 +188,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding; @@ -217,36 +219,86 @@ isolated function getPathForQueryParam(map queryParam, map en return restOfPath; } -isolated function createBodyParts(record {|anydata...;|} anyRecord, map encodingMap = {}) returns mime:Entity[]|error { +isolated function createBodyParts(record {|anydata...;|} anyRecord, map encodingMap = {}) +returns mime:Entity[]|error { mime:Entity[] entities = []; foreach [string, anydata] [key, value] in anyRecord.entries() { Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : {}; - mime:Entity entity = new mime:Entity(); + string contentDisposition = string `form-data; name=${key};`; if value is record {byte[] fileContent; string fileName;} { - entity.setContentDisposition(mime:getContentDispositionObject(string `form-data; name=${key}; filename=${value.fileName}`)); - entity.setByteArray(value.fileContent); + string fileContentDisposition = string `${contentDisposition} filename=${value.fileName}`; + mime:Entity entity = check constructEntity(fileContentDisposition, encodingData, + value.fileContent); + entities.push(entity); } else if value is byte[] { - entity.setContentDisposition(mime:getContentDispositionObject(string `form-data; name=${key};`)); - entity.setByteArray(value); - } else if value is SimpleBasicType|SimpleBasicType[] { - entity.setContentDisposition(mime:getContentDispositionObject(string `form-data; name=${key};`)); - entity.setText(value.toString()); - } else if value is record {}|record {}[] { - entity.setContentDisposition(mime:getContentDispositionObject(string `form-data; name=${key};`)); - entity.setJson(value.toJson()); - } - if encodingData?.contentType is string { - check entity.setContentType(encodingData?.contentType.toString()); - } - map? headers = encodingData?.headers; - if headers is map { - foreach var [headerName, headerValue] in headers.entries() { - if headerValue is SimpleBasicType { - entity.setHeader(headerName, headerValue.toString()); + mime:Entity entity = check constructEntity(contentDisposition, encodingData, value); + entities.push(entity); + } else if value is SimpleBasicType { + mime:Entity entity = check constructEntity(contentDisposition, encodingData, + value.toString()); + entities.push(entity); + } else if value is SimpleBasicType[] { + if encodingData.explode { + foreach SimpleBasicType member in value { + mime:Entity entity = check constructEntity(contentDisposition, encodingData, + member.toString()); + entities.push(entity); + } + } else { + string[] valueStrArray = from SimpleBasicType val in value + select val.toString(); + mime:Entity entity = check constructEntity(contentDisposition, encodingData, + string:'join(",", ...valueStrArray)); + entities.push(entity); + } + } else if value is record {} { + mime:Entity entity = check constructEntity(contentDisposition, encodingData, + value.toString()); + entities.push(entity); + } else if value is record {}[] { + if encodingData.explode { + foreach record {} member in value { + mime:Entity entity = check constructEntity(contentDisposition, encodingData, + member.toString()); + entities.push(entity); } + } else { + string[] valueStrArray = from record {} val in value + select val.toJsonString(); + mime:Entity entity = check constructEntity(contentDisposition, encodingData, + string:'join(",", ...valueStrArray)); + entities.push(entity); } } - entities.push(entity); } return entities; } + +isolated function constructEntity(string contentDisposition, Encoding encoding, + string|byte[]|record {} data) returns mime:Entity|error { + mime:Entity entity = new mime:Entity(); + entity.setContentDisposition(mime:getContentDispositionObject(contentDisposition)); + if data is byte[] { + entity.setByteArray(data); + } else if data is string { + entity.setText(data); + } else { + entity.setJson(data.toJson()); + } + check populateEncodingInfo(entity, encoding); + return entity; +} + +isolated function populateEncodingInfo(mime:Entity entity, Encoding encoding) returns error? { + if encoding?.contentType is string { + check entity.setContentType(encoding?.contentType.toString()); + } + map? headers = encoding?.headers; + if headers is map { + foreach var [headerName, headerValue] in headers.entries() { + if headerValue is SimpleBasicType { + entity.setHeader(headerName, headerValue.toString()); + } + } + } +} diff --git a/docs/spec/openapi.yaml b/docs/spec/openapi.yaml index 7380865..36ea026 100644 --- a/docs/spec/openapi.yaml +++ b/docs/spec/openapi.yaml @@ -1,14276 +1,16020 @@ openapi: 3.0.0 info: - title: OpenAI API - description: The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details. - version: "2.1.0" - termsOfService: https://openai.com/policies/terms-of-use - contact: - name: OpenAI Support - url: https://help.openai.com/ - license: - name: MIT - url: https://github.com/openai/openai-openapi/blob/master/LICENSE + title: OpenAI API + description: The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference + for more details. + termsOfService: https://openai.com/policies/terms-of-use + contact: + name: OpenAI Support + url: https://help.openai.com/ + license: + name: MIT + url: https://github.com/openai/openai-openapi/blob/master/LICENSE + version: 2.1.0 servers: - - url: https://api.openai.com/v1 +- url: https://api.openai.com/v1 +security: +- ApiKeyAuth: [] tags: - - name: Assistants - description: Build Assistants that can call models and use tools. - - name: Audio - description: Turn audio into text or text into audio. - - name: Chat - description: Given a list of messages comprising a conversation, the model will return a response. - - name: Completions - description: Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position. - - name: Embeddings - description: Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms. - - name: Fine-tuning - description: Manage fine-tuning jobs to tailor a model to your specific training data. - - name: Batch - description: Create large batches of API requests to run asynchronously. - - name: Files - description: Files are used to upload documents that can be used with features like Assistants and Fine-tuning. - - name: Uploads - description: Use Uploads to upload large files in multiple parts. - - name: Images - description: Given a prompt and/or an input image, the model will generate a new image. - - name: Models - description: List and describe the various models available in the API. - - name: Moderations - description: Given a input text, outputs if the model classifies it as potentially harmful. +- name: Assistants + description: Build Assistants that can call models and use tools. +- name: Audio + description: Turn audio into text or text into audio. +- name: Chat + description: "Given a list of messages comprising a conversation, the model will\ + \ return a response." +- name: Completions + description: "Given a prompt, the model will return one or more predicted completions,\ + \ and can also return the probabilities of alternative tokens at each position." +- name: Embeddings + description: Get a vector representation of a given input that can be easily consumed + by machine learning models and algorithms. +- name: Fine-tuning + description: Manage fine-tuning jobs to tailor a model to your specific training + data. +- name: Batch + description: Create large batches of API requests to run asynchronously. +- name: Files + description: Files are used to upload documents that can be used with features like + Assistants and Fine-tuning. +- name: Uploads + description: Use Uploads to upload large files in multiple parts. +- name: Images + description: "Given a prompt and/or an input image, the model will generate a new\ + \ image." +- name: Models + description: List and describe the various models available in the API. +- name: Moderations + description: "Given a input text, outputs if the model classifies it as potentially\ + \ harmful." paths: - # Note: When adding an endpoint, make sure you also add it in the `groups` section, in the end of this file, - # under the appropriate group - /chat/completions: - post: - operationId: createChatCompletion - tags: - - Chat - summary: Creates a model response for the given chat conversation. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateChatCompletionRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/CreateChatCompletionResponse" - - x-oaiMeta: - name: Create chat completion - group: chat - returns: | - Returns a [chat completion](/docs/api-reference/chat/object) object, or a streamed sequence of [chat completion chunk](/docs/api-reference/chat/streaming) objects if the request is streamed. - path: create - examples: - - title: Default - request: - curl: | - curl https://api.openai.com/v1/chat/completions \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "model": "VAR_model_id", - "messages": [ - { - "role": "system", - "content": "You are a helpful assistant." - }, - { - "role": "user", - "content": "Hello!" - } - ] - }' - python: | - from openai import OpenAI - client = OpenAI() - - completion = client.chat.completions.create( - model="VAR_model_id", - messages=[ - {"role": "system", "content": "You are a helpful assistant."}, - {"role": "user", "content": "Hello!"} - ] - ) - - print(completion.choices[0].message) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const completion = await openai.chat.completions.create({ - messages: [{ role: "system", content: "You are a helpful assistant." }], - model: "VAR_model_id", - }); - - console.log(completion.choices[0]); - } - - main(); - response: &chat_completion_example | - { - "id": "chatcmpl-123", - "object": "chat.completion", - "created": 1677652288, - "model": "gpt-4o-mini", - "system_fingerprint": "fp_44709d6fcb", - "choices": [{ - "index": 0, - "message": { - "role": "assistant", - "content": "\n\nHello there, how may I assist you today?", + /chat/completions: + post: + tags: + - Chat + summary: Creates a model response for the given chat conversation. + operationId: createChatCompletion + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateChatCompletionRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/CreateChatCompletionResponse' + x-oaiMeta: + name: Create chat completion + group: chat + returns: | + Returns a [chat completion](/docs/api-reference/chat/object) object, or a streamed sequence of [chat completion chunk](/docs/api-reference/chat/streaming) objects if the request is streamed. + path: create + examples: + - title: Default + request: + curl: | + curl https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "VAR_model_id", + "messages": [ + { + "role": "system", + "content": "You are a helpful assistant." + }, + { + "role": "user", + "content": "Hello!" + } + ] + }' + python: | + from openai import OpenAI + client = OpenAI() + + completion = client.chat.completions.create( + model="VAR_model_id", + messages=[ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": "Hello!"} + ] + ) + + print(completion.choices[0].message) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const completion = await openai.chat.completions.create({ + messages: [{ role: "system", content: "You are a helpful assistant." }], + model: "VAR_model_id", + }); + + console.log(completion.choices[0]); + } + + main(); + response: | + { + "id": "chatcmpl-123", + "object": "chat.completion", + "created": 1677652288, + "model": "gpt-4o-mini", + "system_fingerprint": "fp_44709d6fcb", + "choices": [{ + "index": 0, + "message": { + "role": "assistant", + "content": "\n\nHello there, how may I assist you today?", + }, + "logprobs": null, + "finish_reason": "stop" + }], + "usage": { + "prompt_tokens": 9, + "completion_tokens": 12, + "total_tokens": 21 + } + } + - title: Image input + request: + curl: | + curl https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "gpt-4-turbo", + "messages": [ + { + "role": "user", + "content": [ + { + "type": "text", + "text": "What'\''s in this image?" + }, + { + "type": "image_url", + "image_url": { + "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg" + } + } + ] + } + ], + "max_tokens": 300 + }' + python: | + from openai import OpenAI + + client = OpenAI() + + response = client.chat.completions.create( + model="gpt-4-turbo", + messages=[ + { + "role": "user", + "content": [ + {"type": "text", "text": "What's in this image?"}, + { + "type": "image_url", + "image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", }, - "logprobs": null, - "finish_reason": "stop" - }], - "usage": { - "prompt_tokens": 9, - "completion_tokens": 12, - "total_tokens": 21 - } + ], + } + ], + max_tokens=300, + ) + + print(response.choices[0]) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const response = await openai.chat.completions.create({ + model: "gpt-4-turbo", + messages: [ + { + role: "user", + content: [ + { type: "text", text: "What's in this image?" }, + { + type: "image_url", + image_url: + "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", + }, + ], + }, + ], + }); + console.log(response.choices[0]); + } + main(); + response: | + { + "id": "chatcmpl-123", + "object": "chat.completion", + "created": 1677652288, + "model": "gpt-4o-mini", + "system_fingerprint": "fp_44709d6fcb", + "choices": [{ + "index": 0, + "message": { + "role": "assistant", + "content": "\n\nThis image shows a wooden boardwalk extending through a lush green marshland.", + }, + "logprobs": null, + "finish_reason": "stop" + }], + "usage": { + "prompt_tokens": 9, + "completion_tokens": 12, + "total_tokens": 21 + } + } + - title: Streaming + request: + curl: | + curl https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "VAR_model_id", + "messages": [ + { + "role": "system", + "content": "You are a helpful assistant." + }, + { + "role": "user", + "content": "Hello!" + } + ], + "stream": true + }' + python: | + from openai import OpenAI + client = OpenAI() + + completion = client.chat.completions.create( + model="VAR_model_id", + messages=[ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": "Hello!"} + ], + stream=True + ) + + for chunk in completion: + print(chunk.choices[0].delta) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const completion = await openai.chat.completions.create({ + model: "VAR_model_id", + messages: [ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": "Hello!"} + ], + stream: true, + }); + + for await (const chunk of completion) { + console.log(chunk.choices[0].delta.content); + } + } + + main(); + response: | + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-4o-mini", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]} + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-4o-mini", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"Hello"},"logprobs":null,"finish_reason":null}]} + + .... + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-4o-mini", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}]} + - title: Functions + request: + curl: | + curl https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "gpt-4-turbo", + "messages": [ + { + "role": "user", + "content": "What'\''s the weather like in Boston today?" + } + ], + "tools": [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA" + }, + "unit": { + "type": "string", + "enum": ["celsius", "fahrenheit"] } - - title: Image input - request: - curl: | - curl https://api.openai.com/v1/chat/completions \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "model": "gpt-4-turbo", - "messages": [ - { - "role": "user", - "content": [ - { - "type": "text", - "text": "What'\''s in this image?" - }, - { - "type": "image_url", - "image_url": { - "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg" - } - } - ] - } - ], - "max_tokens": 300 - }' - python: | - from openai import OpenAI - - client = OpenAI() - - response = client.chat.completions.create( - model="gpt-4-turbo", - messages=[ - { - "role": "user", - "content": [ - {"type": "text", "text": "What's in this image?"}, - { - "type": "image_url", - "image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", - }, - ], - } - ], - max_tokens=300, - ) - - print(response.choices[0]) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const response = await openai.chat.completions.create({ - model: "gpt-4-turbo", - messages: [ - { - role: "user", - content: [ - { type: "text", text: "What's in this image?" }, - { - type: "image_url", - image_url: - "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", - }, - ], - }, - ], - }); - console.log(response.choices[0]); - } - main(); - response: &chat_completion_image_example | + }, + "required": ["location"] + } + } + } + ], + "tool_choice": "auto" + }' + python: | + from openai import OpenAI + client = OpenAI() + + tools = [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA", + }, + "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, + }, + "required": ["location"], + }, + } + } + ] + messages = [{"role": "user", "content": "What's the weather like in Boston today?"}] + completion = client.chat.completions.create( + model="VAR_model_id", + messages=messages, + tools=tools, + tool_choice="auto" + ) + + print(completion) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const messages = [{"role": "user", "content": "What's the weather like in Boston today?"}]; + const tools = [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA", + }, + "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, + }, + "required": ["location"], + }, + } + } + ]; + + const response = await openai.chat.completions.create({ + model: "gpt-4-turbo", + messages: messages, + tools: tools, + tool_choice: "auto", + }); + + console.log(response); + } + + main(); + response: | + { + "id": "chatcmpl-abc123", + "object": "chat.completion", + "created": 1699896916, + "model": "gpt-4o-mini", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": null, + "tool_calls": [ + { + "id": "call_abc123", + "type": "function", + "function": { + "name": "get_current_weather", + "arguments": "{\n\"location\": \"Boston, MA\"\n}" + } + } + ] + }, + "logprobs": null, + "finish_reason": "tool_calls" + } + ], + "usage": { + "prompt_tokens": 82, + "completion_tokens": 17, + "total_tokens": 99 + } + } + - title: Logprobs + request: + curl: | + curl https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "VAR_model_id", + "messages": [ + { + "role": "user", + "content": "Hello!" + } + ], + "logprobs": true, + "top_logprobs": 2 + }' + python: | + from openai import OpenAI + client = OpenAI() + + completion = client.chat.completions.create( + model="VAR_model_id", + messages=[ + {"role": "user", "content": "Hello!"} + ], + logprobs=True, + top_logprobs=2 + ) + + print(completion.choices[0].message) + print(completion.choices[0].logprobs) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const completion = await openai.chat.completions.create({ + messages: [{ role: "user", content: "Hello!" }], + model: "VAR_model_id", + logprobs: true, + top_logprobs: 2, + }); + + console.log(completion.choices[0]); + } + + main(); + response: | + { + "id": "chatcmpl-123", + "object": "chat.completion", + "created": 1702685778, + "model": "gpt-4o-mini", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "Hello! How can I assist you today?" + }, + "logprobs": { + "content": [ + { + "token": "Hello", + "logprob": -0.31725305, + "bytes": [72, 101, 108, 108, 111], + "top_logprobs": [ { - "id": "chatcmpl-123", - "object": "chat.completion", - "created": 1677652288, - "model": "gpt-4o-mini", - "system_fingerprint": "fp_44709d6fcb", - "choices": [{ - "index": 0, - "message": { - "role": "assistant", - "content": "\n\nThis image shows a wooden boardwalk extending through a lush green marshland.", - }, - "logprobs": null, - "finish_reason": "stop" - }], - "usage": { - "prompt_tokens": 9, - "completion_tokens": 12, - "total_tokens": 21 - } + "token": "Hello", + "logprob": -0.31725305, + "bytes": [72, 101, 108, 108, 111] + }, + { + "token": "Hi", + "logprob": -1.3190403, + "bytes": [72, 105] } - - title: Streaming - request: - curl: | - curl https://api.openai.com/v1/chat/completions \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "model": "VAR_model_id", - "messages": [ - { - "role": "system", - "content": "You are a helpful assistant." - }, - { - "role": "user", - "content": "Hello!" - } - ], - "stream": true - }' - python: | - from openai import OpenAI - client = OpenAI() - - completion = client.chat.completions.create( - model="VAR_model_id", - messages=[ - {"role": "system", "content": "You are a helpful assistant."}, - {"role": "user", "content": "Hello!"} - ], - stream=True - ) - - for chunk in completion: - print(chunk.choices[0].delta) - - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const completion = await openai.chat.completions.create({ - model: "VAR_model_id", - messages: [ - {"role": "system", "content": "You are a helpful assistant."}, - {"role": "user", "content": "Hello!"} - ], - stream: true, - }); - - for await (const chunk of completion) { - console.log(chunk.choices[0].delta.content); - } - } - - main(); - response: &chat_completion_chunk_example | - {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-4o-mini", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]} - - {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-4o-mini", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"Hello"},"logprobs":null,"finish_reason":null}]} - - .... - - {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-4o-mini", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}]} - - title: Functions - request: - curl: | - curl https://api.openai.com/v1/chat/completions \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "model": "gpt-4-turbo", - "messages": [ - { - "role": "user", - "content": "What'\''s the weather like in Boston today?" - } - ], - "tools": [ - { - "type": "function", - "function": { - "name": "get_current_weather", - "description": "Get the current weather in a given location", - "parameters": { - "type": "object", - "properties": { - "location": { - "type": "string", - "description": "The city and state, e.g. San Francisco, CA" - }, - "unit": { - "type": "string", - "enum": ["celsius", "fahrenheit"] - } - }, - "required": ["location"] - } - } - } - ], - "tool_choice": "auto" - }' - python: | - from openai import OpenAI - client = OpenAI() - - tools = [ - { - "type": "function", - "function": { - "name": "get_current_weather", - "description": "Get the current weather in a given location", - "parameters": { - "type": "object", - "properties": { - "location": { - "type": "string", - "description": "The city and state, e.g. San Francisco, CA", - }, - "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, - }, - "required": ["location"], - }, - } - } - ] - messages = [{"role": "user", "content": "What's the weather like in Boston today?"}] - completion = client.chat.completions.create( - model="VAR_model_id", - messages=messages, - tools=tools, - tool_choice="auto" - ) - - print(completion) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const messages = [{"role": "user", "content": "What's the weather like in Boston today?"}]; - const tools = [ - { - "type": "function", - "function": { - "name": "get_current_weather", - "description": "Get the current weather in a given location", - "parameters": { - "type": "object", - "properties": { - "location": { - "type": "string", - "description": "The city and state, e.g. San Francisco, CA", - }, - "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, - }, - "required": ["location"], - }, - } - } - ]; - - const response = await openai.chat.completions.create({ - model: "gpt-4-turbo", - messages: messages, - tools: tools, - tool_choice: "auto", - }); - - console.log(response); - } - - main(); - response: &chat_completion_function_example | + ] + }, + { + "token": "!", + "logprob": -0.02380986, + "bytes": [ + 33 + ], + "top_logprobs": [ { - "id": "chatcmpl-abc123", - "object": "chat.completion", - "created": 1699896916, - "model": "gpt-4o-mini", - "choices": [ - { - "index": 0, - "message": { - "role": "assistant", - "content": null, - "tool_calls": [ - { - "id": "call_abc123", - "type": "function", - "function": { - "name": "get_current_weather", - "arguments": "{\n\"location\": \"Boston, MA\"\n}" - } - } - ] - }, - "logprobs": null, - "finish_reason": "tool_calls" - } - ], - "usage": { - "prompt_tokens": 82, - "completion_tokens": 17, - "total_tokens": 99 - } + "token": "!", + "logprob": -0.02380986, + "bytes": [33] + }, + { + "token": " there", + "logprob": -3.787621, + "bytes": [32, 116, 104, 101, 114, 101] } - - title: Logprobs - request: - curl: | - curl https://api.openai.com/v1/chat/completions \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "model": "VAR_model_id", - "messages": [ - { - "role": "user", - "content": "Hello!" - } - ], - "logprobs": true, - "top_logprobs": 2 - }' - python: | - from openai import OpenAI - client = OpenAI() - - completion = client.chat.completions.create( - model="VAR_model_id", - messages=[ - {"role": "user", "content": "Hello!"} - ], - logprobs=True, - top_logprobs=2 - ) - - print(completion.choices[0].message) - print(completion.choices[0].logprobs) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const completion = await openai.chat.completions.create({ - messages: [{ role: "user", content: "Hello!" }], - model: "VAR_model_id", - logprobs: true, - top_logprobs: 2, - }); - - console.log(completion.choices[0]); - } - - main(); - response: | + ] + }, + { + "token": " How", + "logprob": -0.000054669687, + "bytes": [32, 72, 111, 119], + "top_logprobs": [ { - "id": "chatcmpl-123", - "object": "chat.completion", - "created": 1702685778, - "model": "gpt-4o-mini", - "choices": [ - { - "index": 0, - "message": { - "role": "assistant", - "content": "Hello! How can I assist you today?" - }, - "logprobs": { - "content": [ - { - "token": "Hello", - "logprob": -0.31725305, - "bytes": [72, 101, 108, 108, 111], - "top_logprobs": [ - { - "token": "Hello", - "logprob": -0.31725305, - "bytes": [72, 101, 108, 108, 111] - }, - { - "token": "Hi", - "logprob": -1.3190403, - "bytes": [72, 105] - } - ] - }, - { - "token": "!", - "logprob": -0.02380986, - "bytes": [ - 33 - ], - "top_logprobs": [ - { - "token": "!", - "logprob": -0.02380986, - "bytes": [33] - }, - { - "token": " there", - "logprob": -3.787621, - "bytes": [32, 116, 104, 101, 114, 101] - } - ] - }, - { - "token": " How", - "logprob": -0.000054669687, - "bytes": [32, 72, 111, 119], - "top_logprobs": [ - { - "token": " How", - "logprob": -0.000054669687, - "bytes": [32, 72, 111, 119] - }, - { - "token": "<|end|>", - "logprob": -10.953937, - "bytes": null - } - ] - }, - { - "token": " can", - "logprob": -0.015801601, - "bytes": [32, 99, 97, 110], - "top_logprobs": [ - { - "token": " can", - "logprob": -0.015801601, - "bytes": [32, 99, 97, 110] - }, - { - "token": " may", - "logprob": -4.161023, - "bytes": [32, 109, 97, 121] - } - ] - }, - { - "token": " I", - "logprob": -3.7697225e-6, - "bytes": [ - 32, - 73 - ], - "top_logprobs": [ - { - "token": " I", - "logprob": -3.7697225e-6, - "bytes": [32, 73] - }, - { - "token": " assist", - "logprob": -13.596657, - "bytes": [32, 97, 115, 115, 105, 115, 116] - } - ] - }, - { - "token": " assist", - "logprob": -0.04571125, - "bytes": [32, 97, 115, 115, 105, 115, 116], - "top_logprobs": [ - { - "token": " assist", - "logprob": -0.04571125, - "bytes": [32, 97, 115, 115, 105, 115, 116] - }, - { - "token": " help", - "logprob": -3.1089056, - "bytes": [32, 104, 101, 108, 112] - } - ] - }, - { - "token": " you", - "logprob": -5.4385737e-6, - "bytes": [32, 121, 111, 117], - "top_logprobs": [ - { - "token": " you", - "logprob": -5.4385737e-6, - "bytes": [32, 121, 111, 117] - }, - { - "token": " today", - "logprob": -12.807695, - "bytes": [32, 116, 111, 100, 97, 121] - } - ] - }, - { - "token": " today", - "logprob": -0.0040071653, - "bytes": [32, 116, 111, 100, 97, 121], - "top_logprobs": [ - { - "token": " today", - "logprob": -0.0040071653, - "bytes": [32, 116, 111, 100, 97, 121] - }, - { - "token": "?", - "logprob": -5.5247097, - "bytes": [63] - } - ] - }, - { - "token": "?", - "logprob": -0.0008108172, - "bytes": [63], - "top_logprobs": [ - { - "token": "?", - "logprob": -0.0008108172, - "bytes": [63] - }, - { - "token": "?\n", - "logprob": -7.184561, - "bytes": [63, 10] - } - ] - } - ] - }, - "finish_reason": "stop" - } - ], - "usage": { - "prompt_tokens": 9, - "completion_tokens": 9, - "total_tokens": 18 - }, - "system_fingerprint": null + "token": " How", + "logprob": -0.000054669687, + "bytes": [32, 72, 111, 119] + }, + { + "token": "<|end|>", + "logprob": -10.953937, + "bytes": null } - - /completions: - post: - operationId: createCompletion - tags: - - Completions - summary: Creates a completion for the provided prompt and parameters. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateCompletionRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/CreateCompletionResponse" - x-oaiMeta: - name: Create completion - group: completions - returns: | - Returns a [completion](/docs/api-reference/completions/object) object, or a sequence of completion objects if the request is streamed. - legacy: true - examples: - - title: No streaming - request: - curl: | - curl https://api.openai.com/v1/completions \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "model": "VAR_model_id", - "prompt": "Say this is a test", - "max_tokens": 7, - "temperature": 0 - }' - python: | - from openai import OpenAI - client = OpenAI() - - client.completions.create( - model="VAR_model_id", - prompt="Say this is a test", - max_tokens=7, - temperature=0 - ) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const completion = await openai.completions.create({ - model: "VAR_model_id", - prompt: "Say this is a test.", - max_tokens: 7, - temperature: 0, - }); - - console.log(completion); - } - main(); - response: | + ] + }, + { + "token": " can", + "logprob": -0.015801601, + "bytes": [32, 99, 97, 110], + "top_logprobs": [ { - "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7", - "object": "text_completion", - "created": 1589478378, - "model": "VAR_model_id", - "system_fingerprint": "fp_44709d6fcb", - "choices": [ - { - "text": "\n\nThis is indeed a test", - "index": 0, - "logprobs": null, - "finish_reason": "length" - } - ], - "usage": { - "prompt_tokens": 5, - "completion_tokens": 7, - "total_tokens": 12 - } + "token": " can", + "logprob": -0.015801601, + "bytes": [32, 99, 97, 110] + }, + { + "token": " may", + "logprob": -4.161023, + "bytes": [32, 109, 97, 121] } - - title: Streaming - request: - curl: | - curl https://api.openai.com/v1/completions \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "model": "VAR_model_id", - "prompt": "Say this is a test", - "max_tokens": 7, - "temperature": 0, - "stream": true - }' - python: | - from openai import OpenAI - client = OpenAI() - - for chunk in client.completions.create( - model="VAR_model_id", - prompt="Say this is a test", - max_tokens=7, - temperature=0, - stream=True - ): - print(chunk.choices[0].text) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const stream = await openai.completions.create({ - model: "VAR_model_id", - prompt: "Say this is a test.", - stream: true, - }); - - for await (const chunk of stream) { - console.log(chunk.choices[0].text) - } - } - main(); - response: | + ] + }, + { + "token": " I", + "logprob": -3.7697225e-6, + "bytes": [ + 32, + 73 + ], + "top_logprobs": [ { - "id": "cmpl-7iA7iJjj8V2zOkCGvWF2hAkDWBQZe", - "object": "text_completion", - "created": 1690759702, - "choices": [ - { - "text": "This", - "index": 0, - "logprobs": null, - "finish_reason": null - } - ], - "model": "gpt-3.5-turbo-instruct" - "system_fingerprint": "fp_44709d6fcb", + "token": " I", + "logprob": -3.7697225e-6, + "bytes": [32, 73] + }, + { + "token": " assist", + "logprob": -13.596657, + "bytes": [32, 97, 115, 115, 105, 115, 116] } - - /images/generations: - post: - operationId: createImage - tags: - - Images - summary: Creates an image given a prompt. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateImageRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ImagesResponse" - x-oaiMeta: - name: Create image - group: images - returns: Returns a list of [image](/docs/api-reference/images/object) objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/images/generations \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "model": "dall-e-3", - "prompt": "A cute baby sea otter", - "n": 1, - "size": "1024x1024" - }' - python: | - from openai import OpenAI - client = OpenAI() - - client.images.generate( - model="dall-e-3", - prompt="A cute baby sea otter", - n=1, - size="1024x1024" - ) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const image = await openai.images.generate({ model: "dall-e-3", prompt: "A cute baby sea otter" }); - - console.log(image.data); - } - main(); - response: | - { - "created": 1589478378, - "data": [ - { - "url": "https://..." - }, - { - "url": "https://..." - } - ] - } - /images/edits: - post: - operationId: createImageEdit - tags: - - Images - summary: Creates an edited or extended image given an original image and a prompt. - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: "#/components/schemas/CreateImageEditRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ImagesResponse" - x-oaiMeta: - name: Create image edit - group: images - returns: Returns a list of [image](/docs/api-reference/images/object) objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/images/edits \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -F image="@otter.png" \ - -F mask="@mask.png" \ - -F prompt="A cute baby sea otter wearing a beret" \ - -F n=2 \ - -F size="1024x1024" - python: | - from openai import OpenAI - client = OpenAI() - - client.images.edit( - image=open("otter.png", "rb"), - mask=open("mask.png", "rb"), - prompt="A cute baby sea otter wearing a beret", - n=2, - size="1024x1024" - ) - node.js: |- - import fs from "fs"; - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const image = await openai.images.edit({ - image: fs.createReadStream("otter.png"), - mask: fs.createReadStream("mask.png"), - prompt: "A cute baby sea otter wearing a beret", - }); - - console.log(image.data); - } - main(); - response: | - { - "created": 1589478378, - "data": [ - { - "url": "https://..." - }, - { - "url": "https://..." - } - ] - } - /images/variations: - post: - operationId: createImageVariation - tags: - - Images - summary: Creates a variation of a given image. - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: "#/components/schemas/CreateImageVariationRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ImagesResponse" - x-oaiMeta: - name: Create image variation - group: images - returns: Returns a list of [image](/docs/api-reference/images/object) objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/images/variations \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -F image="@otter.png" \ - -F n=2 \ - -F size="1024x1024" - python: | - from openai import OpenAI - client = OpenAI() - - response = client.images.create_variation( - image=open("image_edit_original.png", "rb"), - n=2, - size="1024x1024" - ) - node.js: |- - import fs from "fs"; - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const image = await openai.images.createVariation({ - image: fs.createReadStream("otter.png"), - }); - - console.log(image.data); - } - main(); - response: | - { - "created": 1589478378, - "data": [ - { - "url": "https://..." - }, - { - "url": "https://..." - } - ] - } - - /embeddings: - post: - operationId: createEmbedding - tags: - - Embeddings - summary: Creates an embedding vector representing the input text. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateEmbeddingRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/CreateEmbeddingResponse" - x-oaiMeta: - name: Create embeddings - group: embeddings - returns: A list of [embedding](/docs/api-reference/embeddings/object) objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/embeddings \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -d '{ - "input": "The food was delicious and the waiter...", - "model": "text-embedding-ada-002", - "encoding_format": "float" - }' - python: | - from openai import OpenAI - client = OpenAI() - - client.embeddings.create( - model="text-embedding-ada-002", - input="The food was delicious and the waiter...", - encoding_format="float" - ) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const embedding = await openai.embeddings.create({ - model: "text-embedding-ada-002", - input: "The quick brown fox jumped over the lazy dog", - encoding_format: "float", - }); - - console.log(embedding); - } - - main(); - response: | - { - "object": "list", - "data": [ - { - "object": "embedding", - "embedding": [ - 0.0023064255, - -0.009327292, - .... (1536 floats total for ada-002) - -0.0028842222, - ], - "index": 0 - } - ], - "model": "text-embedding-ada-002", - "usage": { - "prompt_tokens": 8, - "total_tokens": 8 + ] + }, + { + "token": " assist", + "logprob": -0.04571125, + "bytes": [32, 97, 115, 115, 105, 115, 116], + "top_logprobs": [ + { + "token": " assist", + "logprob": -0.04571125, + "bytes": [32, 97, 115, 115, 105, 115, 116] + }, + { + "token": " help", + "logprob": -3.1089056, + "bytes": [32, 104, 101, 108, 112] } - } - - /audio/speech: - post: - operationId: createSpeech - tags: - - Audio - summary: Generates audio from the input text. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateSpeechRequest" - responses: - "200": - description: OK - headers: - Transfer-Encoding: - schema: - type: string - description: chunked - content: - application/octet-stream: - schema: - type: string - format: binary - x-oaiMeta: - name: Create speech - group: audio - returns: The audio file content. - examples: - request: - curl: | - curl https://api.openai.com/v1/audio/speech \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -d '{ - "model": "tts-1", - "input": "The quick brown fox jumped over the lazy dog.", - "voice": "alloy" - }' \ - --output speech.mp3 - python: | - from pathlib import Path - import openai - - speech_file_path = Path(__file__).parent / "speech.mp3" - response = openai.audio.speech.create( - model="tts-1", - voice="alloy", - input="The quick brown fox jumped over the lazy dog." - ) - response.stream_to_file(speech_file_path) - node: | - import fs from "fs"; - import path from "path"; - import OpenAI from "openai"; - - const openai = new OpenAI(); - - const speechFile = path.resolve("./speech.mp3"); - - async function main() { - const mp3 = await openai.audio.speech.create({ - model: "tts-1", - voice: "alloy", - input: "Today is a wonderful day to build something people love!", - }); - console.log(speechFile); - const buffer = Buffer.from(await mp3.arrayBuffer()); - await fs.promises.writeFile(speechFile, buffer); - } - main(); - /audio/transcriptions: - post: - operationId: createTranscription - tags: - - Audio - summary: Transcribes audio into the input language. - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: "#/components/schemas/CreateTranscriptionRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - oneOf: - - $ref: "#/components/schemas/CreateTranscriptionResponseJson" - - $ref: "#/components/schemas/CreateTranscriptionResponseVerboseJson" - x-oaiMeta: - name: Create transcription - group: audio - returns: The [transcription object](/docs/api-reference/audio/json-object) or a [verbose transcription object](/docs/api-reference/audio/verbose-json-object). - examples: - - title: Default - request: - curl: | - curl https://api.openai.com/v1/audio/transcriptions \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: multipart/form-data" \ - -F file="@/path/to/file/audio.mp3" \ - -F model="whisper-1" - python: | - from openai import OpenAI - client = OpenAI() - - audio_file = open("speech.mp3", "rb") - transcript = client.audio.transcriptions.create( - model="whisper-1", - file=audio_file - ) - node: | - import fs from "fs"; - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const transcription = await openai.audio.transcriptions.create({ - file: fs.createReadStream("audio.mp3"), - model: "whisper-1", - }); - - console.log(transcription.text); - } - main(); - response: &basic_transcription_response_example | + ] + }, + { + "token": " you", + "logprob": -5.4385737e-6, + "bytes": [32, 121, 111, 117], + "top_logprobs": [ + { + "token": " you", + "logprob": -5.4385737e-6, + "bytes": [32, 121, 111, 117] + }, { - "text": "Imagine the wildest idea that you've ever had, and you're curious about how it might scale to something that's a 100, a 1,000 times bigger. This is a place where you can get to do that." + "token": " today", + "logprob": -12.807695, + "bytes": [32, 116, 111, 100, 97, 121] } - - title: Word timestamps - request: - curl: | - curl https://api.openai.com/v1/audio/transcriptions \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: multipart/form-data" \ - -F file="@/path/to/file/audio.mp3" \ - -F "timestamp_granularities[]=word" \ - -F model="whisper-1" \ - -F response_format="verbose_json" - python: | - from openai import OpenAI - client = OpenAI() - - audio_file = open("speech.mp3", "rb") - transcript = client.audio.transcriptions.create( - file=audio_file, - model="whisper-1", - response_format="verbose_json", - timestamp_granularities=["word"] - ) - - print(transcript.words) - node: | - import fs from "fs"; - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const transcription = await openai.audio.transcriptions.create({ - file: fs.createReadStream("audio.mp3"), - model: "whisper-1", - response_format: "verbose_json", - timestamp_granularities: ["word"] - }); - - console.log(transcription.text); - } - main(); - response: | + ] + }, + { + "token": " today", + "logprob": -0.0040071653, + "bytes": [32, 116, 111, 100, 97, 121], + "top_logprobs": [ { - "task": "transcribe", - "language": "english", - "duration": 8.470000267028809, - "text": "The beach was a popular spot on a hot summer day. People were swimming in the ocean, building sandcastles, and playing beach volleyball.", - "words": [ - { - "word": "The", - "start": 0.0, - "end": 0.23999999463558197 - }, - ... - { - "word": "volleyball", - "start": 7.400000095367432, - "end": 7.900000095367432 - } - ] + "token": " today", + "logprob": -0.0040071653, + "bytes": [32, 116, 111, 100, 97, 121] + }, + { + "token": "?", + "logprob": -5.5247097, + "bytes": [63] } - - title: Segment timestamps - request: - curl: | - curl https://api.openai.com/v1/audio/transcriptions \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: multipart/form-data" \ - -F file="@/path/to/file/audio.mp3" \ - -F "timestamp_granularities[]=segment" \ - -F model="whisper-1" \ - -F response_format="verbose_json" - python: | - from openai import OpenAI - client = OpenAI() - - audio_file = open("speech.mp3", "rb") - transcript = client.audio.transcriptions.create( - file=audio_file, - model="whisper-1", - response_format="verbose_json", - timestamp_granularities=["segment"] - ) - - print(transcript.words) - node: | - import fs from "fs"; - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const transcription = await openai.audio.transcriptions.create({ - file: fs.createReadStream("audio.mp3"), - model: "whisper-1", - response_format: "verbose_json", - timestamp_granularities: ["segment"] - }); - - console.log(transcription.text); - } - main(); - response: &verbose_transcription_response_example | + ] + }, + { + "token": "?", + "logprob": -0.0008108172, + "bytes": [63], + "top_logprobs": [ { - "task": "transcribe", - "language": "english", - "duration": 8.470000267028809, - "text": "The beach was a popular spot on a hot summer day. People were swimming in the ocean, building sandcastles, and playing beach volleyball.", - "segments": [ - { - "id": 0, - "seek": 0, - "start": 0.0, - "end": 3.319999933242798, - "text": " The beach was a popular spot on a hot summer day.", - "tokens": [ - 50364, 440, 7534, 390, 257, 3743, 4008, 322, 257, 2368, 4266, 786, 13, 50530 - ], - "temperature": 0.0, - "avg_logprob": -0.2860786020755768, - "compression_ratio": 1.2363636493682861, - "no_speech_prob": 0.00985979475080967 - }, - ... - ] + "token": "?", + "logprob": -0.0008108172, + "bytes": [63] + }, + { + "token": "?\n", + "logprob": -7.184561, + "bytes": [63, 10] } - /audio/translations: - post: - operationId: createTranslation - tags: - - Audio - summary: Translates audio into English. - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: "#/components/schemas/CreateTranslationRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - oneOf: - - $ref: "#/components/schemas/CreateTranslationResponseJson" - - $ref: "#/components/schemas/CreateTranslationResponseVerboseJson" - x-oaiMeta: - name: Create translation - group: audio - returns: The translated text. - examples: - request: - curl: | - curl https://api.openai.com/v1/audio/translations \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: multipart/form-data" \ - -F file="@/path/to/file/german.m4a" \ - -F model="whisper-1" - python: | - from openai import OpenAI - client = OpenAI() - - audio_file = open("speech.mp3", "rb") - transcript = client.audio.translations.create( - model="whisper-1", - file=audio_file - ) - node: | - import fs from "fs"; - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const translation = await openai.audio.translations.create({ - file: fs.createReadStream("speech.mp3"), - model: "whisper-1", - }); - - console.log(translation.text); - } - main(); - response: | - { - "text": "Hello, my name is Wolfgang and I come from Germany. Where are you heading today?" - } + ] + } + ] + }, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 9, + "completion_tokens": 9, + "total_tokens": 18 + }, + "system_fingerprint": null + } + /completions: + post: + tags: + - Completions + summary: Creates a completion for the provided prompt and parameters. + operationId: createCompletion + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateCompletionRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/CreateCompletionResponse' + x-oaiMeta: + name: Create completion + group: completions + returns: | + Returns a [completion](/docs/api-reference/completions/object) object, or a sequence of completion objects if the request is streamed. + legacy: true + examples: + - title: No streaming + request: + curl: | + curl https://api.openai.com/v1/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "VAR_model_id", + "prompt": "Say this is a test", + "max_tokens": 7, + "temperature": 0 + }' + python: | + from openai import OpenAI + client = OpenAI() + + client.completions.create( + model="VAR_model_id", + prompt="Say this is a test", + max_tokens=7, + temperature=0 + ) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const completion = await openai.completions.create({ + model: "VAR_model_id", + prompt: "Say this is a test.", + max_tokens: 7, + temperature: 0, + }); + + console.log(completion); + } + main(); + response: | + { + "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7", + "object": "text_completion", + "created": 1589478378, + "model": "VAR_model_id", + "system_fingerprint": "fp_44709d6fcb", + "choices": [ + { + "text": "\n\nThis is indeed a test", + "index": 0, + "logprobs": null, + "finish_reason": "length" + } + ], + "usage": { + "prompt_tokens": 5, + "completion_tokens": 7, + "total_tokens": 12 + } + } + - title: Streaming + request: + curl: | + curl https://api.openai.com/v1/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "VAR_model_id", + "prompt": "Say this is a test", + "max_tokens": 7, + "temperature": 0, + "stream": true + }' + python: | + from openai import OpenAI + client = OpenAI() + + for chunk in client.completions.create( + model="VAR_model_id", + prompt="Say this is a test", + max_tokens=7, + temperature=0, + stream=True + ): + print(chunk.choices[0].text) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const stream = await openai.completions.create({ + model: "VAR_model_id", + prompt: "Say this is a test.", + stream: true, + }); + + for await (const chunk of stream) { + console.log(chunk.choices[0].text) + } + } + main(); + response: | + { + "id": "cmpl-7iA7iJjj8V2zOkCGvWF2hAkDWBQZe", + "object": "text_completion", + "created": 1690759702, + "choices": [ + { + "text": "This", + "index": 0, + "logprobs": null, + "finish_reason": null + } + ], + "model": "gpt-3.5-turbo-instruct" + "system_fingerprint": "fp_44709d6fcb", + } + /images/generations: + post: + tags: + - Images + summary: Creates an image given a prompt. + operationId: createImage + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateImageRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ImagesResponse' + x-oaiMeta: + name: Create image + group: images + returns: "Returns a list of [image](/docs/api-reference/images/object) objects." + examples: + request: + curl: | + curl https://api.openai.com/v1/images/generations \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "dall-e-3", + "prompt": "A cute baby sea otter", + "n": 1, + "size": "1024x1024" + }' + python: | + from openai import OpenAI + client = OpenAI() + + client.images.generate( + model="dall-e-3", + prompt="A cute baby sea otter", + n=1, + size="1024x1024" + ) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const image = await openai.images.generate({ model: "dall-e-3", prompt: "A cute baby sea otter" }); + + console.log(image.data); + } + main(); + response: | + { + "created": 1589478378, + "data": [ + { + "url": "https://..." + }, + { + "url": "https://..." + } + ] + } + /images/edits: + post: + tags: + - Images + summary: Creates an edited or extended image given an original image and a prompt. + operationId: createImageEdit + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/CreateImageEditRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ImagesResponse' + x-oaiMeta: + name: Create image edit + group: images + returns: "Returns a list of [image](/docs/api-reference/images/object) objects." + examples: + request: + curl: | + curl https://api.openai.com/v1/images/edits \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -F image="@otter.png" \ + -F mask="@mask.png" \ + -F prompt="A cute baby sea otter wearing a beret" \ + -F n=2 \ + -F size="1024x1024" + python: | + from openai import OpenAI + client = OpenAI() + + client.images.edit( + image=open("otter.png", "rb"), + mask=open("mask.png", "rb"), + prompt="A cute baby sea otter wearing a beret", + n=2, + size="1024x1024" + ) + node.js: |- + import fs from "fs"; + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const image = await openai.images.edit({ + image: fs.createReadStream("otter.png"), + mask: fs.createReadStream("mask.png"), + prompt: "A cute baby sea otter wearing a beret", + }); + + console.log(image.data); + } + main(); + response: | + { + "created": 1589478378, + "data": [ + { + "url": "https://..." + }, + { + "url": "https://..." + } + ] + } + /images/variations: + post: + tags: + - Images + summary: Creates a variation of a given image. + operationId: createImageVariation + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/CreateImageVariationRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ImagesResponse' + x-oaiMeta: + name: Create image variation + group: images + returns: "Returns a list of [image](/docs/api-reference/images/object) objects." + examples: + request: + curl: | + curl https://api.openai.com/v1/images/variations \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -F image="@otter.png" \ + -F n=2 \ + -F size="1024x1024" + python: | + from openai import OpenAI + client = OpenAI() + + response = client.images.create_variation( + image=open("image_edit_original.png", "rb"), + n=2, + size="1024x1024" + ) + node.js: |- + import fs from "fs"; + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const image = await openai.images.createVariation({ + image: fs.createReadStream("otter.png"), + }); + + console.log(image.data); + } + main(); + response: | + { + "created": 1589478378, + "data": [ + { + "url": "https://..." + }, + { + "url": "https://..." + } + ] + } + /embeddings: + post: + tags: + - Embeddings + summary: Creates an embedding vector representing the input text. + operationId: createEmbedding + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateEmbeddingRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/CreateEmbeddingResponse' + x-oaiMeta: + name: Create embeddings + group: embeddings + returns: "A list of [embedding](/docs/api-reference/embeddings/object) objects." + examples: + request: + curl: | + curl https://api.openai.com/v1/embeddings \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -d '{ + "input": "The food was delicious and the waiter...", + "model": "text-embedding-ada-002", + "encoding_format": "float" + }' + python: | + from openai import OpenAI + client = OpenAI() + + client.embeddings.create( + model="text-embedding-ada-002", + input="The food was delicious and the waiter...", + encoding_format="float" + ) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const embedding = await openai.embeddings.create({ + model: "text-embedding-ada-002", + input: "The quick brown fox jumped over the lazy dog", + encoding_format: "float", + }); + + console.log(embedding); + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "object": "embedding", + "embedding": [ + 0.0023064255, + -0.009327292, + .... (1536 floats total for ada-002) + -0.0028842222, + ], + "index": 0 + } + ], + "model": "text-embedding-ada-002", + "usage": { + "prompt_tokens": 8, + "total_tokens": 8 + } + } + /audio/speech: + post: + tags: + - Audio + summary: Generates audio from the input text. + operationId: createSpeech + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateSpeechRequest' + required: true + responses: + "200": + description: OK + headers: + Transfer-Encoding: + description: chunked + style: simple + explode: false + schema: + type: string + content: + application/octet-stream: + schema: + type: string + format: binary + x-oaiMeta: + name: Create speech + group: audio + returns: The audio file content. + examples: + request: + curl: | + curl https://api.openai.com/v1/audio/speech \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -d '{ + "model": "tts-1", + "input": "The quick brown fox jumped over the lazy dog.", + "voice": "alloy" + }' \ + --output speech.mp3 + python: | + from pathlib import Path + import openai + + speech_file_path = Path(__file__).parent / "speech.mp3" + response = openai.audio.speech.create( + model="tts-1", + voice="alloy", + input="The quick brown fox jumped over the lazy dog." + ) + response.stream_to_file(speech_file_path) + node: | + import fs from "fs"; + import path from "path"; + import OpenAI from "openai"; + + const openai = new OpenAI(); + + const speechFile = path.resolve("./speech.mp3"); + + async function main() { + const mp3 = await openai.audio.speech.create({ + model: "tts-1", + voice: "alloy", + input: "Today is a wonderful day to build something people love!", + }); + console.log(speechFile); + const buffer = Buffer.from(await mp3.arrayBuffer()); + await fs.promises.writeFile(speechFile, buffer); + } + main(); + /audio/transcriptions: + post: + tags: + - Audio + summary: Transcribes audio into the input language. + operationId: createTranscription + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/CreateTranscriptionRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/InlineResponse200' + x-oaiMeta: + name: Create transcription + group: audio + returns: "The [transcription object](/docs/api-reference/audio/json-object)\ + \ or a [verbose transcription object](/docs/api-reference/audio/verbose-json-object)." + examples: + - title: Default + request: + curl: | + curl https://api.openai.com/v1/audio/transcriptions \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: multipart/form-data" \ + -F file="@/path/to/file/audio.mp3" \ + -F model="whisper-1" + python: | + from openai import OpenAI + client = OpenAI() + + audio_file = open("speech.mp3", "rb") + transcript = client.audio.transcriptions.create( + model="whisper-1", + file=audio_file + ) + node: | + import fs from "fs"; + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const transcription = await openai.audio.transcriptions.create({ + file: fs.createReadStream("audio.mp3"), + model: "whisper-1", + }); + + console.log(transcription.text); + } + main(); + response: | + { + "text": "Imagine the wildest idea that you've ever had, and you're curious about how it might scale to something that's a 100, a 1,000 times bigger. This is a place where you can get to do that." + } + - title: Word timestamps + request: + curl: | + curl https://api.openai.com/v1/audio/transcriptions \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: multipart/form-data" \ + -F file="@/path/to/file/audio.mp3" \ + -F "timestamp_granularities[]=word" \ + -F model="whisper-1" \ + -F response_format="verbose_json" + python: | + from openai import OpenAI + client = OpenAI() + + audio_file = open("speech.mp3", "rb") + transcript = client.audio.transcriptions.create( + file=audio_file, + model="whisper-1", + response_format="verbose_json", + timestamp_granularities=["word"] + ) + + print(transcript.words) + node: | + import fs from "fs"; + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const transcription = await openai.audio.transcriptions.create({ + file: fs.createReadStream("audio.mp3"), + model: "whisper-1", + response_format: "verbose_json", + timestamp_granularities: ["word"] + }); + + console.log(transcription.text); + } + main(); + response: | + { + "task": "transcribe", + "language": "english", + "duration": 8.470000267028809, + "text": "The beach was a popular spot on a hot summer day. People were swimming in the ocean, building sandcastles, and playing beach volleyball.", + "words": [ + { + "word": "The", + "start": 0.0, + "end": 0.23999999463558197 + }, + ... + { + "word": "volleyball", + "start": 7.400000095367432, + "end": 7.900000095367432 + } + ] + } + - title: Segment timestamps + request: + curl: | + curl https://api.openai.com/v1/audio/transcriptions \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: multipart/form-data" \ + -F file="@/path/to/file/audio.mp3" \ + -F "timestamp_granularities[]=segment" \ + -F model="whisper-1" \ + -F response_format="verbose_json" + python: | + from openai import OpenAI + client = OpenAI() + + audio_file = open("speech.mp3", "rb") + transcript = client.audio.transcriptions.create( + file=audio_file, + model="whisper-1", + response_format="verbose_json", + timestamp_granularities=["segment"] + ) + + print(transcript.words) + node: | + import fs from "fs"; + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const transcription = await openai.audio.transcriptions.create({ + file: fs.createReadStream("audio.mp3"), + model: "whisper-1", + response_format: "verbose_json", + timestamp_granularities: ["segment"] + }); + + console.log(transcription.text); + } + main(); + response: | + { + "task": "transcribe", + "language": "english", + "duration": 8.470000267028809, + "text": "The beach was a popular spot on a hot summer day. People were swimming in the ocean, building sandcastles, and playing beach volleyball.", + "segments": [ + { + "id": 0, + "seek": 0, + "start": 0.0, + "end": 3.319999933242798, + "text": " The beach was a popular spot on a hot summer day.", + "tokens": [ + 50364, 440, 7534, 390, 257, 3743, 4008, 322, 257, 2368, 4266, 786, 13, 50530 + ], + "temperature": 0.0, + "avg_logprob": -0.2860786020755768, + "compression_ratio": 1.2363636493682861, + "no_speech_prob": 0.00985979475080967 + }, + ... + ] + } + /audio/translations: + post: + tags: + - Audio + summary: Translates audio into English. + operationId: createTranslation + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/CreateTranslationRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/InlineResponse2001' + x-oaiMeta: + name: Create translation + group: audio + returns: The translated text. + examples: + request: + curl: | + curl https://api.openai.com/v1/audio/translations \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: multipart/form-data" \ + -F file="@/path/to/file/german.m4a" \ + -F model="whisper-1" + python: | + from openai import OpenAI + client = OpenAI() + + audio_file = open("speech.mp3", "rb") + transcript = client.audio.translations.create( + model="whisper-1", + file=audio_file + ) + node: | + import fs from "fs"; + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const translation = await openai.audio.translations.create({ + file: fs.createReadStream("speech.mp3"), + model: "whisper-1", + }); + + console.log(translation.text); + } + main(); + response: | + { + "text": "Hello, my name is Wolfgang and I come from Germany. Where are you heading today?" + } + /files: + get: + tags: + - Files + summary: Returns a list of files that belong to the user's organization. + operationId: listFiles + parameters: + - name: purpose + in: query + description: Only return files with the given purpose + required: false + style: form + explode: true + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ListFilesResponse' + x-oaiMeta: + name: List files + group: files + returns: "A list of [File](/docs/api-reference/files/object) objects." + examples: + request: + curl: | + curl https://api.openai.com/v1/files \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.files.list() + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const list = await openai.files.list(); + + for await (const file of list) { + console.log(file); + } + } + + main(); + response: | + { + "data": [ + { + "id": "file-abc123", + "object": "file", + "bytes": 175, + "created_at": 1613677385, + "filename": "salesOverview.pdf", + "purpose": "assistants", + }, + { + "id": "file-abc123", + "object": "file", + "bytes": 140, + "created_at": 1613779121, + "filename": "puppy.jsonl", + "purpose": "fine-tune", + } + ], + "object": "list" + } + post: + tags: + - Files + summary: | + Upload a file that can be used across various endpoints. Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB. + + The Assistants API supports files up to 2 million tokens and of specific file types. See the [Assistants Tools guide](/docs/assistants/tools) for details. + + The Fine-tuning API only supports `.jsonl` files. The input also has certain required formats for fine-tuning [chat](/docs/api-reference/fine-tuning/chat-input) or [completions](/docs/api-reference/fine-tuning/completions-input) models. + + The Batch API only supports `.jsonl` files up to 100 MB in size. The input also has a specific required [format](/docs/api-reference/batch/request-input). + + Please [contact us](https://help.openai.com/) if you need to increase these storage limits. + operationId: createFile + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/CreateFileRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/OpenAIFile' + x-oaiMeta: + name: Upload file + group: files + returns: "The uploaded [File](/docs/api-reference/files/object) object." + examples: + request: + curl: | + curl https://api.openai.com/v1/files \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -F purpose="fine-tune" \ + -F file="@mydata.jsonl" + python: | + from openai import OpenAI + client = OpenAI() + + client.files.create( + file=open("mydata.jsonl", "rb"), + purpose="fine-tune" + ) + node.js: |- + import fs from "fs"; + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const file = await openai.files.create({ + file: fs.createReadStream("mydata.jsonl"), + purpose: "fine-tune", + }); + + console.log(file); + } + + main(); + response: | + { + "id": "file-abc123", + "object": "file", + "bytes": 120000, + "created_at": 1677610602, + "filename": "mydata.jsonl", + "purpose": "fine-tune", + } + /files/{fileId}: + get: + tags: + - Files + summary: Returns information about a specific file. + operationId: retrieveFile + parameters: + - name: fileId + in: path + description: The ID of the file to use for this request + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/OpenAIFile' + x-oaiMeta: + name: Retrieve file + group: files + returns: "The [File](/docs/api-reference/files/object) object matching the\ + \ specified ID." + examples: + request: + curl: | + curl https://api.openai.com/v1/files/file-abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.files.retrieve("file-abc123") + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const file = await openai.files.retrieve("file-abc123"); + + console.log(file); + } + + main(); + response: | + { + "id": "file-abc123", + "object": "file", + "bytes": 120000, + "created_at": 1677610602, + "filename": "mydata.jsonl", + "purpose": "fine-tune", + } + delete: + tags: + - Files + summary: Delete a file. + operationId: deleteFile + parameters: + - name: fileId + in: path + description: The ID of the file to use for this request + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/DeleteFileResponse' + x-oaiMeta: + name: Delete file + group: files + returns: Deletion status. + examples: + request: + curl: | + curl https://api.openai.com/v1/files/file-abc123 \ + -X DELETE \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.files.delete("file-abc123") + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const file = await openai.files.del("file-abc123"); + + console.log(file); + } + + main(); + response: | + { + "id": "file-abc123", + "object": "file", + "deleted": true + } + /files/{fileId}/content: + get: + tags: + - Files + summary: Returns the contents of the specified file. + operationId: downloadFile + parameters: + - name: fileId + in: path + description: The ID of the file to use for this request + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: OK + content: + application/octet-stream: + schema: + type: string + x-oaiMeta: + name: Retrieve file content + group: files + returns: The file content. + examples: + request: + curl: | + curl https://api.openai.com/v1/files/file-abc123/content \ + -H "Authorization: Bearer $OPENAI_API_KEY" > file.jsonl + python: | + from openai import OpenAI + client = OpenAI() + + content = client.files.content("file-abc123") + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const file = await openai.files.content("file-abc123"); + + console.log(file); + } + + main(); + /uploads: + post: + tags: + - Uploads + summary: | + Creates an intermediate [Upload](/docs/api-reference/uploads/object) object that you can add [Parts](/docs/api-reference/uploads/part-object) to. Currently, an Upload can accept at most 8 GB in total and expires after an hour after you create it. + + Once you complete the Upload, we will create a [File](/docs/api-reference/files/object) object that contains all the parts you uploaded. This File is usable in the rest of our platform as a regular File object. + + For certain `purpose`s, the correct `mime_type` must be specified. Please refer to documentation for the supported MIME types for your use case: + - [Assistants](/docs/assistants/tools/file-search/supported-files) + + For guidance on the proper filename extensions for each purpose, please follow the documentation on [creating a File](/docs/api-reference/files/create). + operationId: createUpload + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateUploadRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Upload' + x-oaiMeta: + name: Create upload + group: uploads + returns: "The [Upload](/docs/api-reference/uploads/object) object with status\ + \ `pending`." + examples: + request: + curl: | + curl https://api.openai.com/v1/uploads \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "purpose": "fine-tune", + "filename": "training_examples.jsonl", + "bytes": 2147483648, + "mime_type": "text/jsonl" + }' + response: | + { + "id": "upload_abc123", + "object": "upload", + "bytes": 2147483648, + "created_at": 1719184911, + "filename": "training_examples.jsonl", + "purpose": "fine-tune", + "status": "pending", + "expires_at": 1719127296 + } + /uploads/{uploadId}/parts: + post: + tags: + - Uploads + summary: "Adds a [Part](/docs/api-reference/uploads/part-object) to an [Upload](/docs/api-reference/uploads/object)\ + \ object. A Part represents a chunk of bytes from the file you are trying\ + \ to upload. \n\nEach Part can be at most 64 MB, and you can add Parts until\ + \ you hit the Upload maximum of 8 GB.\n\nIt is possible to add multiple Parts\ + \ in parallel. You can decide the intended order of the Parts when you [complete\ + \ the Upload](/docs/api-reference/uploads/complete).\n" + operationId: addUploadPart + parameters: + - name: uploadId + in: path + description: | + The ID of the Upload + required: true + style: simple + explode: false + schema: + type: string + example: upload_abc123 + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/AddUploadPartRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/UploadPart' + x-oaiMeta: + name: Add upload part + group: uploads + returns: "The upload [Part](/docs/api-reference/uploads/part-object) object." + examples: + request: + curl: | + curl https://api.openai.com/v1/uploads/upload_abc123/parts + -F data="aHR0cHM6Ly9hcGkub3BlbmFpLmNvbS92MS91cGxvYWRz..." + response: | + { + "id": "part_def456", + "object": "upload.part", + "created_at": 1719185911, + "upload_id": "upload_abc123" + } + /uploads/{uploadId}/complete: + post: + tags: + - Uploads + summary: "Completes the [Upload](/docs/api-reference/uploads/object). \n\nWithin\ + \ the returned Upload object, there is a nested [File](/docs/api-reference/files/object)\ + \ object that is ready to use in the rest of the platform.\n\nYou can specify\ + \ the order of the Parts by passing in an ordered list of the Part IDs.\n\n\ + The number of bytes uploaded upon completion must match the number of bytes\ + \ initially specified when creating the Upload object. No Parts may be added\ + \ after an Upload is completed.\n" + operationId: completeUpload + parameters: + - name: uploadId + in: path + description: | + The ID of the Upload + required: true + style: simple + explode: false + schema: + type: string + example: upload_abc123 + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CompleteUploadRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Upload' + x-oaiMeta: + name: Complete upload + group: uploads + returns: "The [Upload](/docs/api-reference/uploads/object) object with status\ + \ `completed` with an additional `file` property containing the created\ + \ usable File object." + examples: + request: + curl: | + curl https://api.openai.com/v1/uploads/upload_abc123/complete + -d '{ + "part_ids": ["part_def456", "part_ghi789"] + }' + response: | + { + "id": "upload_abc123", + "object": "upload", + "bytes": 2147483648, + "created_at": 1719184911, + "filename": "training_examples.jsonl", + "purpose": "fine-tune", + "status": "completed", + "expires_at": 1719127296, + "file": { + "id": "file-xyz321", + "object": "file", + "bytes": 2147483648, + "created_at": 1719186911, + "filename": "training_examples.jsonl", + "purpose": "fine-tune", + } + } + /uploads/{uploadId}/cancel: + post: + tags: + - Uploads + summary: | + Cancels the Upload. No Parts may be added after an Upload is cancelled. + operationId: cancelUpload + parameters: + - name: uploadId + in: path + description: | + The ID of the Upload + required: true + style: simple + explode: false + schema: + type: string + example: upload_abc123 + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Upload' + x-oaiMeta: + name: Cancel upload + group: uploads + returns: "The [Upload](/docs/api-reference/uploads/object) object with status\ + \ `cancelled`." + examples: + request: + curl: | + curl https://api.openai.com/v1/uploads/upload_abc123/cancel + response: | + { + "id": "upload_abc123", + "object": "upload", + "bytes": 2147483648, + "created_at": 1719184911, + "filename": "training_examples.jsonl", + "purpose": "fine-tune", + "status": "cancelled", + "expires_at": 1719127296 + } + /fine_tuning/jobs: + get: + tags: + - Fine-tuning + summary: | + List your organization's fine-tuning jobs + operationId: listPaginatedFineTuningJobs + parameters: + - name: after + in: query + description: Identifier for the last job from the previous pagination request + required: false + style: form + explode: true + schema: + type: string + - name: limit + in: query + description: Number of fine-tuning jobs to retrieve + required: false + style: form + explode: true + schema: + type: integer + default: 20 + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ListPaginatedFineTuningJobsResponse' + x-oaiMeta: + name: List fine-tuning jobs + group: fine-tuning + returns: "A list of paginated [fine-tuning job](/docs/api-reference/fine-tuning/object)\ + \ objects." + examples: + request: + curl: | + curl https://api.openai.com/v1/fine_tuning/jobs?limit=2 \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.fine_tuning.jobs.list() + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const list = await openai.fineTuning.jobs.list(); + + for await (const fineTune of list) { + console.log(fineTune); + } + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "object": "fine_tuning.job.event", + "id": "ft-event-TjX0lMfOniCZX64t9PUQT5hn", + "created_at": 1689813489, + "level": "warn", + "message": "Fine tuning process stopping due to job cancellation", + "data": null, + "type": "message" + }, + { ... }, + { ... } + ], "has_more": true + } + post: + tags: + - Fine-tuning + summary: | + Creates a fine-tuning job which begins the process of creating a new 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](/docs/guides/fine-tuning) + operationId: createFineTuningJob + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateFineTuningJobRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/FineTuningJob' + x-oaiMeta: + name: Create fine-tuning job + group: fine-tuning + returns: "A [fine-tuning.job](/docs/api-reference/fine-tuning/object) object." + examples: + - title: Default + request: + curl: | + curl https://api.openai.com/v1/fine_tuning/jobs \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "training_file": "file-BK7bzQj3FfZFXr7DbL6xJwfo", + "model": "gpt-3.5-turbo" + }' + python: | + from openai import OpenAI + client = OpenAI() + + client.fine_tuning.jobs.create( + training_file="file-abc123", + model="gpt-3.5-turbo" + ) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const fineTune = await openai.fineTuning.jobs.create({ + training_file: "file-abc123" + }); + + console.log(fineTune); + } + + main(); + response: | + { + "object": "fine_tuning.job", + "id": "ftjob-abc123", + "model": "gpt-3.5-turbo-0125", + "created_at": 1614807352, + "fine_tuned_model": null, + "organization_id": "org-123", + "result_files": [], + "status": "queued", + "validation_file": null, + "training_file": "file-abc123", + } + - title: Epochs + request: + curl: | + curl https://api.openai.com/v1/fine_tuning/jobs \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "training_file": "file-abc123", + "model": "gpt-3.5-turbo", + "hyperparameters": { + "n_epochs": 2 + } + }' + python: | + from openai import OpenAI + client = OpenAI() + + client.fine_tuning.jobs.create( + training_file="file-abc123", + model="gpt-3.5-turbo", + hyperparameters={ + "n_epochs":2 + } + ) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const fineTune = await openai.fineTuning.jobs.create({ + training_file: "file-abc123", + model: "gpt-3.5-turbo", + hyperparameters: { n_epochs: 2 } + }); + + console.log(fineTune); + } + + main(); + response: | + { + "object": "fine_tuning.job", + "id": "ftjob-abc123", + "model": "gpt-3.5-turbo-0125", + "created_at": 1614807352, + "fine_tuned_model": null, + "organization_id": "org-123", + "result_files": [], + "status": "queued", + "validation_file": null, + "training_file": "file-abc123", + "hyperparameters": {"n_epochs": 2}, + } + - title: Validation file + request: + curl: | + curl https://api.openai.com/v1/fine_tuning/jobs \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "training_file": "file-abc123", + "validation_file": "file-abc123", + "model": "gpt-3.5-turbo" + }' + python: | + from openai import OpenAI + client = OpenAI() + + client.fine_tuning.jobs.create( + training_file="file-abc123", + validation_file="file-def456", + model="gpt-3.5-turbo" + ) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const fineTune = await openai.fineTuning.jobs.create({ + training_file: "file-abc123", + validation_file: "file-abc123" + }); + + console.log(fineTune); + } + + main(); + response: | + { + "object": "fine_tuning.job", + "id": "ftjob-abc123", + "model": "gpt-3.5-turbo-0125", + "created_at": 1614807352, + "fine_tuned_model": null, + "organization_id": "org-123", + "result_files": [], + "status": "queued", + "validation_file": "file-abc123", + "training_file": "file-abc123", + } + - title: W&B Integration + request: + curl: | + curl https://api.openai.com/v1/fine_tuning/jobs \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "training_file": "file-abc123", + "validation_file": "file-abc123", + "model": "gpt-3.5-turbo", + "integrations": [ + { + "type": "wandb", + "wandb": { + "project": "my-wandb-project", + "name": "ft-run-display-name" + "tags": [ + "first-experiment", "v2" + ] + } + } + ] + }' + response: | + { + "object": "fine_tuning.job", + "id": "ftjob-abc123", + "model": "gpt-3.5-turbo-0125", + "created_at": 1614807352, + "fine_tuned_model": null, + "organization_id": "org-123", + "result_files": [], + "status": "queued", + "validation_file": "file-abc123", + "training_file": "file-abc123", + "integrations": [ + { + "type": "wandb", + "wandb": { + "project": "my-wandb-project", + "entity": None, + "run_id": "ftjob-abc123" + } + } + ] + } + /fine_tuning/jobs/{fineTuningJobId}: + get: + tags: + - Fine-tuning + summary: | + Get info about a fine-tuning job. + + [Learn more about fine-tuning](/docs/guides/fine-tuning) + operationId: retrieveFineTuningJob + parameters: + - name: fineTuningJobId + in: path + description: | + The ID of the fine-tuning job + required: true + style: simple + explode: false + schema: + type: string + example: ft-AF1WoRqd3aJAHsqc9NY7iL8F + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/FineTuningJob' + x-oaiMeta: + name: Retrieve fine-tuning job + group: fine-tuning + returns: "The [fine-tuning](/docs/api-reference/fine-tuning/object) object\ + \ with the given ID." + examples: + request: + curl: | + curl https://api.openai.com/v1/fine_tuning/jobs/ft-AF1WoRqd3aJAHsqc9NY7iL8F \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.fine_tuning.jobs.retrieve("ftjob-abc123") + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const fineTune = await openai.fineTuning.jobs.retrieve("ftjob-abc123"); + + console.log(fineTune); + } + + main(); + response: | + { + "object": "fine_tuning.job", + "id": "ftjob-abc123", + "model": "davinci-002", + "created_at": 1692661014, + "finished_at": 1692661190, + "fine_tuned_model": "ft:davinci-002:my-org:custom_suffix:7q8mpxmy", + "organization_id": "org-123", + "result_files": [ + "file-abc123" + ], + "status": "succeeded", + "validation_file": null, + "training_file": "file-abc123", + "hyperparameters": { + "n_epochs": 4, + "batch_size": 1, + "learning_rate_multiplier": 1.0 + }, + "trained_tokens": 5768, + "integrations": [], + "seed": 0, + "estimated_finish": 0 + } + /fine_tuning/jobs/{fineTuningJobId}/events: + get: + tags: + - Fine-tuning + summary: | + Get status updates for a fine-tuning job. + operationId: listFineTuningEvents + parameters: + - name: fineTuningJobId + in: path + description: | + The ID of the fine-tuning job to get events for + required: true + style: simple + explode: false + schema: + type: string + example: ft-AF1WoRqd3aJAHsqc9NY7iL8F + - name: after + in: query + description: Identifier for the last event from the previous pagination request + required: false + style: form + explode: true + schema: + type: string + - name: limit + in: query + description: Number of events to retrieve + required: false + style: form + explode: true + schema: + type: integer + default: 20 + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ListFineTuningJobEventsResponse' + x-oaiMeta: + name: List fine-tuning events + group: fine-tuning + returns: A list of fine-tuning event objects. + examples: + request: + curl: | + curl https://api.openai.com/v1/fine_tuning/jobs/ftjob-abc123/events \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.fine_tuning.jobs.list_events( + fine_tuning_job_id="ftjob-abc123", + limit=2 + ) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const list = await openai.fineTuning.list_events(id="ftjob-abc123", limit=2); + + for await (const fineTune of list) { + console.log(fineTune); + } + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "object": "fine_tuning.job.event", + "id": "ft-event-ddTJfwuMVpfLXseO0Am0Gqjm", + "created_at": 1692407401, + "level": "info", + "message": "Fine tuning job successfully completed", + "data": null, + "type": "message" + }, + { + "object": "fine_tuning.job.event", + "id": "ft-event-tyiGuB72evQncpH87xe505Sv", + "created_at": 1692407400, + "level": "info", + "message": "New fine-tuned model created: ft:gpt-3.5-turbo:openai::7p4lURel", + "data": null, + "type": "message" + } + ], + "has_more": true + } + /fine_tuning/jobs/{fineTuningJobId}/cancel: + post: + tags: + - Fine-tuning + summary: | + Immediately cancel a fine-tune job. + operationId: cancelFineTuningJob + parameters: + - name: fineTuningJobId + in: path + description: | + The ID of the fine-tuning job to cancel + required: true + style: simple + explode: false + schema: + type: string + example: ft-AF1WoRqd3aJAHsqc9NY7iL8F + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/FineTuningJob' + x-oaiMeta: + name: Cancel fine-tuning + group: fine-tuning + returns: "The cancelled [fine-tuning](/docs/api-reference/fine-tuning/object)\ + \ object." + examples: + request: + curl: | + curl -X POST https://api.openai.com/v1/fine_tuning/jobs/ftjob-abc123/cancel \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.fine_tuning.jobs.cancel("ftjob-abc123") + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const fineTune = await openai.fineTuning.jobs.cancel("ftjob-abc123"); + + console.log(fineTune); + } + main(); + response: | + { + "object": "fine_tuning.job", + "id": "ftjob-abc123", + "model": "gpt-3.5-turbo-0125", + "created_at": 1689376978, + "fine_tuned_model": null, + "organization_id": "org-123", + "result_files": [], + "hyperparameters": { + "n_epochs": "auto" + }, + "status": "cancelled", + "validation_file": "file-abc123", + "training_file": "file-abc123" + } + /fine_tuning/jobs/{fineTuningJobId}/checkpoints: + get: + tags: + - Fine-tuning + summary: | + List checkpoints for a fine-tuning job. + operationId: listFineTuningJobCheckpoints + parameters: + - name: fineTuningJobId + in: path + description: | + The ID of the fine-tuning job to get checkpoints for + required: true + style: simple + explode: false + schema: + type: string + example: ft-AF1WoRqd3aJAHsqc9NY7iL8F + - name: after + in: query + description: Identifier for the last checkpoint ID from the previous pagination + request + required: false + style: form + explode: true + schema: + type: string + - name: limit + in: query + description: Number of checkpoints to retrieve + required: false + style: form + explode: true + schema: + type: integer + default: 10 + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ListFineTuningJobCheckpointsResponse' + x-oaiMeta: + name: List fine-tuning checkpoints + group: fine-tuning + returns: "A list of fine-tuning [checkpoint objects](/docs/api-reference/fine-tuning/checkpoint-object)\ + \ for a fine-tuning job." + examples: + request: + curl: | + curl https://api.openai.com/v1/fine_tuning/jobs/ftjob-abc123/checkpoints \ + -H "Authorization: Bearer $OPENAI_API_KEY" + response: | + { + "object": "list" + "data": [ + { + "object": "fine_tuning.job.checkpoint", + "id": "ftckpt_zc4Q7MP6XxulcVzj4MZdwsAB", + "created_at": 1519129973, + "fine_tuned_model_checkpoint": "ft:gpt-3.5-turbo-0125:my-org:custom-suffix:96olL566:ckpt-step-2000", + "metrics": { + "full_valid_loss": 0.134, + "full_valid_mean_token_accuracy": 0.874 + }, + "fine_tuning_job_id": "ftjob-abc123", + "step_number": 2000, + }, + { + "object": "fine_tuning.job.checkpoint", + "id": "ftckpt_enQCFmOTGj3syEpYVhBRLTSy", + "created_at": 1519129833, + "fine_tuned_model_checkpoint": "ft:gpt-3.5-turbo-0125:my-org:custom-suffix:7q8mpxmy:ckpt-step-1000", + "metrics": { + "full_valid_loss": 0.167, + "full_valid_mean_token_accuracy": 0.781 + }, + "fine_tuning_job_id": "ftjob-abc123", + "step_number": 1000, + }, + ], + "first_id": "ftckpt_zc4Q7MP6XxulcVzj4MZdwsAB", + "last_id": "ftckpt_enQCFmOTGj3syEpYVhBRLTSy", + "has_more": true + } + /models: + get: + tags: + - Models + summary: "Lists the currently available models, and provides basic information\ + \ about each one such as the owner and availability." + operationId: listModels + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ListModelsResponse' + x-oaiMeta: + name: List models + group: models + returns: "A list of [model](/docs/api-reference/models/object) objects." + examples: + request: + curl: | + curl https://api.openai.com/v1/models \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.models.list() + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const list = await openai.models.list(); + + for await (const model of list) { + console.log(model); + } + } + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "model-id-0", + "object": "model", + "created": 1686935002, + "owned_by": "organization-owner" + }, + { + "id": "model-id-1", + "object": "model", + "created": 1686935002, + "owned_by": "organization-owner", + }, + { + "id": "model-id-2", + "object": "model", + "created": 1686935002, + "owned_by": "openai" + }, + ], + "object": "list" + } + /models/{model}: + get: + tags: + - Models + summary: "Retrieves a model instance, providing basic information about the\ + \ model such as the owner and permissioning." + operationId: retrieveModel + parameters: + - name: model + in: path + description: The ID of the model to use for this request + required: true + style: simple + explode: false + schema: + type: string + example: gpt-3.5-turbo + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Model' + x-oaiMeta: + name: Retrieve model + group: models + returns: "The [model](/docs/api-reference/models/object) object matching the\ + \ specified ID." + examples: + request: + curl: | + curl https://api.openai.com/v1/models/VAR_model_id \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.models.retrieve("VAR_model_id") + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const model = await openai.models.retrieve("VAR_model_id"); + + console.log(model); + } + + main(); + response: | + { + "id": "VAR_model_id", + "object": "model", + "created": 1686935002, + "owned_by": "openai" + } + delete: + tags: + - Models + summary: Delete a fine-tuned model. You must have the Owner role in your organization + to delete a model. + operationId: deleteModel + parameters: + - name: model + in: path + description: The model to delete + required: true + style: simple + explode: false + schema: + type: string + example: ft:gpt-3.5-turbo:acemeco:suffix:abc123 + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/DeleteModelResponse' + x-oaiMeta: + name: Delete a fine-tuned model + group: models + returns: Deletion status. + examples: + request: + curl: | + curl https://api.openai.com/v1/models/ft:gpt-3.5-turbo:acemeco:suffix:abc123 \ + -X DELETE \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.models.delete("ft:gpt-3.5-turbo:acemeco:suffix:abc123") + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const model = await openai.models.del("ft:gpt-3.5-turbo:acemeco:suffix:abc123"); + + console.log(model); + } + main(); + response: | + { + "id": "ft:gpt-3.5-turbo:acemeco:suffix:abc123", + "object": "model", + "deleted": true + } + /moderations: + post: + tags: + - Moderations + summary: Classifies if text is potentially harmful. + operationId: createModeration + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateModerationRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/CreateModerationResponse' + x-oaiMeta: + name: Create moderation + group: moderations + returns: "A [moderation](/docs/api-reference/moderations/object) object." + examples: + request: + curl: | + curl https://api.openai.com/v1/moderations \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "input": "I want to kill them." + }' + python: | + from openai import OpenAI + client = OpenAI() + + moderation = client.moderations.create(input="I want to kill them.") + print(moderation) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const moderation = await openai.moderations.create({ input: "I want to kill them." }); + + console.log(moderation); + } + main(); + response: | + { + "id": "modr-XXXXX", + "model": "text-moderation-005", + "results": [ + { + "flagged": true, + "categories": { + "sexual": false, + "hate": false, + "harassment": false, + "self-harm": false, + "sexual/minors": false, + "hate/threatening": false, + "violence/graphic": false, + "self-harm/intent": false, + "self-harm/instructions": false, + "harassment/threatening": true, + "violence": true, + }, + "category_scores": { + "sexual": 1.2282071e-06, + "hate": 0.010696256, + "harassment": 0.29842457, + "self-harm": 1.5236925e-08, + "sexual/minors": 5.7246268e-08, + "hate/threatening": 0.0060676364, + "violence/graphic": 4.435014e-06, + "self-harm/intent": 8.098441e-10, + "self-harm/instructions": 2.8498655e-11, + "harassment/threatening": 0.63055265, + "violence": 0.99011886, + } + } + ] + } + /assistants: + get: + tags: + - Assistants + summary: Returns a list of assistants. + operationId: listAssistants + parameters: + - name: limit + in: query + description: | + A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20 + required: false + style: form + explode: true + schema: + type: integer + default: 20 + - name: order + in: query + description: | + Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order + required: false + style: form + explode: true + schema: + type: string + default: desc + enum: + - asc + - desc + - name: after + in: query + description: | + A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list + required: false + style: form + explode: true + schema: + type: string + - name: before + in: query + description: | + A cursor for use in pagination. `before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list + required: false + style: form + explode: true + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ListAssistantsResponse' + x-oaiMeta: + name: List assistants + group: assistants + beta: true + returns: "A list of [assistant](/docs/api-reference/assistants/object) objects." + examples: + request: + curl: | + curl "https://api.openai.com/v1/assistants?order=desc&limit=20" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" + python: | + from openai import OpenAI + client = OpenAI() + + my_assistants = client.beta.assistants.list( + order="desc", + limit="20", + ) + print(my_assistants.data) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const myAssistants = await openai.beta.assistants.list({ + order: "desc", + limit: "20", + }); + + console.log(myAssistants.data); + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "asst_abc123", + "object": "assistant", + "created_at": 1698982736, + "name": "Coding Tutor", + "description": null, + "model": "gpt-4-turbo", + "instructions": "You are a helpful assistant designed to make me better at coding!", + "tools": [], + "tool_resources": {}, + "metadata": {}, + "top_p": 1.0, + "temperature": 1.0, + "response_format": "auto" + }, + { + "id": "asst_abc456", + "object": "assistant", + "created_at": 1698982718, + "name": "My Assistant", + "description": null, + "model": "gpt-4-turbo", + "instructions": "You are a helpful assistant designed to make me better at coding!", + "tools": [], + "tool_resources": {}, + "metadata": {}, + "top_p": 1.0, + "temperature": 1.0, + "response_format": "auto" + }, + { + "id": "asst_abc789", + "object": "assistant", + "created_at": 1698982643, + "name": null, + "description": null, + "model": "gpt-4-turbo", + "instructions": null, + "tools": [], + "tool_resources": {}, + "metadata": {}, + "top_p": 1.0, + "temperature": 1.0, + "response_format": "auto" + } + ], + "first_id": "asst_abc123", + "last_id": "asst_abc789", + "has_more": false + } + post: + tags: + - Assistants + summary: Create an assistant with a model and instructions. + operationId: createAssistant + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateAssistantRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/AssistantObject' + x-oaiMeta: + name: Create assistant + group: assistants + beta: true + returns: "An [assistant](/docs/api-reference/assistants/object) object." + examples: + - title: Code Interpreter + request: + curl: | + curl "https://api.openai.com/v1/assistants" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.", + "name": "Math Tutor", + "tools": [{"type": "code_interpreter"}], + "model": "gpt-4-turbo" + }' + python: | + from openai import OpenAI + client = OpenAI() + + my_assistant = client.beta.assistants.create( + instructions="You are a personal math tutor. When asked a question, write and run Python code to answer the question.", + name="Math Tutor", + tools=[{"type": "code_interpreter"}], + model="gpt-4-turbo", + ) + print(my_assistant) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const myAssistant = await openai.beta.assistants.create({ + instructions: + "You are a personal math tutor. When asked a question, write and run Python code to answer the question.", + name: "Math Tutor", + tools: [{ type: "code_interpreter" }], + model: "gpt-4-turbo", + }); + + console.log(myAssistant); + } + + main(); + response: | + { + "id": "asst_abc123", + "object": "assistant", + "created_at": 1698984975, + "name": "Math Tutor", + "description": null, + "model": "gpt-4-turbo", + "instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.", + "tools": [ + { + "type": "code_interpreter" + } + ], + "metadata": {}, + "top_p": 1.0, + "temperature": 1.0, + "response_format": "auto" + } + - title: Files + request: + curl: | + curl https://api.openai.com/v1/assistants \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies.", + "tools": [{"type": "file_search"}], + "tool_resources": {"file_search": {"vector_store_ids": ["vs_123"]}}, + "model": "gpt-4-turbo" + }' + python: | + from openai import OpenAI + client = OpenAI() + + my_assistant = client.beta.assistants.create( + instructions="You are an HR bot, and you have access to files to answer employee questions about company policies.", + name="HR Helper", + tools=[{"type": "file_search"}], + tool_resources={"file_search": {"vector_store_ids": ["vs_123"]}}, + model="gpt-4-turbo" + ) + print(my_assistant) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const myAssistant = await openai.beta.assistants.create({ + instructions: + "You are an HR bot, and you have access to files to answer employee questions about company policies.", + name: "HR Helper", + tools: [{ type: "file_search" }], + tool_resources: { + file_search: { + vector_store_ids: ["vs_123"] + } + }, + model: "gpt-4-turbo" + }); + + console.log(myAssistant); + } + + main(); + response: | + { + "id": "asst_abc123", + "object": "assistant", + "created_at": 1699009403, + "name": "HR Helper", + "description": null, + "model": "gpt-4-turbo", + "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies.", + "tools": [ + { + "type": "file_search" + } + ], + "tool_resources": { + "file_search": { + "vector_store_ids": ["vs_123"] + } + }, + "metadata": {}, + "top_p": 1.0, + "temperature": 1.0, + "response_format": "auto" + } + /assistants/{assistantId}: + get: + tags: + - Assistants + summary: Retrieves an assistant. + operationId: getAssistant + parameters: + - name: assistantId + in: path + description: The ID of the assistant to retrieve + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/AssistantObject' + x-oaiMeta: + name: Retrieve assistant + group: assistants + beta: true + returns: "The [assistant](/docs/api-reference/assistants/object) object matching\ + \ the specified ID." + examples: + request: + curl: | + curl https://api.openai.com/v1/assistants/asst_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" + python: | + from openai import OpenAI + client = OpenAI() + + my_assistant = client.beta.assistants.retrieve("asst_abc123") + print(my_assistant) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const myAssistant = await openai.beta.assistants.retrieve( + "asst_abc123" + ); + + console.log(myAssistant); + } + + main(); + response: | + { + "id": "asst_abc123", + "object": "assistant", + "created_at": 1699009709, + "name": "HR Helper", + "description": null, + "model": "gpt-4-turbo", + "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies.", + "tools": [ + { + "type": "file_search" + } + ], + "metadata": {}, + "top_p": 1.0, + "temperature": 1.0, + "response_format": "auto" + } + post: + tags: + - Assistants + summary: Modifies an assistant. + operationId: modifyAssistant + parameters: + - name: assistantId + in: path + description: The ID of the assistant to modify + required: true + style: simple + explode: false + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ModifyAssistantRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/AssistantObject' + x-oaiMeta: + name: Modify assistant + group: assistants + beta: true + returns: "The modified [assistant](/docs/api-reference/assistants/object)\ + \ object." + examples: + request: + curl: | + curl https://api.openai.com/v1/assistants/asst_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies. Always response with info from either of the files.", + "tools": [{"type": "file_search"}], + "model": "gpt-4-turbo" + }' + python: | + from openai import OpenAI + client = OpenAI() + + my_updated_assistant = client.beta.assistants.update( + "asst_abc123", + instructions="You are an HR bot, and you have access to files to answer employee questions about company policies. Always response with info from either of the files.", + name="HR Helper", + tools=[{"type": "file_search"}], + model="gpt-4-turbo" + ) + + print(my_updated_assistant) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const myUpdatedAssistant = await openai.beta.assistants.update( + "asst_abc123", + { + instructions: + "You are an HR bot, and you have access to files to answer employee questions about company policies. Always response with info from either of the files.", + name: "HR Helper", + tools: [{ type: "file_search" }], + model: "gpt-4-turbo" + } + ); + + console.log(myUpdatedAssistant); + } + + main(); + response: | + { + "id": "asst_123", + "object": "assistant", + "created_at": 1699009709, + "name": "HR Helper", + "description": null, + "model": "gpt-4-turbo", + "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies. Always response with info from either of the files.", + "tools": [ + { + "type": "file_search" + } + ], + "tool_resources": { + "file_search": { + "vector_store_ids": [] + } + }, + "metadata": {}, + "top_p": 1.0, + "temperature": 1.0, + "response_format": "auto" + } + delete: + tags: + - Assistants + summary: Delete an assistant. + operationId: deleteAssistant + parameters: + - name: assistantId + in: path + description: The ID of the assistant to delete + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/DeleteAssistantResponse' + x-oaiMeta: + name: Delete assistant + group: assistants + beta: true + returns: Deletion status + examples: + request: + curl: | + curl https://api.openai.com/v1/assistants/asst_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" \ + -X DELETE + python: | + from openai import OpenAI + client = OpenAI() + + response = client.beta.assistants.delete("asst_abc123") + print(response) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const response = await openai.beta.assistants.del("asst_abc123"); + + console.log(response); + } + main(); + response: | + { + "id": "asst_abc123", + "object": "assistant.deleted", + "deleted": true + } + /threads: + post: + tags: + - Assistants + summary: Create a thread. + operationId: createThread + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateThreadRequest' + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ThreadObject' + x-oaiMeta: + name: Create thread + group: threads + beta: true + returns: "A [thread](/docs/api-reference/threads) object." + examples: + - title: Empty + request: + curl: | + curl https://api.openai.com/v1/threads \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '' + python: | + from openai import OpenAI + client = OpenAI() + + empty_thread = client.beta.threads.create() + print(empty_thread) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const emptyThread = await openai.beta.threads.create(); + + console.log(emptyThread); + } + + main(); + response: | + { + "id": "thread_abc123", + "object": "thread", + "created_at": 1699012949, + "metadata": {}, + "tool_resources": {} + } + - title: Messages + request: + curl: | + curl https://api.openai.com/v1/threads \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "messages": [{ + "role": "user", + "content": "Hello, what is AI?" + }, { + "role": "user", + "content": "How does AI work? Explain it in simple terms." + }] + }' + python: | + from openai import OpenAI + client = OpenAI() + + message_thread = client.beta.threads.create( + messages=[ + { + "role": "user", + "content": "Hello, what is AI?" + }, + { + "role": "user", + "content": "How does AI work? Explain it in simple terms." + }, + ] + ) - /files: - get: - operationId: listFiles - tags: - - Files - summary: Returns a list of files that belong to the user's organization. - parameters: - - in: query - name: purpose - required: false - schema: - type: string - description: Only return files with the given purpose. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ListFilesResponse" - x-oaiMeta: - name: List files - group: files - returns: A list of [File](/docs/api-reference/files/object) objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/files \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - from openai import OpenAI - client = OpenAI() - - client.files.list() - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const list = await openai.files.list(); - - for await (const file of list) { - console.log(file); - } - } + print(message_thread) + node.js: |- + import OpenAI from "openai"; - main(); - response: | - { - "data": [ - { - "id": "file-abc123", - "object": "file", - "bytes": 175, - "created_at": 1613677385, - "filename": "salesOverview.pdf", - "purpose": "assistants", - }, - { - "id": "file-abc123", - "object": "file", - "bytes": 140, - "created_at": 1613779121, - "filename": "puppy.jsonl", - "purpose": "fine-tune", - } - ], - "object": "list" - } - post: - operationId: createFile - tags: - - Files - summary: | - Upload a file that can be used across various endpoints. Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB. - - The Assistants API supports files up to 2 million tokens and of specific file types. See the [Assistants Tools guide](/docs/assistants/tools) for details. - - The Fine-tuning API only supports `.jsonl` files. The input also has certain required formats for fine-tuning [chat](/docs/api-reference/fine-tuning/chat-input) or [completions](/docs/api-reference/fine-tuning/completions-input) models. - - The Batch API only supports `.jsonl` files up to 100 MB in size. The input also has a specific required [format](/docs/api-reference/batch/request-input). - - Please [contact us](https://help.openai.com/) if you need to increase these storage limits. - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: "#/components/schemas/CreateFileRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/OpenAIFile" - x-oaiMeta: - name: Upload file - group: files - returns: The uploaded [File](/docs/api-reference/files/object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/files \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -F purpose="fine-tune" \ - -F file="@mydata.jsonl" - python: | - from openai import OpenAI - client = OpenAI() - - client.files.create( - file=open("mydata.jsonl", "rb"), - purpose="fine-tune" - ) - node.js: |- - import fs from "fs"; - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const file = await openai.files.create({ - file: fs.createReadStream("mydata.jsonl"), - purpose: "fine-tune", - }); - - console.log(file); - } + const openai = new OpenAI(); - main(); - response: | - { - "id": "file-abc123", - "object": "file", - "bytes": 120000, - "created_at": 1677610602, - "filename": "mydata.jsonl", - "purpose": "fine-tune", - } - /files/{file_id}: - delete: - operationId: deleteFile - tags: - - Files - summary: Delete a file. - parameters: - - in: path - name: file_id - required: true - schema: - type: string - description: The ID of the file to use for this request. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/DeleteFileResponse" - x-oaiMeta: - name: Delete file - group: files - returns: Deletion status. - examples: - request: - curl: | - curl https://api.openai.com/v1/files/file-abc123 \ - -X DELETE \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - from openai import OpenAI - client = OpenAI() - - client.files.delete("file-abc123") - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const file = await openai.files.del("file-abc123"); - - console.log(file); - } + async function main() { + const messageThread = await openai.beta.threads.create({ + messages: [ + { + role: "user", + content: "Hello, what is AI?" + }, + { + role: "user", + content: "How does AI work? Explain it in simple terms.", + }, + ], + }); + + console.log(messageThread); + } + + main(); + response: | + { + "id": "thread_abc123", + "object": "thread", + "created_at": 1699014083, + "metadata": {}, + "tool_resources": {} + } + /threads/{threadId}: + get: + tags: + - Assistants + summary: Retrieves a thread. + operationId: getThread + parameters: + - name: threadId + in: path + description: The ID of the thread to retrieve + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ThreadObject' + x-oaiMeta: + name: Retrieve thread + group: threads + beta: true + returns: "The [thread](/docs/api-reference/threads/object) object matching\ + \ the specified ID." + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" + python: | + from openai import OpenAI + client = OpenAI() + + my_thread = client.beta.threads.retrieve("thread_abc123") + print(my_thread) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const myThread = await openai.beta.threads.retrieve( + "thread_abc123" + ); + + console.log(myThread); + } + + main(); + response: | + { + "id": "thread_abc123", + "object": "thread", + "created_at": 1699014083, + "metadata": {}, + "tool_resources": { + "code_interpreter": { + "file_ids": [] + } + } + } + post: + tags: + - Assistants + summary: Modifies a thread. + operationId: modifyThread + parameters: + - name: threadId + in: path + description: The ID of the thread to modify. Only the `metadata` can be modified + required: true + style: simple + explode: false + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ModifyThreadRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ThreadObject' + x-oaiMeta: + name: Modify thread + group: threads + beta: true + returns: "The modified [thread](/docs/api-reference/threads/object) object\ + \ matching the specified ID." + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "metadata": { + "modified": "true", + "user": "abc123" + } + }' + python: | + from openai import OpenAI + client = OpenAI() + + my_updated_thread = client.beta.threads.update( + "thread_abc123", + metadata={ + "modified": "true", + "user": "abc123" + } + ) + print(my_updated_thread) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const updatedThread = await openai.beta.threads.update( + "thread_abc123", + { + metadata: { modified: "true", user: "abc123" }, + } + ); + + console.log(updatedThread); + } + + main(); + response: | + { + "id": "thread_abc123", + "object": "thread", + "created_at": 1699014083, + "metadata": { + "modified": "true", + "user": "abc123" + }, + "tool_resources": {} + } + delete: + tags: + - Assistants + summary: Delete a thread. + operationId: deleteThread + parameters: + - name: threadId + in: path + description: The ID of the thread to delete + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/DeleteThreadResponse' + x-oaiMeta: + name: Delete thread + group: threads + beta: true + returns: Deletion status + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" \ + -X DELETE + python: | + from openai import OpenAI + client = OpenAI() + + response = client.beta.threads.delete("thread_abc123") + print(response) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const response = await openai.beta.threads.del("thread_abc123"); + + console.log(response); + } + main(); + response: | + { + "id": "thread_abc123", + "object": "thread.deleted", + "deleted": true + } + /threads/{threadId}/messages: + get: + tags: + - Assistants + summary: Returns a list of messages for a given thread. + operationId: listMessages + parameters: + - name: threadId + in: path + description: "The ID of the [thread](/docs/api-reference/threads) the messages\ + \ belong to" + required: true + style: simple + explode: false + schema: + type: string + - name: limit + in: query + description: | + A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20 + required: false + style: form + explode: true + schema: + type: integer + default: 20 + - name: order + in: query + description: | + Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order + required: false + style: form + explode: true + schema: + type: string + default: desc + enum: + - asc + - desc + - name: after + in: query + description: | + A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list + required: false + style: form + explode: true + schema: + type: string + - name: before + in: query + description: | + A cursor for use in pagination. `before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list + required: false + style: form + explode: true + schema: + type: string + - name: run_id + in: query + description: | + Filter messages by the run ID that generated them + required: false + style: form + explode: true + schema: + type: string + x-ballerina-name: runId + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ListMessagesResponse' + x-oaiMeta: + name: List messages + group: threads + beta: true + returns: "A list of [message](/docs/api-reference/messages) objects." + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/messages \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" + python: | + from openai import OpenAI + client = OpenAI() + + thread_messages = client.beta.threads.messages.list("thread_abc123") + print(thread_messages.data) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const threadMessages = await openai.beta.threads.messages.list( + "thread_abc123" + ); + + console.log(threadMessages.data); + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "msg_abc123", + "object": "thread.message", + "created_at": 1699016383, + "assistant_id": null, + "thread_id": "thread_abc123", + "run_id": null, + "role": "user", + "content": [ + { + "type": "text", + "text": { + "value": "How does AI work? Explain it in simple terms.", + "annotations": [] + } + } + ], + "attachments": [], + "metadata": {} + }, + { + "id": "msg_abc456", + "object": "thread.message", + "created_at": 1699016383, + "assistant_id": null, + "thread_id": "thread_abc123", + "run_id": null, + "role": "user", + "content": [ + { + "type": "text", + "text": { + "value": "Hello, what is AI?", + "annotations": [] + } + } + ], + "attachments": [], + "metadata": {} + } + ], + "first_id": "msg_abc123", + "last_id": "msg_abc456", + "has_more": false + } + post: + tags: + - Assistants + summary: Create a message. + operationId: createMessage + parameters: + - name: threadId + in: path + description: "The ID of the [thread](/docs/api-reference/threads) to create\ + \ a message for" + required: true + style: simple + explode: false + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateMessageRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/MessageObject' + x-oaiMeta: + name: Create message + group: threads + beta: true + returns: "A [message](/docs/api-reference/messages/object) object." + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/messages \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "role": "user", + "content": "How does AI work? Explain it in simple terms." + }' + python: | + from openai import OpenAI + client = OpenAI() + + thread_message = client.beta.threads.messages.create( + "thread_abc123", + role="user", + content="How does AI work? Explain it in simple terms.", + ) + print(thread_message) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const threadMessages = await openai.beta.threads.messages.create( + "thread_abc123", + { role: "user", content: "How does AI work? Explain it in simple terms." } + ); + + console.log(threadMessages); + } + + main(); + response: | + { + "id": "msg_abc123", + "object": "thread.message", + "created_at": 1713226573, + "assistant_id": null, + "thread_id": "thread_abc123", + "run_id": null, + "role": "user", + "content": [ + { + "type": "text", + "text": { + "value": "How does AI work? Explain it in simple terms.", + "annotations": [] + } + } + ], + "attachments": [], + "metadata": {} + } + /threads/{threadId}/messages/{messageId}: + get: + tags: + - Assistants + summary: Retrieve a message. + operationId: getMessage + parameters: + - name: threadId + in: path + description: "The ID of the [thread](/docs/api-reference/threads) to which\ + \ this message belongs" + required: true + style: simple + explode: false + schema: + type: string + - name: messageId + in: path + description: The ID of the message to retrieve + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/MessageObject' + x-oaiMeta: + name: Retrieve message + group: threads + beta: true + returns: "The [message](/docs/api-reference/messages/object) object matching\ + \ the specified ID." + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" + python: | + from openai import OpenAI + client = OpenAI() + + message = client.beta.threads.messages.retrieve( + message_id="msg_abc123", + thread_id="thread_abc123", + ) + print(message) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const message = await openai.beta.threads.messages.retrieve( + "thread_abc123", + "msg_abc123" + ); + + console.log(message); + } + + main(); + response: | + { + "id": "msg_abc123", + "object": "thread.message", + "created_at": 1699017614, + "assistant_id": null, + "thread_id": "thread_abc123", + "run_id": null, + "role": "user", + "content": [ + { + "type": "text", + "text": { + "value": "How does AI work? Explain it in simple terms.", + "annotations": [] + } + } + ], + "attachments": [], + "metadata": {} + } + post: + tags: + - Assistants + summary: Modifies a message. + operationId: modifyMessage + parameters: + - name: threadId + in: path + description: The ID of the thread to which this message belongs + required: true + style: simple + explode: false + schema: + type: string + - name: messageId + in: path + description: The ID of the message to modify + required: true + style: simple + explode: false + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ModifyMessageRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/MessageObject' + x-oaiMeta: + name: Modify message + group: threads + beta: true + returns: "The modified [message](/docs/api-reference/messages/object) object." + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "metadata": { + "modified": "true", + "user": "abc123" + } + }' + python: | + from openai import OpenAI + client = OpenAI() + + message = client.beta.threads.messages.update( + message_id="msg_abc12", + thread_id="thread_abc123", + metadata={ + "modified": "true", + "user": "abc123", + }, + ) + print(message) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const message = await openai.beta.threads.messages.update( + "thread_abc123", + "msg_abc123", + { + metadata: { + modified: "true", + user: "abc123", + }, + } + }' + response: | + { + "id": "msg_abc123", + "object": "thread.message", + "created_at": 1699017614, + "assistant_id": null, + "thread_id": "thread_abc123", + "run_id": null, + "role": "user", + "content": [ + { + "type": "text", + "text": { + "value": "How does AI work? Explain it in simple terms.", + "annotations": [] + } + } + ], + "file_ids": [], + "metadata": { + "modified": "true", + "user": "abc123" + } + } + delete: + tags: + - Assistants + summary: Deletes a message. + operationId: deleteMessage + parameters: + - name: threadId + in: path + description: The ID of the thread to which this message belongs + required: true + style: simple + explode: false + schema: + type: string + - name: messageId + in: path + description: The ID of the message to delete + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/DeleteMessageResponse' + x-oaiMeta: + name: Delete message + group: threads + beta: true + returns: Deletion status + examples: + request: + curl: | + curl -X DELETE https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" + python: | + from openai import OpenAI + client = OpenAI() + + deleted_message = client.beta.threads.messages.delete( + message_id="msg_abc12", + thread_id="thread_abc123", + ) + print(deleted_message) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const deletedMessage = await openai.beta.threads.messages.del( + "thread_abc123", + "msg_abc123" + ); + + console.log(deletedMessage); + } + response: | + { + "id": "msg_abc123", + "object": "thread.message.deleted", + "deleted": true + } + /threads/runs: + post: + tags: + - Assistants + summary: Create a thread and run it in one request. + operationId: createThreadAndRun + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateThreadAndRunRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/RunObject' + x-oaiMeta: + name: Create thread and run + group: threads + beta: true + returns: "A [run](/docs/api-reference/runs/object) object." + examples: + - title: Default + request: + curl: | + curl https://api.openai.com/v1/threads/runs \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "assistant_id": "asst_abc123", + "thread": { + "messages": [ + {"role": "user", "content": "Explain deep learning to a 5 year old."} + ] + } + }' + python: | + from openai import OpenAI + client = OpenAI() + + run = client.beta.threads.create_and_run( + assistant_id="asst_abc123", + thread={ + "messages": [ + {"role": "user", "content": "Explain deep learning to a 5 year old."} + ] + } + ) + + print(run) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const run = await openai.beta.threads.createAndRun({ + assistant_id: "asst_abc123", + thread: { + messages: [ + { role: "user", content: "Explain deep learning to a 5 year old." }, + ], + }, + }); + + console.log(run); + } + + main(); + response: | + { + "id": "run_abc123", + "object": "thread.run", + "created_at": 1699076792, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "queued", + "started_at": null, + "expires_at": 1699077392, + "cancelled_at": null, + "failed_at": null, + "completed_at": null, + "required_action": null, + "last_error": null, + "model": "gpt-4-turbo", + "instructions": "You are a helpful assistant.", + "tools": [], + "tool_resources": {}, + "metadata": {}, + "temperature": 1.0, + "top_p": 1.0, + "max_completion_tokens": null, + "max_prompt_tokens": null, + "truncation_strategy": { + "type": "auto", + "last_messages": null + }, + "incomplete_details": null, + "usage": null, + "response_format": "auto", + "tool_choice": "auto", + "parallel_tool_calls": true + } + - title: Streaming + request: + curl: | + curl https://api.openai.com/v1/threads/runs \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "assistant_id": "asst_123", + "thread": { + "messages": [ + {"role": "user", "content": "Hello"} + ] + }, + "stream": true + }' + python: | + from openai import OpenAI + client = OpenAI() + + stream = client.beta.threads.create_and_run( + assistant_id="asst_123", + thread={ + "messages": [ + {"role": "user", "content": "Hello"} + ] + }, + stream=True + ) + + for event in stream: + print(event) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const stream = await openai.beta.threads.createAndRun({ + assistant_id: "asst_123", + thread: { + messages: [ + { role: "user", content: "Hello" }, + ], + }, + stream: true + }); - main(); - response: | - { - "id": "file-abc123", - "object": "file", - "deleted": true - } - get: - operationId: retrieveFile - tags: - - Files - summary: Returns information about a specific file. - parameters: - - in: path - name: file_id - required: true - schema: - type: string - description: The ID of the file to use for this request. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/OpenAIFile" - x-oaiMeta: - name: Retrieve file - group: files - returns: The [File](/docs/api-reference/files/object) object matching the specified ID. - examples: - request: - curl: | - curl https://api.openai.com/v1/files/file-abc123 \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - from openai import OpenAI - client = OpenAI() - - client.files.retrieve("file-abc123") - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const file = await openai.files.retrieve("file-abc123"); - - console.log(file); - } + for await (const event of stream) { + console.log(event); + } + } - main(); - response: | - { - "id": "file-abc123", - "object": "file", - "bytes": 120000, - "created_at": 1677610602, - "filename": "mydata.jsonl", - "purpose": "fine-tune", - } - /files/{file_id}/content: - get: - operationId: downloadFile - tags: - - Files - summary: Returns the contents of the specified file. - parameters: - - in: path - name: file_id - required: true - schema: - type: string - description: The ID of the file to use for this request. - responses: - "200": - description: OK - content: - application/octet-stream: - schema: - type: string - x-oaiMeta: - name: Retrieve file content - group: files - returns: The file content. - examples: - request: - curl: | - curl https://api.openai.com/v1/files/file-abc123/content \ - -H "Authorization: Bearer $OPENAI_API_KEY" > file.jsonl - python: | - from openai import OpenAI - client = OpenAI() - - content = client.files.content("file-abc123") - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const file = await openai.files.content("file-abc123"); - - console.log(file); - } + main(); + response: | + event: thread.created + data: {"id":"thread_123","object":"thread","created_at":1710348075,"metadata":{}} - main(); - /uploads: - post: - operationId: createUpload - tags: - - Uploads - summary: | - Creates an intermediate [Upload](/docs/api-reference/uploads/object) object that you can add [Parts](/docs/api-reference/uploads/part-object) to. Currently, an Upload can accept at most 8 GB in total and expires after an hour after you create it. - - Once you complete the Upload, we will create a [File](/docs/api-reference/files/object) object that contains all the parts you uploaded. This File is usable in the rest of our platform as a regular File object. - - For certain `purpose`s, the correct `mime_type` must be specified. Please refer to documentation for the supported MIME types for your use case: - - [Assistants](/docs/assistants/tools/file-search/supported-files) - - For guidance on the proper filename extensions for each purpose, please follow the documentation on [creating a File](/docs/api-reference/files/create). - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateUploadRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/Upload" - x-oaiMeta: - name: Create upload - group: uploads - returns: The [Upload](/docs/api-reference/uploads/object) object with status `pending`. - examples: - request: - curl: | - curl https://api.openai.com/v1/uploads \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "purpose": "fine-tune", - "filename": "training_examples.jsonl", - "bytes": 2147483648, - "mime_type": "text/jsonl" - }' - response: | - { - "id": "upload_abc123", - "object": "upload", - "bytes": 2147483648, - "created_at": 1719184911, - "filename": "training_examples.jsonl", - "purpose": "fine-tune", - "status": "pending", - "expires_at": 1719127296 - } + event: thread.run.created + data: {"id":"run_123","object":"thread.run","created_at":1710348075,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710348675,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"tool_resources":{},"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true} - /uploads/{upload_id}/parts: - post: - operationId: addUploadPart - tags: - - Uploads - summary: | - Adds a [Part](/docs/api-reference/uploads/part-object) to an [Upload](/docs/api-reference/uploads/object) object. A Part represents a chunk of bytes from the file you are trying to upload. - - Each Part can be at most 64 MB, and you can add Parts until you hit the Upload maximum of 8 GB. - - It is possible to add multiple Parts in parallel. You can decide the intended order of the Parts when you [complete the Upload](/docs/api-reference/uploads/complete). - parameters: - - in: path - name: upload_id - required: true - schema: - type: string - example: upload_abc123 - description: | - The ID of the Upload. - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: "#/components/schemas/AddUploadPartRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/UploadPart" - x-oaiMeta: - name: Add upload part - group: uploads - returns: The upload [Part](/docs/api-reference/uploads/part-object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/uploads/upload_abc123/parts - -F data="aHR0cHM6Ly9hcGkub3BlbmFpLmNvbS92MS91cGxvYWRz..." - response: | - { - "id": "part_def456", - "object": "upload.part", - "created_at": 1719185911, - "upload_id": "upload_abc123" - } + event: thread.run.queued + data: {"id":"run_123","object":"thread.run","created_at":1710348075,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710348675,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"tool_resources":{},"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true} - /uploads/{upload_id}/complete: - post: - operationId: completeUpload - tags: - - Uploads - summary: | - Completes the [Upload](/docs/api-reference/uploads/object). - - Within the returned Upload object, there is a nested [File](/docs/api-reference/files/object) object that is ready to use in the rest of the platform. - - You can specify the order of the Parts by passing in an ordered list of the Part IDs. - - The number of bytes uploaded upon completion must match the number of bytes initially specified when creating the Upload object. No Parts may be added after an Upload is completed. - parameters: - - in: path - name: upload_id - required: true - schema: - type: string - example: upload_abc123 - description: | - The ID of the Upload. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CompleteUploadRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/Upload" - x-oaiMeta: - name: Complete upload - group: uploads - returns: The [Upload](/docs/api-reference/uploads/object) object with status `completed` with an additional `file` property containing the created usable File object. - examples: - request: - curl: | - curl https://api.openai.com/v1/uploads/upload_abc123/complete - -d '{ - "part_ids": ["part_def456", "part_ghi789"] - }' - response: | - { - "id": "upload_abc123", - "object": "upload", - "bytes": 2147483648, - "created_at": 1719184911, - "filename": "training_examples.jsonl", - "purpose": "fine-tune", - "status": "completed", - "expires_at": 1719127296, - "file": { - "id": "file-xyz321", - "object": "file", - "bytes": 2147483648, - "created_at": 1719186911, - "filename": "training_examples.jsonl", - "purpose": "fine-tune", - } - } + event: thread.run.in_progress + data: {"id":"run_123","object":"thread.run","created_at":1710348075,"assistant_id":"asst_123","thread_id":"thread_123","status":"in_progress","started_at":null,"expires_at":1710348675,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"tool_resources":{},"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true} - /uploads/{upload_id}/cancel: - post: - operationId: cancelUpload - tags: - - Uploads - summary: | - Cancels the Upload. No Parts may be added after an Upload is cancelled. - parameters: - - in: path - name: upload_id - required: true - schema: - type: string - example: upload_abc123 - description: | - The ID of the Upload. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/Upload" - x-oaiMeta: - name: Cancel upload - group: uploads - returns: The [Upload](/docs/api-reference/uploads/object) object with status `cancelled`. - examples: - request: - curl: | - curl https://api.openai.com/v1/uploads/upload_abc123/cancel - response: | - { - "id": "upload_abc123", - "object": "upload", - "bytes": 2147483648, - "created_at": 1719184911, - "filename": "training_examples.jsonl", - "purpose": "fine-tune", - "status": "cancelled", - "expires_at": 1719127296 - } - - /fine_tuning/jobs: - post: - operationId: createFineTuningJob - tags: - - Fine-tuning - summary: | - Creates a fine-tuning job which begins the process of creating a new 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](/docs/guides/fine-tuning) - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateFineTuningJobRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/FineTuningJob" - x-oaiMeta: - name: Create fine-tuning job - group: fine-tuning - returns: A [fine-tuning.job](/docs/api-reference/fine-tuning/object) object. - examples: - - title: Default - request: - curl: | - curl https://api.openai.com/v1/fine_tuning/jobs \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "training_file": "file-BK7bzQj3FfZFXr7DbL6xJwfo", - "model": "gpt-3.5-turbo" - }' - python: | - from openai import OpenAI - client = OpenAI() - - client.fine_tuning.jobs.create( - training_file="file-abc123", - model="gpt-3.5-turbo" - ) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const fineTune = await openai.fineTuning.jobs.create({ - training_file: "file-abc123" - }); - - console.log(fineTune); - } - - main(); - response: | - { - "object": "fine_tuning.job", - "id": "ftjob-abc123", - "model": "gpt-3.5-turbo-0125", - "created_at": 1614807352, - "fine_tuned_model": null, - "organization_id": "org-123", - "result_files": [], - "status": "queued", - "validation_file": null, - "training_file": "file-abc123", - } - - title: Epochs - request: - curl: | - curl https://api.openai.com/v1/fine_tuning/jobs \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "training_file": "file-abc123", - "model": "gpt-3.5-turbo", - "hyperparameters": { - "n_epochs": 2 - } - }' - python: | - from openai import OpenAI - client = OpenAI() - - client.fine_tuning.jobs.create( - training_file="file-abc123", - model="gpt-3.5-turbo", - hyperparameters={ - "n_epochs":2 - } - ) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const fineTune = await openai.fineTuning.jobs.create({ - training_file: "file-abc123", - model: "gpt-3.5-turbo", - hyperparameters: { n_epochs: 2 } - }); - - console.log(fineTune); - } - - main(); - response: | - { - "object": "fine_tuning.job", - "id": "ftjob-abc123", - "model": "gpt-3.5-turbo-0125", - "created_at": 1614807352, - "fine_tuned_model": null, - "organization_id": "org-123", - "result_files": [], - "status": "queued", - "validation_file": null, - "training_file": "file-abc123", - "hyperparameters": {"n_epochs": 2}, - } - - title: Validation file - request: - curl: | - curl https://api.openai.com/v1/fine_tuning/jobs \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "training_file": "file-abc123", - "validation_file": "file-abc123", - "model": "gpt-3.5-turbo" - }' - python: | - from openai import OpenAI - client = OpenAI() - - client.fine_tuning.jobs.create( - training_file="file-abc123", - validation_file="file-def456", - model="gpt-3.5-turbo" - ) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const fineTune = await openai.fineTuning.jobs.create({ - training_file: "file-abc123", - validation_file: "file-abc123" - }); - - console.log(fineTune); - } - - main(); - response: | - { - "object": "fine_tuning.job", - "id": "ftjob-abc123", - "model": "gpt-3.5-turbo-0125", - "created_at": 1614807352, - "fine_tuned_model": null, - "organization_id": "org-123", - "result_files": [], - "status": "queued", - "validation_file": "file-abc123", - "training_file": "file-abc123", - } - - title: W&B Integration - request: - curl: | - curl https://api.openai.com/v1/fine_tuning/jobs \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "training_file": "file-abc123", - "validation_file": "file-abc123", - "model": "gpt-3.5-turbo", - "integrations": [ - { - "type": "wandb", - "wandb": { - "project": "my-wandb-project", - "name": "ft-run-display-name" - "tags": [ - "first-experiment", "v2" - ] - } - } - ] - }' - response: | - { - "object": "fine_tuning.job", - "id": "ftjob-abc123", - "model": "gpt-3.5-turbo-0125", - "created_at": 1614807352, - "fine_tuned_model": null, - "organization_id": "org-123", - "result_files": [], - "status": "queued", - "validation_file": "file-abc123", - "training_file": "file-abc123", - "integrations": [ - { - "type": "wandb", - "wandb": { - "project": "my-wandb-project", - "entity": None, - "run_id": "ftjob-abc123" - } - } - ] - } - get: - operationId: listPaginatedFineTuningJobs - tags: - - Fine-tuning - summary: | - List your organization's fine-tuning jobs - parameters: - - name: after - in: query - description: Identifier for the last job from the previous pagination request. - required: false - schema: - type: string - - name: limit - in: query - description: Number of fine-tuning jobs to retrieve. - required: false - schema: - type: integer - default: 20 - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ListPaginatedFineTuningJobsResponse" - x-oaiMeta: - name: List fine-tuning jobs - group: fine-tuning - returns: A list of paginated [fine-tuning job](/docs/api-reference/fine-tuning/object) objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/fine_tuning/jobs?limit=2 \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - from openai import OpenAI - client = OpenAI() - - client.fine_tuning.jobs.list() - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const list = await openai.fineTuning.jobs.list(); - - for await (const fineTune of list) { - console.log(fineTune); - } - } + event: thread.run.step.created + data: {"id":"step_001","object":"thread.run.step","created_at":1710348076,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710348675,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":null} - main(); - response: | - { - "object": "list", - "data": [ - { - "object": "fine_tuning.job.event", - "id": "ft-event-TjX0lMfOniCZX64t9PUQT5hn", - "created_at": 1689813489, - "level": "warn", - "message": "Fine tuning process stopping due to job cancellation", - "data": null, - "type": "message" - }, - { ... }, - { ... } - ], "has_more": true - } - /fine_tuning/jobs/{fine_tuning_job_id}: - get: - operationId: retrieveFineTuningJob - tags: - - Fine-tuning - summary: | - Get info about a fine-tuning job. - - [Learn more about fine-tuning](/docs/guides/fine-tuning) - parameters: - - in: path - name: fine_tuning_job_id - required: true - schema: - type: string - example: ft-AF1WoRqd3aJAHsqc9NY7iL8F - description: | - The ID of the fine-tuning job. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/FineTuningJob" - x-oaiMeta: - name: Retrieve fine-tuning job - group: fine-tuning - returns: The [fine-tuning](/docs/api-reference/fine-tuning/object) object with the given ID. - examples: - request: - curl: | - curl https://api.openai.com/v1/fine_tuning/jobs/ft-AF1WoRqd3aJAHsqc9NY7iL8F \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - from openai import OpenAI - client = OpenAI() - - client.fine_tuning.jobs.retrieve("ftjob-abc123") - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const fineTune = await openai.fineTuning.jobs.retrieve("ftjob-abc123"); - - console.log(fineTune); - } + event: thread.run.step.in_progress + data: {"id":"step_001","object":"thread.run.step","created_at":1710348076,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710348675,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":null} - main(); - response: &fine_tuning_example | - { - "object": "fine_tuning.job", - "id": "ftjob-abc123", - "model": "davinci-002", - "created_at": 1692661014, - "finished_at": 1692661190, - "fine_tuned_model": "ft:davinci-002:my-org:custom_suffix:7q8mpxmy", - "organization_id": "org-123", - "result_files": [ - "file-abc123" - ], - "status": "succeeded", - "validation_file": null, - "training_file": "file-abc123", - "hyperparameters": { - "n_epochs": 4, - "batch_size": 1, - "learning_rate_multiplier": 1.0 - }, - "trained_tokens": 5768, - "integrations": [], - "seed": 0, - "estimated_finish": 0 - } - /fine_tuning/jobs/{fine_tuning_job_id}/events: - get: - operationId: listFineTuningEvents - tags: - - Fine-tuning - summary: | - Get status updates for a fine-tuning job. - parameters: - - in: path - name: fine_tuning_job_id - required: true - schema: - type: string - example: ft-AF1WoRqd3aJAHsqc9NY7iL8F - description: | - The ID of the fine-tuning job to get events for. - - name: after - in: query - description: Identifier for the last event from the previous pagination request. - required: false - schema: - type: string - - name: limit - in: query - description: Number of events to retrieve. - required: false - schema: - type: integer - default: 20 - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ListFineTuningJobEventsResponse" - x-oaiMeta: - name: List fine-tuning events - group: fine-tuning - returns: A list of fine-tuning event objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/fine_tuning/jobs/ftjob-abc123/events \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - from openai import OpenAI - client = OpenAI() - - client.fine_tuning.jobs.list_events( - fine_tuning_job_id="ftjob-abc123", - limit=2 - ) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const list = await openai.fineTuning.list_events(id="ftjob-abc123", limit=2); - - for await (const fineTune of list) { - console.log(fineTune); - } - } + event: thread.message.created + data: {"id":"msg_001","object":"thread.message","created_at":1710348076,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"in_progress","incomplete_details":null,"incomplete_at":null,"completed_at":null,"role":"assistant","content":[], "metadata":{}} - main(); - response: | - { - "object": "list", - "data": [ - { - "object": "fine_tuning.job.event", - "id": "ft-event-ddTJfwuMVpfLXseO0Am0Gqjm", - "created_at": 1692407401, - "level": "info", - "message": "Fine tuning job successfully completed", - "data": null, - "type": "message" + event: thread.message.in_progress + data: {"id":"msg_001","object":"thread.message","created_at":1710348076,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"in_progress","incomplete_details":null,"incomplete_at":null,"completed_at":null,"role":"assistant","content":[], "metadata":{}} + + event: thread.message.delta + data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":"Hello","annotations":[]}}]}} + + ... + + event: thread.message.delta + data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":" today"}}]}} + + event: thread.message.delta + data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":"?"}}]}} + + event: thread.message.completed + data: {"id":"msg_001","object":"thread.message","created_at":1710348076,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"completed","incomplete_details":null,"incomplete_at":null,"completed_at":1710348077,"role":"assistant","content":[{"type":"text","text":{"value":"Hello! How can I assist you today?","annotations":[]}}], "metadata":{}} + + event: thread.run.step.completed + data: {"id":"step_001","object":"thread.run.step","created_at":1710348076,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"completed","cancelled_at":null,"completed_at":1710348077,"expires_at":1710348675,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":{"prompt_tokens":20,"completion_tokens":11,"total_tokens":31}} + + event: thread.run.completed + {"id":"run_123","object":"thread.run","created_at":1710348076,"assistant_id":"asst_123","thread_id":"thread_123","status":"completed","started_at":1713226836,"expires_at":null,"cancelled_at":null,"failed_at":null,"completed_at":1713226837,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":{"prompt_tokens":345,"completion_tokens":11,"total_tokens":356},"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true} + + event: done + data: [DONE] + - title: Streaming with Functions + request: + curl: | + curl https://api.openai.com/v1/threads/runs \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "assistant_id": "asst_abc123", + "thread": { + "messages": [ + {"role": "user", "content": "What is the weather like in San Francisco?"} + ] + }, + "tools": [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA" }, - { - "object": "fine_tuning.job.event", - "id": "ft-event-tyiGuB72evQncpH87xe505Sv", - "created_at": 1692407400, - "level": "info", - "message": "New fine-tuned model created: ft:gpt-3.5-turbo:openai::7p4lURel", - "data": null, - "type": "message" - } - ], - "has_more": true - } - /fine_tuning/jobs/{fine_tuning_job_id}/cancel: - post: - operationId: cancelFineTuningJob - tags: - - Fine-tuning - summary: | - Immediately cancel a fine-tune job. - parameters: - - in: path - name: fine_tuning_job_id - required: true - schema: - type: string - example: ft-AF1WoRqd3aJAHsqc9NY7iL8F - description: | - The ID of the fine-tuning job to cancel. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/FineTuningJob" - x-oaiMeta: - name: Cancel fine-tuning - group: fine-tuning - returns: The cancelled [fine-tuning](/docs/api-reference/fine-tuning/object) object. - examples: - request: - curl: | - curl -X POST https://api.openai.com/v1/fine_tuning/jobs/ftjob-abc123/cancel \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - from openai import OpenAI - client = OpenAI() - - client.fine_tuning.jobs.cancel("ftjob-abc123") - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const fineTune = await openai.fineTuning.jobs.cancel("ftjob-abc123"); - - console.log(fineTune); + "unit": { + "type": "string", + "enum": ["celsius", "fahrenheit"] } - main(); - response: | - { - "object": "fine_tuning.job", - "id": "ftjob-abc123", - "model": "gpt-3.5-turbo-0125", - "created_at": 1689376978, - "fine_tuned_model": null, - "organization_id": "org-123", - "result_files": [], - "hyperparameters": { - "n_epochs": "auto" }, - "status": "cancelled", - "validation_file": "file-abc123", - "training_file": "file-abc123" - } - /fine_tuning/jobs/{fine_tuning_job_id}/checkpoints: - get: - operationId: listFineTuningJobCheckpoints - tags: - - Fine-tuning - summary: | - List checkpoints for a fine-tuning job. - parameters: - - in: path - name: fine_tuning_job_id - required: true - schema: - type: string - example: ft-AF1WoRqd3aJAHsqc9NY7iL8F - description: | - The ID of the fine-tuning job to get checkpoints for. - - name: after - in: query - description: Identifier for the last checkpoint ID from the previous pagination request. - required: false - schema: - type: string - - name: limit - in: query - description: Number of checkpoints to retrieve. - required: false - schema: - type: integer - default: 10 - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ListFineTuningJobCheckpointsResponse" - x-oaiMeta: - name: List fine-tuning checkpoints - group: fine-tuning - returns: A list of fine-tuning [checkpoint objects](/docs/api-reference/fine-tuning/checkpoint-object) for a fine-tuning job. - examples: - request: - curl: | - curl https://api.openai.com/v1/fine_tuning/jobs/ftjob-abc123/checkpoints \ - -H "Authorization: Bearer $OPENAI_API_KEY" - response: | - { - "object": "list" - "data": [ - { - "object": "fine_tuning.job.checkpoint", - "id": "ftckpt_zc4Q7MP6XxulcVzj4MZdwsAB", - "created_at": 1519129973, - "fine_tuned_model_checkpoint": "ft:gpt-3.5-turbo-0125:my-org:custom-suffix:96olL566:ckpt-step-2000", - "metrics": { - "full_valid_loss": 0.134, - "full_valid_mean_token_accuracy": 0.874 - }, - "fine_tuning_job_id": "ftjob-abc123", - "step_number": 2000, - }, - { - "object": "fine_tuning.job.checkpoint", - "id": "ftckpt_enQCFmOTGj3syEpYVhBRLTSy", - "created_at": 1519129833, - "fine_tuned_model_checkpoint": "ft:gpt-3.5-turbo-0125:my-org:custom-suffix:7q8mpxmy:ckpt-step-1000", - "metrics": { - "full_valid_loss": 0.167, - "full_valid_mean_token_accuracy": 0.781 - }, - "fine_tuning_job_id": "ftjob-abc123", - "step_number": 1000, - }, - ], - "first_id": "ftckpt_zc4Q7MP6XxulcVzj4MZdwsAB", - "last_id": "ftckpt_enQCFmOTGj3syEpYVhBRLTSy", - "has_more": true + "required": ["location"] } + } + } + ], + "stream": true + }' + python: | + from openai import OpenAI + client = OpenAI() + + tools = [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA", + }, + "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, + }, + "required": ["location"], + }, + } + } + ] - /models: - get: - operationId: listModels - tags: - - Models - summary: Lists the currently available models, and provides basic information about each one such as the owner and availability. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ListModelsResponse" - x-oaiMeta: - name: List models - group: models - returns: A list of [model](/docs/api-reference/models/object) objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/models \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - from openai import OpenAI - client = OpenAI() - - client.models.list() - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const list = await openai.models.list(); - - for await (const model of list) { - console.log(model); - } - } - main(); - response: | - { - "object": "list", - "data": [ - { - "id": "model-id-0", - "object": "model", - "created": 1686935002, - "owned_by": "organization-owner" - }, - { - "id": "model-id-1", - "object": "model", - "created": 1686935002, - "owned_by": "organization-owner", - }, - { - "id": "model-id-2", - "object": "model", - "created": 1686935002, - "owned_by": "openai" - }, - ], - "object": "list" - } - /models/{model}: - get: - operationId: retrieveModel - tags: - - Models - summary: Retrieves a model instance, providing basic information about the model such as the owner and permissioning. - parameters: - - in: path - name: model - required: true - schema: - type: string - # ideally this will be an actual ID, so this will always work from browser - example: gpt-3.5-turbo - description: The ID of the model to use for this request - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/Model" - x-oaiMeta: - name: Retrieve model - group: models - returns: The [model](/docs/api-reference/models/object) object matching the specified ID. - examples: - request: - curl: | - curl https://api.openai.com/v1/models/VAR_model_id \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - from openai import OpenAI - client = OpenAI() - - client.models.retrieve("VAR_model_id") - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const model = await openai.models.retrieve("VAR_model_id"); - - console.log(model); - } - - main(); - response: &retrieve_model_response | - { - "id": "VAR_model_id", - "object": "model", - "created": 1686935002, - "owned_by": "openai" - } - delete: - operationId: deleteModel - tags: - - Models - summary: Delete a fine-tuned model. You must have the Owner role in your organization to delete a model. - parameters: - - in: path - name: model - required: true - schema: - type: string - example: ft:gpt-3.5-turbo:acemeco:suffix:abc123 - description: The model to delete - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/DeleteModelResponse" - x-oaiMeta: - name: Delete a fine-tuned model - group: models - returns: Deletion status. - examples: - request: - curl: | - curl https://api.openai.com/v1/models/ft:gpt-3.5-turbo:acemeco:suffix:abc123 \ - -X DELETE \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - from openai import OpenAI - client = OpenAI() - - client.models.delete("ft:gpt-3.5-turbo:acemeco:suffix:abc123") - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const model = await openai.models.del("ft:gpt-3.5-turbo:acemeco:suffix:abc123"); - - console.log(model); - } - main(); - response: | - { - "id": "ft:gpt-3.5-turbo:acemeco:suffix:abc123", - "object": "model", - "deleted": true - } + stream = client.beta.threads.create_and_run( + thread={ + "messages": [ + {"role": "user", "content": "What is the weather like in San Francisco?"} + ] + }, + assistant_id="asst_abc123", + tools=tools, + stream=True + ) - /moderations: - post: - operationId: createModeration - tags: - - Moderations - summary: Classifies if text is potentially harmful. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateModerationRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/CreateModerationResponse" - x-oaiMeta: - name: Create moderation - group: moderations - returns: A [moderation](/docs/api-reference/moderations/object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/moderations \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "input": "I want to kill them." - }' - python: | - from openai import OpenAI - client = OpenAI() - - moderation = client.moderations.create(input="I want to kill them.") - print(moderation) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const moderation = await openai.moderations.create({ input: "I want to kill them." }); - - console.log(moderation); - } - main(); - response: &moderation_example | - { - "id": "modr-XXXXX", - "model": "text-moderation-005", - "results": [ - { - "flagged": true, - "categories": { - "sexual": false, - "hate": false, - "harassment": false, - "self-harm": false, - "sexual/minors": false, - "hate/threatening": false, - "violence/graphic": false, - "self-harm/intent": false, - "self-harm/instructions": false, - "harassment/threatening": true, - "violence": true, - }, - "category_scores": { - "sexual": 1.2282071e-06, - "hate": 0.010696256, - "harassment": 0.29842457, - "self-harm": 1.5236925e-08, - "sexual/minors": 5.7246268e-08, - "hate/threatening": 0.0060676364, - "violence/graphic": 4.435014e-06, - "self-harm/intent": 8.098441e-10, - "self-harm/instructions": 2.8498655e-11, - "harassment/threatening": 0.63055265, - "violence": 0.99011886, - } - } - ] - } + for event in stream: + print(event) + node.js: | + import OpenAI from "openai"; - /assistants: - get: - operationId: listAssistants - tags: - - Assistants - summary: Returns a list of assistants. - parameters: - - name: limit - in: query - description: &pagination_limit_param_description | - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - required: false - schema: - type: integer - default: 20 - - name: order - in: query - description: &pagination_order_param_description | - Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. - schema: - type: string - default: desc - enum: ["asc", "desc"] - - name: after - in: query - description: &pagination_after_param_description | - A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - schema: - type: string - - name: before - in: query - description: &pagination_before_param_description | - A cursor for use in pagination. `before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. - schema: - type: string - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ListAssistantsResponse" - x-oaiMeta: - name: List assistants - group: assistants - beta: true - returns: A list of [assistant](/docs/api-reference/assistants/object) objects. - examples: - request: - curl: | - curl "https://api.openai.com/v1/assistants?order=desc&limit=20" \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" - python: | - from openai import OpenAI - client = OpenAI() - - my_assistants = client.beta.assistants.list( - order="desc", - limit="20", - ) - print(my_assistants.data) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const myAssistants = await openai.beta.assistants.list({ - order: "desc", - limit: "20", - }); - - console.log(myAssistants.data); - } + const openai = new OpenAI(); - main(); - response: &list_assistants_example | - { - "object": "list", - "data": [ - { - "id": "asst_abc123", - "object": "assistant", - "created_at": 1698982736, - "name": "Coding Tutor", - "description": null, - "model": "gpt-4-turbo", - "instructions": "You are a helpful assistant designed to make me better at coding!", - "tools": [], - "tool_resources": {}, - "metadata": {}, - "top_p": 1.0, - "temperature": 1.0, - "response_format": "auto" - }, - { - "id": "asst_abc456", - "object": "assistant", - "created_at": 1698982718, - "name": "My Assistant", - "description": null, - "model": "gpt-4-turbo", - "instructions": "You are a helpful assistant designed to make me better at coding!", - "tools": [], - "tool_resources": {}, - "metadata": {}, - "top_p": 1.0, - "temperature": 1.0, - "response_format": "auto" - }, - { - "id": "asst_abc789", - "object": "assistant", - "created_at": 1698982643, - "name": null, - "description": null, - "model": "gpt-4-turbo", - "instructions": null, - "tools": [], - "tool_resources": {}, - "metadata": {}, - "top_p": 1.0, - "temperature": 1.0, - "response_format": "auto" - } - ], - "first_id": "asst_abc123", - "last_id": "asst_abc789", - "has_more": false - } - post: - operationId: createAssistant - tags: - - Assistants - summary: Create an assistant with a model and instructions. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateAssistantRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/AssistantObject" - x-oaiMeta: - name: Create assistant - group: assistants - beta: true - returns: An [assistant](/docs/api-reference/assistants/object) object. - examples: - - title: Code Interpreter - request: - curl: | - curl "https://api.openai.com/v1/assistants" \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.", - "name": "Math Tutor", - "tools": [{"type": "code_interpreter"}], - "model": "gpt-4-turbo" - }' - - python: | - from openai import OpenAI - client = OpenAI() - - my_assistant = client.beta.assistants.create( - instructions="You are a personal math tutor. When asked a question, write and run Python code to answer the question.", - name="Math Tutor", - tools=[{"type": "code_interpreter"}], - model="gpt-4-turbo", - ) - print(my_assistant) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const myAssistant = await openai.beta.assistants.create({ - instructions: - "You are a personal math tutor. When asked a question, write and run Python code to answer the question.", - name: "Math Tutor", - tools: [{ type: "code_interpreter" }], - model: "gpt-4-turbo", - }); - - console.log(myAssistant); - } - - main(); - response: &create_assistants_example | - { - "id": "asst_abc123", - "object": "assistant", - "created_at": 1698984975, - "name": "Math Tutor", - "description": null, - "model": "gpt-4-turbo", - "instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.", - "tools": [ - { - "type": "code_interpreter" - } - ], - "metadata": {}, - "top_p": 1.0, - "temperature": 1.0, - "response_format": "auto" - } - - title: Files - request: - curl: | - curl https://api.openai.com/v1/assistants \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies.", - "tools": [{"type": "file_search"}], - "tool_resources": {"file_search": {"vector_store_ids": ["vs_123"]}}, - "model": "gpt-4-turbo" - }' - python: | - from openai import OpenAI - client = OpenAI() - - my_assistant = client.beta.assistants.create( - instructions="You are an HR bot, and you have access to files to answer employee questions about company policies.", - name="HR Helper", - tools=[{"type": "file_search"}], - tool_resources={"file_search": {"vector_store_ids": ["vs_123"]}}, - model="gpt-4-turbo" - ) - print(my_assistant) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const myAssistant = await openai.beta.assistants.create({ - instructions: - "You are an HR bot, and you have access to files to answer employee questions about company policies.", - name: "HR Helper", - tools: [{ type: "file_search" }], - tool_resources: { - file_search: { - vector_store_ids: ["vs_123"] - } - }, - model: "gpt-4-turbo" - }); - - console.log(myAssistant); - } - - main(); - response: | - { - "id": "asst_abc123", - "object": "assistant", - "created_at": 1699009403, - "name": "HR Helper", - "description": null, - "model": "gpt-4-turbo", - "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies.", - "tools": [ - { - "type": "file_search" - } - ], - "tool_resources": { - "file_search": { - "vector_store_ids": ["vs_123"] - } + const tools = [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA", + }, + "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, + }, + "required": ["location"], + }, + } + } + ]; + + async function main() { + const stream = await openai.beta.threads.createAndRun({ + assistant_id: "asst_123", + thread: { + messages: [ + { role: "user", content: "What is the weather like in San Francisco?" }, + ], + }, + tools: tools, + stream: true + }); + + for await (const event of stream) { + console.log(event); + } + } + + main(); + response: | + event: thread.created + data: {"id":"thread_123","object":"thread","created_at":1710351818,"metadata":{}} + + event: thread.run.created + data: {"id":"run_123","object":"thread.run","created_at":1710351818,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710352418,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} + + event: thread.run.queued + data: {"id":"run_123","object":"thread.run","created_at":1710351818,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710352418,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} + + event: thread.run.in_progress + data: {"id":"run_123","object":"thread.run","created_at":1710351818,"assistant_id":"asst_123","thread_id":"thread_123","status":"in_progress","started_at":1710351818,"expires_at":1710352418,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} + + event: thread.run.step.created + data: {"id":"step_001","object":"thread.run.step","created_at":1710351819,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"tool_calls","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710352418,"failed_at":null,"last_error":null,"step_details":{"type":"tool_calls","tool_calls":[]},"usage":null} + + event: thread.run.step.in_progress + data: {"id":"step_001","object":"thread.run.step","created_at":1710351819,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"tool_calls","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710352418,"failed_at":null,"last_error":null,"step_details":{"type":"tool_calls","tool_calls":[]},"usage":null} + + event: thread.run.step.delta + data: {"id":"step_001","object":"thread.run.step.delta","delta":{"step_details":{"type":"tool_calls","tool_calls":[{"index":0,"id":"call_XXNp8YGaFrjrSjgqxtC8JJ1B","type":"function","function":{"name":"get_current_weather","arguments":"","output":null}}]}}} + + event: thread.run.step.delta + data: {"id":"step_001","object":"thread.run.step.delta","delta":{"step_details":{"type":"tool_calls","tool_calls":[{"index":0,"type":"function","function":{"arguments":"{\""}}]}}} + + event: thread.run.step.delta + data: {"id":"step_001","object":"thread.run.step.delta","delta":{"step_details":{"type":"tool_calls","tool_calls":[{"index":0,"type":"function","function":{"arguments":"location"}}]}}} + + ... + + event: thread.run.step.delta + data: {"id":"step_001","object":"thread.run.step.delta","delta":{"step_details":{"type":"tool_calls","tool_calls":[{"index":0,"type":"function","function":{"arguments":"ahrenheit"}}]}}} + + event: thread.run.step.delta + data: {"id":"step_001","object":"thread.run.step.delta","delta":{"step_details":{"type":"tool_calls","tool_calls":[{"index":0,"type":"function","function":{"arguments":"\"}"}}]}}} + + event: thread.run.requires_action + data: {"id":"run_123","object":"thread.run","created_at":1710351818,"assistant_id":"asst_123","thread_id":"thread_123","status":"requires_action","started_at":1710351818,"expires_at":1710352418,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":{"type":"submit_tool_outputs","submit_tool_outputs":{"tool_calls":[{"id":"call_XXNp8YGaFrjrSjgqxtC8JJ1B","type":"function","function":{"name":"get_current_weather","arguments":"{\"location\":\"San Francisco, CA\",\"unit\":\"fahrenheit\"}"}}]}},"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":{"prompt_tokens":345,"completion_tokens":11,"total_tokens":356},"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} + + event: done + data: [DONE] + /threads/{threadId}/runs: + get: + tags: + - Assistants + summary: Returns a list of runs belonging to a thread. + operationId: listRuns + parameters: + - name: threadId + in: path + description: The ID of the thread the run belongs to + required: true + style: simple + explode: false + schema: + type: string + - name: limit + in: query + description: | + A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20 + required: false + style: form + explode: true + schema: + type: integer + default: 20 + - name: order + in: query + description: | + Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order + required: false + style: form + explode: true + schema: + type: string + default: desc + enum: + - asc + - desc + - name: after + in: query + description: | + A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list + required: false + style: form + explode: true + schema: + type: string + - name: before + in: query + description: | + A cursor for use in pagination. `before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list + required: false + style: form + explode: true + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ListRunsResponse' + x-oaiMeta: + name: List runs + group: threads + beta: true + returns: "A list of [run](/docs/api-reference/runs/object) objects." + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" + python: | + from openai import OpenAI + client = OpenAI() + + runs = client.beta.threads.runs.list( + "thread_abc123" + ) + + print(runs) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const runs = await openai.beta.threads.runs.list( + "thread_abc123" + ); + + console.log(runs); + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "run_abc123", + "object": "thread.run", + "created_at": 1699075072, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "completed", + "started_at": 1699075072, + "expires_at": null, + "cancelled_at": null, + "failed_at": null, + "completed_at": 1699075073, + "last_error": null, + "model": "gpt-4-turbo", + "instructions": null, + "incomplete_details": null, + "tools": [ + { + "type": "code_interpreter" + } + ], + "tool_resources": { + "code_interpreter": { + "file_ids": [ + "file-abc123", + "file-abc456" + ] + } + }, + "metadata": {}, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + }, + "temperature": 1.0, + "top_p": 1.0, + "max_prompt_tokens": 1000, + "max_completion_tokens": 1000, + "truncation_strategy": { + "type": "auto", + "last_messages": null + }, + "response_format": "auto", + "tool_choice": "auto", + "parallel_tool_calls": true + }, + { + "id": "run_abc456", + "object": "thread.run", + "created_at": 1699063290, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "completed", + "started_at": 1699063290, + "expires_at": null, + "cancelled_at": null, + "failed_at": null, + "completed_at": 1699063291, + "last_error": null, + "model": "gpt-4-turbo", + "instructions": null, + "incomplete_details": null, + "tools": [ + { + "type": "code_interpreter" + } + ], + "tool_resources": { + "code_interpreter": { + "file_ids": [ + "file-abc123", + "file-abc456" + ] + } + }, + "metadata": {}, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + }, + "temperature": 1.0, + "top_p": 1.0, + "max_prompt_tokens": 1000, + "max_completion_tokens": 1000, + "truncation_strategy": { + "type": "auto", + "last_messages": null + }, + "response_format": "auto", + "tool_choice": "auto", + "parallel_tool_calls": true + } + ], + "first_id": "run_abc123", + "last_id": "run_abc456", + "has_more": false + } + post: + tags: + - Assistants + summary: Create a run. + operationId: createRun + parameters: + - name: threadId + in: path + description: The ID of the thread to run + required: true + style: simple + explode: false + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateRunRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/RunObject' + x-oaiMeta: + name: Create run + group: threads + beta: true + returns: "A [run](/docs/api-reference/runs/object) object." + examples: + - title: Default + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "assistant_id": "asst_abc123" + }' + python: | + from openai import OpenAI + client = OpenAI() + + run = client.beta.threads.runs.create( + thread_id="thread_abc123", + assistant_id="asst_abc123" + ) + + print(run) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const run = await openai.beta.threads.runs.create( + "thread_abc123", + { assistant_id: "asst_abc123" } + ); + + console.log(run); + } + + main(); + response: | + { + "id": "run_abc123", + "object": "thread.run", + "created_at": 1699063290, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "queued", + "started_at": 1699063290, + "expires_at": null, + "cancelled_at": null, + "failed_at": null, + "completed_at": 1699063291, + "last_error": null, + "model": "gpt-4-turbo", + "instructions": null, + "incomplete_details": null, + "tools": [ + { + "type": "code_interpreter" + } + ], + "metadata": {}, + "usage": null, + "temperature": 1.0, + "top_p": 1.0, + "max_prompt_tokens": 1000, + "max_completion_tokens": 1000, + "truncation_strategy": { + "type": "auto", + "last_messages": null + }, + "response_format": "auto", + "tool_choice": "auto", + "parallel_tool_calls": true + } + - title: Streaming + request: + curl: | + curl https://api.openai.com/v1/threads/thread_123/runs \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "assistant_id": "asst_123", + "stream": true + }' + python: | + from openai import OpenAI + client = OpenAI() + + stream = client.beta.threads.runs.create( + thread_id="thread_123", + assistant_id="asst_123", + stream=True + ) + + for event in stream: + print(event) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const stream = await openai.beta.threads.runs.create( + "thread_123", + { assistant_id: "asst_123", stream: true } + ); + + for await (const event of stream) { + console.log(event); + } + } + + main(); + response: | + event: thread.run.created + data: {"id":"run_123","object":"thread.run","created_at":1710330640,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710331240,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} + + event: thread.run.queued + data: {"id":"run_123","object":"thread.run","created_at":1710330640,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710331240,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} + + event: thread.run.in_progress + data: {"id":"run_123","object":"thread.run","created_at":1710330640,"assistant_id":"asst_123","thread_id":"thread_123","status":"in_progress","started_at":1710330641,"expires_at":1710331240,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} + + event: thread.run.step.created + data: {"id":"step_001","object":"thread.run.step","created_at":1710330641,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710331240,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":null} + + event: thread.run.step.in_progress + data: {"id":"step_001","object":"thread.run.step","created_at":1710330641,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710331240,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":null} + + event: thread.message.created + data: {"id":"msg_001","object":"thread.message","created_at":1710330641,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"in_progress","incomplete_details":null,"incomplete_at":null,"completed_at":null,"role":"assistant","content":[],"metadata":{}} + + event: thread.message.in_progress + data: {"id":"msg_001","object":"thread.message","created_at":1710330641,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"in_progress","incomplete_details":null,"incomplete_at":null,"completed_at":null,"role":"assistant","content":[],"metadata":{}} + + event: thread.message.delta + data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":"Hello","annotations":[]}}]}} + + ... + + event: thread.message.delta + data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":" today"}}]}} + + event: thread.message.delta + data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":"?"}}]}} + + event: thread.message.completed + data: {"id":"msg_001","object":"thread.message","created_at":1710330641,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"completed","incomplete_details":null,"incomplete_at":null,"completed_at":1710330642,"role":"assistant","content":[{"type":"text","text":{"value":"Hello! How can I assist you today?","annotations":[]}}],"metadata":{}} + + event: thread.run.step.completed + data: {"id":"step_001","object":"thread.run.step","created_at":1710330641,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"completed","cancelled_at":null,"completed_at":1710330642,"expires_at":1710331240,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":{"prompt_tokens":20,"completion_tokens":11,"total_tokens":31}} + + event: thread.run.completed + data: {"id":"run_123","object":"thread.run","created_at":1710330640,"assistant_id":"asst_123","thread_id":"thread_123","status":"completed","started_at":1710330641,"expires_at":null,"cancelled_at":null,"failed_at":null,"completed_at":1710330642,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":{"prompt_tokens":20,"completion_tokens":11,"total_tokens":31},"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} + + event: done + data: [DONE] + - title: Streaming with Functions + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "assistant_id": "asst_abc123", + "tools": [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA" }, - "metadata": {}, - "top_p": 1.0, - "temperature": 1.0, - "response_format": "auto" - } - - /assistants/{assistant_id}: - get: - operationId: getAssistant - tags: - - Assistants - summary: Retrieves an assistant. - parameters: - - in: path - name: assistant_id - required: true - schema: - type: string - description: The ID of the assistant to retrieve. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/AssistantObject" - x-oaiMeta: - name: Retrieve assistant - group: assistants - beta: true - returns: The [assistant](/docs/api-reference/assistants/object) object matching the specified ID. - examples: - request: - curl: | - curl https://api.openai.com/v1/assistants/asst_abc123 \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" - python: | - from openai import OpenAI - client = OpenAI() - - my_assistant = client.beta.assistants.retrieve("asst_abc123") - print(my_assistant) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const myAssistant = await openai.beta.assistants.retrieve( - "asst_abc123" - ); - - console.log(myAssistant); - } - - main(); - response: | - { - "id": "asst_abc123", - "object": "assistant", - "created_at": 1699009709, - "name": "HR Helper", - "description": null, - "model": "gpt-4-turbo", - "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies.", - "tools": [ - { - "type": "file_search" - } - ], - "metadata": {}, - "top_p": 1.0, - "temperature": 1.0, - "response_format": "auto" - } - post: - operationId: modifyAssistant - tags: - - Assistants - summary: Modifies an assistant. - parameters: - - in: path - name: assistant_id - required: true - schema: - type: string - description: The ID of the assistant to modify. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/ModifyAssistantRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/AssistantObject" - x-oaiMeta: - name: Modify assistant - group: assistants - beta: true - returns: The modified [assistant](/docs/api-reference/assistants/object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/assistants/asst_abc123 \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies. Always response with info from either of the files.", - "tools": [{"type": "file_search"}], - "model": "gpt-4-turbo" - }' - python: | - from openai import OpenAI - client = OpenAI() - - my_updated_assistant = client.beta.assistants.update( - "asst_abc123", - instructions="You are an HR bot, and you have access to files to answer employee questions about company policies. Always response with info from either of the files.", - name="HR Helper", - tools=[{"type": "file_search"}], - model="gpt-4-turbo" - ) - - print(my_updated_assistant) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const myUpdatedAssistant = await openai.beta.assistants.update( - "asst_abc123", - { - instructions: - "You are an HR bot, and you have access to files to answer employee questions about company policies. Always response with info from either of the files.", - name: "HR Helper", - tools: [{ type: "file_search" }], - model: "gpt-4-turbo" - } - ); - - console.log(myUpdatedAssistant); - } - - main(); - response: | - { - "id": "asst_123", - "object": "assistant", - "created_at": 1699009709, - "name": "HR Helper", - "description": null, - "model": "gpt-4-turbo", - "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies. Always response with info from either of the files.", - "tools": [ - { - "type": "file_search" - } - ], - "tool_resources": { - "file_search": { - "vector_store_ids": [] + "unit": { + "type": "string", + "enum": ["celsius", "fahrenheit"] } }, - "metadata": {}, - "top_p": 1.0, - "temperature": 1.0, - "response_format": "auto" - } - delete: - operationId: deleteAssistant - tags: - - Assistants - summary: Delete an assistant. - parameters: - - in: path - name: assistant_id - required: true - schema: - type: string - description: The ID of the assistant to delete. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/DeleteAssistantResponse" - x-oaiMeta: - name: Delete assistant - group: assistants - beta: true - returns: Deletion status - examples: - request: - curl: | - curl https://api.openai.com/v1/assistants/asst_abc123 \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" \ - -X DELETE - python: | - from openai import OpenAI - client = OpenAI() - - response = client.beta.assistants.delete("asst_abc123") - print(response) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const response = await openai.beta.assistants.del("asst_abc123"); - - console.log(response); - } - main(); - response: | - { - "id": "asst_abc123", - "object": "assistant.deleted", - "deleted": true + "required": ["location"] } + } + } + ], + "stream": true + }' + python: | + from openai import OpenAI + client = OpenAI() + + tools = [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA", + }, + "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, + }, + "required": ["location"], + }, + } + } + ] - /threads: - post: - operationId: createThread - tags: - - Assistants - summary: Create a thread. - requestBody: - content: - application/json: - schema: - $ref: "#/components/schemas/CreateThreadRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ThreadObject" - x-oaiMeta: - name: Create thread - group: threads - beta: true - returns: A [thread](/docs/api-reference/threads) object. - examples: - - title: Empty - request: - curl: | - curl https://api.openai.com/v1/threads \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '' - python: | - from openai import OpenAI - client = OpenAI() - - empty_thread = client.beta.threads.create() - print(empty_thread) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const emptyThread = await openai.beta.threads.create(); - - console.log(emptyThread); - } - - main(); - response: | - { - "id": "thread_abc123", - "object": "thread", - "created_at": 1699012949, - "metadata": {}, - "tool_resources": {} - } - - title: Messages - request: - curl: | - curl https://api.openai.com/v1/threads \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "messages": [{ - "role": "user", - "content": "Hello, what is AI?" - }, { - "role": "user", - "content": "How does AI work? Explain it in simple terms." - }] - }' - python: | - from openai import OpenAI - client = OpenAI() - - message_thread = client.beta.threads.create( - messages=[ - { - "role": "user", - "content": "Hello, what is AI?" - }, - { - "role": "user", - "content": "How does AI work? Explain it in simple terms." - }, - ] - ) - - print(message_thread) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const messageThread = await openai.beta.threads.create({ - messages: [ - { - role: "user", - content: "Hello, what is AI?" - }, - { - role: "user", - content: "How does AI work? Explain it in simple terms.", - }, - ], - }); - - console.log(messageThread); - } - - main(); - response: | - { - "id": "thread_abc123", - "object": "thread", - "created_at": 1699014083, - "metadata": {}, - "tool_resources": {} - } + stream = client.beta.threads.runs.create( + thread_id="thread_abc123", + assistant_id="asst_abc123", + tools=tools, + stream=True + ) - /threads/{thread_id}: - get: - operationId: getThread - tags: - - Assistants - summary: Retrieves a thread. - parameters: - - in: path - name: thread_id - required: true - schema: - type: string - description: The ID of the thread to retrieve. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ThreadObject" - x-oaiMeta: - name: Retrieve thread - group: threads - beta: true - returns: The [thread](/docs/api-reference/threads/object) object matching the specified ID. - examples: - request: - curl: | - curl https://api.openai.com/v1/threads/thread_abc123 \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" - python: | - from openai import OpenAI - client = OpenAI() - - my_thread = client.beta.threads.retrieve("thread_abc123") - print(my_thread) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const myThread = await openai.beta.threads.retrieve( - "thread_abc123" - ); - - console.log(myThread); - } + for event in stream: + print(event) + node.js: | + import OpenAI from "openai"; - main(); - response: | - { - "id": "thread_abc123", - "object": "thread", - "created_at": 1699014083, - "metadata": {}, - "tool_resources": { - "code_interpreter": { - "file_ids": [] - } - } - } - post: - operationId: modifyThread - tags: - - Assistants - summary: Modifies a thread. - parameters: - - in: path - name: thread_id - required: true - schema: - type: string - description: The ID of the thread to modify. Only the `metadata` can be modified. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/ModifyThreadRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ThreadObject" - x-oaiMeta: - name: Modify thread - group: threads - beta: true - returns: The modified [thread](/docs/api-reference/threads/object) object matching the specified ID. - examples: - request: - curl: | - curl https://api.openai.com/v1/threads/thread_abc123 \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "metadata": { - "modified": "true", - "user": "abc123" - } - }' - python: | - from openai import OpenAI - client = OpenAI() - - my_updated_thread = client.beta.threads.update( - "thread_abc123", - metadata={ - "modified": "true", - "user": "abc123" - } - ) - print(my_updated_thread) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const updatedThread = await openai.beta.threads.update( - "thread_abc123", - { - metadata: { modified: "true", user: "abc123" }, - } - ); - - console.log(updatedThread); - } + const openai = new OpenAI(); - main(); - response: | - { - "id": "thread_abc123", - "object": "thread", - "created_at": 1699014083, - "metadata": { - "modified": "true", - "user": "abc123" + const tools = [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA", }, - "tool_resources": {} - } - delete: - operationId: deleteThread - tags: - - Assistants - summary: Delete a thread. - parameters: - - in: path - name: thread_id - required: true - schema: - type: string - description: The ID of the thread to delete. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/DeleteThreadResponse" - x-oaiMeta: - name: Delete thread - group: threads - beta: true - returns: Deletion status - examples: - request: - curl: | - curl https://api.openai.com/v1/threads/thread_abc123 \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" \ - -X DELETE - python: | - from openai import OpenAI - client = OpenAI() - - response = client.beta.threads.delete("thread_abc123") - print(response) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const response = await openai.beta.threads.del("thread_abc123"); - - console.log(response); - } - main(); - response: | - { - "id": "thread_abc123", - "object": "thread.deleted", - "deleted": true - } + "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, + }, + "required": ["location"], + }, + } + } + ]; - /threads/{thread_id}/messages: - get: - operationId: listMessages - tags: - - Assistants - summary: Returns a list of messages for a given thread. - parameters: - - in: path - name: thread_id - required: true - schema: - type: string - description: The ID of the [thread](/docs/api-reference/threads) the messages belong to. - - name: limit - in: query - description: *pagination_limit_param_description - required: false - schema: - type: integer - default: 20 - - name: order - in: query - description: *pagination_order_param_description - schema: - type: string - default: desc - enum: ["asc", "desc"] - - name: after - in: query - description: *pagination_after_param_description - schema: - type: string - - name: before - in: query - description: *pagination_before_param_description - schema: - type: string - - name: run_id - in: query - description: | - Filter messages by the run ID that generated them. - schema: - type: string - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ListMessagesResponse" - x-oaiMeta: - name: List messages - group: threads - beta: true - returns: A list of [message](/docs/api-reference/messages) objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/threads/thread_abc123/messages \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" - python: | - from openai import OpenAI - client = OpenAI() - - thread_messages = client.beta.threads.messages.list("thread_abc123") - print(thread_messages.data) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const threadMessages = await openai.beta.threads.messages.list( - "thread_abc123" - ); - - console.log(threadMessages.data); - } + async function main() { + const stream = await openai.beta.threads.runs.create( + "thread_abc123", + { + assistant_id: "asst_abc123", + tools: tools, + stream: true + } + ); + + for await (const event of stream) { + console.log(event); + } + } + + main(); + response: | + event: thread.run.created + data: {"id":"run_123","object":"thread.run","created_at":1710348075,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710348675,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} + + event: thread.run.queued + data: {"id":"run_123","object":"thread.run","created_at":1710348075,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710348675,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} + + event: thread.run.in_progress + data: {"id":"run_123","object":"thread.run","created_at":1710348075,"assistant_id":"asst_123","thread_id":"thread_123","status":"in_progress","started_at":1710348075,"expires_at":1710348675,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} + + event: thread.run.step.created + data: {"id":"step_001","object":"thread.run.step","created_at":1710348076,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710348675,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":null} + + event: thread.run.step.in_progress + data: {"id":"step_001","object":"thread.run.step","created_at":1710348076,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710348675,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":null} + + event: thread.message.created + data: {"id":"msg_001","object":"thread.message","created_at":1710348076,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"in_progress","incomplete_details":null,"incomplete_at":null,"completed_at":null,"role":"assistant","content":[],"metadata":{}} + + event: thread.message.in_progress + data: {"id":"msg_001","object":"thread.message","created_at":1710348076,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"in_progress","incomplete_details":null,"incomplete_at":null,"completed_at":null,"role":"assistant","content":[],"metadata":{}} + + event: thread.message.delta + data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":"Hello","annotations":[]}}]}} + + ... + + event: thread.message.delta + data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":" today"}}]}} + + event: thread.message.delta + data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":"?"}}]}} + + event: thread.message.completed + data: {"id":"msg_001","object":"thread.message","created_at":1710348076,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"completed","incomplete_details":null,"incomplete_at":null,"completed_at":1710348077,"role":"assistant","content":[{"type":"text","text":{"value":"Hello! How can I assist you today?","annotations":[]}}],"metadata":{}} + + event: thread.run.step.completed + data: {"id":"step_001","object":"thread.run.step","created_at":1710348076,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"completed","cancelled_at":null,"completed_at":1710348077,"expires_at":1710348675,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":{"prompt_tokens":20,"completion_tokens":11,"total_tokens":31}} + + event: thread.run.completed + data: {"id":"run_123","object":"thread.run","created_at":1710348075,"assistant_id":"asst_123","thread_id":"thread_123","status":"completed","started_at":1710348075,"expires_at":null,"cancelled_at":null,"failed_at":null,"completed_at":1710348077,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":{"prompt_tokens":20,"completion_tokens":11,"total_tokens":31},"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} + + event: done + data: [DONE] + /threads/{threadId}/runs/{runId}: + get: + tags: + - Assistants + summary: Retrieves a run. + operationId: getRun + parameters: + - name: threadId + in: path + description: "The ID of the [thread](/docs/api-reference/threads) that was\ + \ run" + required: true + style: simple + explode: false + schema: + type: string + - name: runId + in: path + description: The ID of the run to retrieve + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/RunObject' + x-oaiMeta: + name: Retrieve run + group: threads + beta: true + returns: "The [run](/docs/api-reference/runs/object) object matching the specified\ + \ ID." + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" + python: | + from openai import OpenAI + client = OpenAI() + + run = client.beta.threads.runs.retrieve( + thread_id="thread_abc123", + run_id="run_abc123" + ) + + print(run) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const run = await openai.beta.threads.runs.retrieve( + "thread_abc123", + "run_abc123" + ); + + console.log(run); + } + + main(); + response: | + { + "id": "run_abc123", + "object": "thread.run", + "created_at": 1699075072, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "completed", + "started_at": 1699075072, + "expires_at": null, + "cancelled_at": null, + "failed_at": null, + "completed_at": 1699075073, + "last_error": null, + "model": "gpt-4-turbo", + "instructions": null, + "incomplete_details": null, + "tools": [ + { + "type": "code_interpreter" + } + ], + "metadata": {}, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + }, + "temperature": 1.0, + "top_p": 1.0, + "max_prompt_tokens": 1000, + "max_completion_tokens": 1000, + "truncation_strategy": { + "type": "auto", + "last_messages": null + }, + "response_format": "auto", + "tool_choice": "auto", + "parallel_tool_calls": true + } + post: + tags: + - Assistants + summary: Modifies a run. + operationId: modifyRun + parameters: + - name: threadId + in: path + description: "The ID of the [thread](/docs/api-reference/threads) that was\ + \ run" + required: true + style: simple + explode: false + schema: + type: string + - name: runId + in: path + description: The ID of the run to modify + required: true + style: simple + explode: false + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ModifyRunRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/RunObject' + x-oaiMeta: + name: Modify run + group: threads + beta: true + returns: "The modified [run](/docs/api-reference/runs/object) object matching\ + \ the specified ID." + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "metadata": { + "user_id": "user_abc123" + } + }' + python: | + from openai import OpenAI + client = OpenAI() + + run = client.beta.threads.runs.update( + thread_id="thread_abc123", + run_id="run_abc123", + metadata={"user_id": "user_abc123"}, + ) + + print(run) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const run = await openai.beta.threads.runs.update( + "thread_abc123", + "run_abc123", + { + metadata: { + user_id: "user_abc123", + }, + } + ); + + console.log(run); + } + + main(); + response: | + { + "id": "run_abc123", + "object": "thread.run", + "created_at": 1699075072, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "completed", + "started_at": 1699075072, + "expires_at": null, + "cancelled_at": null, + "failed_at": null, + "completed_at": 1699075073, + "last_error": null, + "model": "gpt-4-turbo", + "instructions": null, + "incomplete_details": null, + "tools": [ + { + "type": "code_interpreter" + } + ], + "tool_resources": { + "code_interpreter": { + "file_ids": [ + "file-abc123", + "file-abc456" + ] + } + }, + "metadata": { + "user_id": "user_abc123" + }, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + }, + "temperature": 1.0, + "top_p": 1.0, + "max_prompt_tokens": 1000, + "max_completion_tokens": 1000, + "truncation_strategy": { + "type": "auto", + "last_messages": null + }, + "response_format": "auto", + "tool_choice": "auto", + "parallel_tool_calls": true + } + /threads/{threadId}/runs/{runId}/submit_tool_outputs: + post: + tags: + - Assistants + summary: | + When a run has the `status: "requires_action"` and `required_action.type` is `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request. + operationId: submitToolOuputsToRun + parameters: + - name: threadId + in: path + description: "The ID of the [thread](/docs/api-reference/threads) to which\ + \ this run belongs" + required: true + style: simple + explode: false + schema: + type: string + - name: runId + in: path + description: The ID of the run that requires the tool output submission + required: true + style: simple + explode: false + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/SubmitToolOutputsRunRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/RunObject' + x-oaiMeta: + name: Submit tool outputs to run + group: threads + beta: true + returns: "The modified [run](/docs/api-reference/runs/object) object matching\ + \ the specified ID." + examples: + - title: Default + request: + curl: | + curl https://api.openai.com/v1/threads/thread_123/runs/run_123/submit_tool_outputs \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "tool_outputs": [ + { + "tool_call_id": "call_001", + "output": "70 degrees and sunny." + } + ] + }' + python: | + from openai import OpenAI + client = OpenAI() + + run = client.beta.threads.runs.submit_tool_outputs( + thread_id="thread_123", + run_id="run_123", + tool_outputs=[ + { + "tool_call_id": "call_001", + "output": "70 degrees and sunny." + } + ] + ) - main(); - response: | - { - "object": "list", - "data": [ - { - "id": "msg_abc123", - "object": "thread.message", - "created_at": 1699016383, - "assistant_id": null, - "thread_id": "thread_abc123", - "run_id": null, - "role": "user", - "content": [ - { - "type": "text", - "text": { - "value": "How does AI work? Explain it in simple terms.", - "annotations": [] - } - } - ], - "attachments": [], - "metadata": {} - }, - { - "id": "msg_abc456", - "object": "thread.message", - "created_at": 1699016383, - "assistant_id": null, - "thread_id": "thread_abc123", - "run_id": null, - "role": "user", - "content": [ - { - "type": "text", - "text": { - "value": "Hello, what is AI?", - "annotations": [] - } - } - ], - "attachments": [], - "metadata": {} - } - ], - "first_id": "msg_abc123", - "last_id": "msg_abc456", - "has_more": false - } - post: - operationId: createMessage - tags: - - Assistants - summary: Create a message. - parameters: - - in: path - name: thread_id - required: true - schema: - type: string - description: The ID of the [thread](/docs/api-reference/threads) to create a message for. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateMessageRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/MessageObject" - x-oaiMeta: - name: Create message - group: threads - beta: true - returns: A [message](/docs/api-reference/messages/object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/threads/thread_abc123/messages \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "role": "user", - "content": "How does AI work? Explain it in simple terms." - }' - python: | - from openai import OpenAI - client = OpenAI() - - thread_message = client.beta.threads.messages.create( - "thread_abc123", - role="user", - content="How does AI work? Explain it in simple terms.", - ) - print(thread_message) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const threadMessages = await openai.beta.threads.messages.create( - "thread_abc123", - { role: "user", content: "How does AI work? Explain it in simple terms." } - ); - - console.log(threadMessages); - } + print(run) + node.js: | + import OpenAI from "openai"; - main(); - response: | - { - "id": "msg_abc123", - "object": "thread.message", - "created_at": 1713226573, - "assistant_id": null, - "thread_id": "thread_abc123", - "run_id": null, - "role": "user", - "content": [ - { - "type": "text", - "text": { - "value": "How does AI work? Explain it in simple terms.", - "annotations": [] - } - } - ], - "attachments": [], - "metadata": {} + const openai = new OpenAI(); + + async function main() { + const run = await openai.beta.threads.runs.submitToolOutputs( + "thread_123", + "run_123", + { + tool_outputs: [ + { + tool_call_id: "call_001", + output: "70 degrees and sunny.", + }, + ], + } + ); + + console.log(run); + } + + main(); + response: | + { + "id": "run_123", + "object": "thread.run", + "created_at": 1699075592, + "assistant_id": "asst_123", + "thread_id": "thread_123", + "status": "queued", + "started_at": 1699075592, + "expires_at": 1699076192, + "cancelled_at": null, + "failed_at": null, + "completed_at": null, + "last_error": null, + "model": "gpt-4-turbo", + "instructions": null, + "tools": [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA" + }, + "unit": { + "type": "string", + "enum": ["celsius", "fahrenheit"] } + }, + "required": ["location"] + } + } + } + ], + "metadata": {}, + "usage": null, + "temperature": 1.0, + "top_p": 1.0, + "max_prompt_tokens": 1000, + "max_completion_tokens": 1000, + "truncation_strategy": { + "type": "auto", + "last_messages": null + }, + "response_format": "auto", + "tool_choice": "auto", + "parallel_tool_calls": true + } + - title: Streaming + request: + curl: | + curl https://api.openai.com/v1/threads/thread_123/runs/run_123/submit_tool_outputs \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "tool_outputs": [ + { + "tool_call_id": "call_001", + "output": "70 degrees and sunny." + } + ], + "stream": true + }' + python: | + from openai import OpenAI + client = OpenAI() + + stream = client.beta.threads.runs.submit_tool_outputs( + thread_id="thread_123", + run_id="run_123", + tool_outputs=[ + { + "tool_call_id": "call_001", + "output": "70 degrees and sunny." + } + ], + stream=True + ) - /threads/{thread_id}/messages/{message_id}: - get: - operationId: getMessage - tags: - - Assistants - summary: Retrieve a message. - parameters: - - in: path - name: thread_id - required: true - schema: - type: string - description: The ID of the [thread](/docs/api-reference/threads) to which this message belongs. - - in: path - name: message_id - required: true - schema: - type: string - description: The ID of the message to retrieve. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/MessageObject" - x-oaiMeta: - name: Retrieve message - group: threads - beta: true - returns: The [message](/docs/api-reference/messages/object) object matching the specified ID. - examples: - request: - curl: | - curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123 \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" - python: | - from openai import OpenAI - client = OpenAI() - - message = client.beta.threads.messages.retrieve( - message_id="msg_abc123", - thread_id="thread_abc123", - ) - print(message) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const message = await openai.beta.threads.messages.retrieve( - "thread_abc123", - "msg_abc123" - ); - - console.log(message); - } + for event in stream: + print(event) + node.js: | + import OpenAI from "openai"; - main(); - response: | - { - "id": "msg_abc123", - "object": "thread.message", - "created_at": 1699017614, - "assistant_id": null, - "thread_id": "thread_abc123", - "run_id": null, - "role": "user", - "content": [ - { - "type": "text", - "text": { - "value": "How does AI work? Explain it in simple terms.", - "annotations": [] - } - } - ], - "attachments": [], - "metadata": {} - } - post: - operationId: modifyMessage - tags: - - Assistants - summary: Modifies a message. - parameters: - - in: path - name: thread_id - required: true - schema: - type: string - description: The ID of the thread to which this message belongs. - - in: path - name: message_id - required: true - schema: - type: string - description: The ID of the message to modify. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/ModifyMessageRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/MessageObject" - x-oaiMeta: - name: Modify message - group: threads - beta: true - returns: The modified [message](/docs/api-reference/messages/object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123 \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "metadata": { - "modified": "true", - "user": "abc123" - } - }' - python: | - from openai import OpenAI - client = OpenAI() - - message = client.beta.threads.messages.update( - message_id="msg_abc12", - thread_id="thread_abc123", - metadata={ - "modified": "true", - "user": "abc123", - }, - ) - print(message) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const message = await openai.beta.threads.messages.update( - "thread_abc123", - "msg_abc123", - { - metadata: { - modified: "true", - user: "abc123", - }, - } - }' - response: | - { - "id": "msg_abc123", - "object": "thread.message", - "created_at": 1699017614, - "assistant_id": null, - "thread_id": "thread_abc123", - "run_id": null, - "role": "user", - "content": [ - { - "type": "text", - "text": { - "value": "How does AI work? Explain it in simple terms.", - "annotations": [] - } - } - ], - "file_ids": [], - "metadata": { - "modified": "true", - "user": "abc123" - } - } - delete: - operationId: deleteMessage - tags: - - Assistants - summary: Deletes a message. - parameters: - - in: path - name: thread_id - required: true - schema: - type: string - description: The ID of the thread to which this message belongs. - - in: path - name: message_id - required: true - schema: - type: string - description: The ID of the message to delete. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/DeleteMessageResponse" - x-oaiMeta: - name: Delete message - group: threads - beta: true - returns: Deletion status - examples: - request: - curl: | - curl -X DELETE https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123 \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" - python: | - from openai import OpenAI - client = OpenAI() - - deleted_message = client.beta.threads.messages.delete( - message_id="msg_abc12", - thread_id="thread_abc123", - ) - print(deleted_message) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const deletedMessage = await openai.beta.threads.messages.del( - "thread_abc123", - "msg_abc123" - ); - - console.log(deletedMessage); - } - response: | - { - "id": "msg_abc123", - "object": "thread.message.deleted", - "deleted": true - } + const openai = new OpenAI(); - /threads/runs: - post: - operationId: createThreadAndRun - tags: - - Assistants - summary: Create a thread and run it in one request. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateThreadAndRunRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/RunObject" - x-oaiMeta: - name: Create thread and run - group: threads - beta: true - returns: A [run](/docs/api-reference/runs/object) object. - examples: - - title: Default - request: - curl: | - curl https://api.openai.com/v1/threads/runs \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "assistant_id": "asst_abc123", - "thread": { - "messages": [ - {"role": "user", "content": "Explain deep learning to a 5 year old."} - ] - } - }' - python: | - from openai import OpenAI - client = OpenAI() - - run = client.beta.threads.create_and_run( - assistant_id="asst_abc123", - thread={ - "messages": [ - {"role": "user", "content": "Explain deep learning to a 5 year old."} - ] - } - ) - - print(run) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const run = await openai.beta.threads.createAndRun({ - assistant_id: "asst_abc123", - thread: { - messages: [ - { role: "user", content: "Explain deep learning to a 5 year old." }, - ], - }, - }); - - console.log(run); - } - - main(); - response: | - { - "id": "run_abc123", - "object": "thread.run", - "created_at": 1699076792, - "assistant_id": "asst_abc123", - "thread_id": "thread_abc123", - "status": "queued", - "started_at": null, - "expires_at": 1699077392, - "cancelled_at": null, - "failed_at": null, - "completed_at": null, - "required_action": null, - "last_error": null, - "model": "gpt-4-turbo", - "instructions": "You are a helpful assistant.", - "tools": [], - "tool_resources": {}, - "metadata": {}, - "temperature": 1.0, - "top_p": 1.0, - "max_completion_tokens": null, - "max_prompt_tokens": null, - "truncation_strategy": { - "type": "auto", - "last_messages": null - }, - "incomplete_details": null, - "usage": null, - "response_format": "auto", - "tool_choice": "auto", - "parallel_tool_calls": true - } + async function main() { + const stream = await openai.beta.threads.runs.submitToolOutputs( + "thread_123", + "run_123", + { + tool_outputs: [ + { + tool_call_id: "call_001", + output: "70 degrees and sunny.", + }, + ], + } + ); + + for await (const event of stream) { + console.log(event); + } + } + + main(); + response: | + event: thread.run.step.completed + data: {"id":"step_001","object":"thread.run.step","created_at":1710352449,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"tool_calls","status":"completed","cancelled_at":null,"completed_at":1710352475,"expires_at":1710353047,"failed_at":null,"last_error":null,"step_details":{"type":"tool_calls","tool_calls":[{"id":"call_iWr0kQ2EaYMaxNdl0v3KYkx7","type":"function","function":{"name":"get_current_weather","arguments":"{\"location\":\"San Francisco, CA\",\"unit\":\"fahrenheit\"}","output":"70 degrees and sunny."}}]},"usage":{"prompt_tokens":291,"completion_tokens":24,"total_tokens":315}} + + event: thread.run.queued + data: {"id":"run_123","object":"thread.run","created_at":1710352447,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":1710352448,"expires_at":1710353047,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} + + event: thread.run.in_progress + data: {"id":"run_123","object":"thread.run","created_at":1710352447,"assistant_id":"asst_123","thread_id":"thread_123","status":"in_progress","started_at":1710352475,"expires_at":1710353047,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} + + event: thread.run.step.created + data: {"id":"step_002","object":"thread.run.step","created_at":1710352476,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710353047,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_002"}},"usage":null} + + event: thread.run.step.in_progress + data: {"id":"step_002","object":"thread.run.step","created_at":1710352476,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710353047,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_002"}},"usage":null} + + event: thread.message.created + data: {"id":"msg_002","object":"thread.message","created_at":1710352476,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"in_progress","incomplete_details":null,"incomplete_at":null,"completed_at":null,"role":"assistant","content":[],"metadata":{}} + + event: thread.message.in_progress + data: {"id":"msg_002","object":"thread.message","created_at":1710352476,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"in_progress","incomplete_details":null,"incomplete_at":null,"completed_at":null,"role":"assistant","content":[],"metadata":{}} + + event: thread.message.delta + data: {"id":"msg_002","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":"The","annotations":[]}}]}} + + event: thread.message.delta + data: {"id":"msg_002","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":" current"}}]}} + + event: thread.message.delta + data: {"id":"msg_002","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":" weather"}}]}} + + ... + + event: thread.message.delta + data: {"id":"msg_002","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":" sunny"}}]}} + + event: thread.message.delta + data: {"id":"msg_002","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":"."}}]}} + + event: thread.message.completed + data: {"id":"msg_002","object":"thread.message","created_at":1710352476,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"completed","incomplete_details":null,"incomplete_at":null,"completed_at":1710352477,"role":"assistant","content":[{"type":"text","text":{"value":"The current weather in San Francisco, CA is 70 degrees Fahrenheit and sunny.","annotations":[]}}],"metadata":{}} + + event: thread.run.step.completed + data: {"id":"step_002","object":"thread.run.step","created_at":1710352476,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"completed","cancelled_at":null,"completed_at":1710352477,"expires_at":1710353047,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_002"}},"usage":{"prompt_tokens":329,"completion_tokens":18,"total_tokens":347}} + + event: thread.run.completed + data: {"id":"run_123","object":"thread.run","created_at":1710352447,"assistant_id":"asst_123","thread_id":"thread_123","status":"completed","started_at":1710352475,"expires_at":null,"cancelled_at":null,"failed_at":null,"completed_at":1710352477,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":{"prompt_tokens":20,"completion_tokens":11,"total_tokens":31},"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} + + event: done + data: [DONE] + /threads/{threadId}/runs/{runId}/cancel: + post: + tags: + - Assistants + summary: Cancels a run that is `in_progress`. + operationId: cancelRun + parameters: + - name: threadId + in: path + description: The ID of the thread to which this run belongs + required: true + style: simple + explode: false + schema: + type: string + - name: runId + in: path + description: The ID of the run to cancel + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/RunObject' + x-oaiMeta: + name: Cancel a run + group: threads + beta: true + returns: "The modified [run](/docs/api-reference/runs/object) object matching\ + \ the specified ID." + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/cancel \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v2" \ + -X POST + python: | + from openai import OpenAI + client = OpenAI() + + run = client.beta.threads.runs.cancel( + thread_id="thread_abc123", + run_id="run_abc123" + ) + + print(run) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const run = await openai.beta.threads.runs.cancel( + "thread_abc123", + "run_abc123" + ); + + console.log(run); + } + + main(); + response: | + { + "id": "run_abc123", + "object": "thread.run", + "created_at": 1699076126, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "cancelling", + "started_at": 1699076126, + "expires_at": 1699076726, + "cancelled_at": null, + "failed_at": null, + "completed_at": null, + "last_error": null, + "model": "gpt-4-turbo", + "instructions": "You summarize books.", + "tools": [ + { + "type": "file_search" + } + ], + "tool_resources": { + "file_search": { + "vector_store_ids": ["vs_123"] + } + }, + "metadata": {}, + "usage": null, + "temperature": 1.0, + "top_p": 1.0, + "response_format": "auto", + "tool_choice": "auto", + "parallel_tool_calls": true + } + /threads/{threadId}/runs/{runId}/steps: + get: + tags: + - Assistants + summary: Returns a list of run steps belonging to a run. + operationId: listRunSteps + parameters: + - name: threadId + in: path + description: The ID of the thread the run and run steps belong to + required: true + style: simple + explode: false + schema: + type: string + - name: runId + in: path + description: The ID of the run the run steps belong to + required: true + style: simple + explode: false + schema: + type: string + - name: limit + in: query + description: | + A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20 + required: false + style: form + explode: true + schema: + type: integer + default: 20 + - name: order + in: query + description: | + Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order + required: false + style: form + explode: true + schema: + type: string + default: desc + enum: + - asc + - desc + - name: after + in: query + description: | + A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list + required: false + style: form + explode: true + schema: + type: string + - name: before + in: query + description: | + A cursor for use in pagination. `before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list + required: false + style: form + explode: true + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ListRunStepsResponse' + x-oaiMeta: + name: List run steps + group: threads + beta: true + returns: "A list of [run step](/docs/api-reference/runs/step-object) objects." + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/steps \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" + python: | + from openai import OpenAI + client = OpenAI() + + run_steps = client.beta.threads.runs.steps.list( + thread_id="thread_abc123", + run_id="run_abc123" + ) + + print(run_steps) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const runStep = await openai.beta.threads.runs.steps.list( + "thread_abc123", + "run_abc123" + ); + console.log(runStep); + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "step_abc123", + "object": "thread.run.step", + "created_at": 1699063291, + "run_id": "run_abc123", + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "type": "message_creation", + "status": "completed", + "cancelled_at": null, + "completed_at": 1699063291, + "expired_at": null, + "failed_at": null, + "last_error": null, + "step_details": { + "type": "message_creation", + "message_creation": { + "message_id": "msg_abc123" + } + }, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + } + } + ], + "first_id": "step_abc123", + "last_id": "step_abc456", + "has_more": false + } + /threads/{threadId}/runs/{runId}/steps/{stepId}: + get: + tags: + - Assistants + summary: Retrieves a run step. + operationId: getRunStep + parameters: + - name: threadId + in: path + description: The ID of the thread to which the run and run step belongs + required: true + style: simple + explode: false + schema: + type: string + - name: runId + in: path + description: The ID of the run to which the run step belongs + required: true + style: simple + explode: false + schema: + type: string + - name: stepId + in: path + description: The ID of the run step to retrieve + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/RunStepObject' + x-oaiMeta: + name: Retrieve run step + group: threads + beta: true + returns: "The [run step](/docs/api-reference/runs/step-object) object matching\ + \ the specified ID." + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/steps/step_abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" + python: | + from openai import OpenAI + client = OpenAI() + + run_step = client.beta.threads.runs.steps.retrieve( + thread_id="thread_abc123", + run_id="run_abc123", + step_id="step_abc123" + ) + + print(run_step) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const runStep = await openai.beta.threads.runs.steps.retrieve( + "thread_abc123", + "run_abc123", + "step_abc123" + ); + console.log(runStep); + } + + main(); + response: | + { + "id": "step_abc123", + "object": "thread.run.step", + "created_at": 1699063291, + "run_id": "run_abc123", + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "type": "message_creation", + "status": "completed", + "cancelled_at": null, + "completed_at": 1699063291, + "expired_at": null, + "failed_at": null, + "last_error": null, + "step_details": { + "type": "message_creation", + "message_creation": { + "message_id": "msg_abc123" + } + }, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + } + } + /vector_stores: + get: + tags: + - Vector Stores + summary: Returns a list of vector stores. + operationId: listVectorStores + parameters: + - name: limit + in: query + description: | + A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20 + required: false + style: form + explode: true + schema: + type: integer + default: 20 + - name: order + in: query + description: | + Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order + required: false + style: form + explode: true + schema: + type: string + default: desc + enum: + - asc + - desc + - name: after + in: query + description: | + A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list + required: false + style: form + explode: true + schema: + type: string + - name: before + in: query + description: | + A cursor for use in pagination. `before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list + required: false + style: form + explode: true + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ListVectorStoresResponse' + x-oaiMeta: + name: List vector stores + group: vector_stores + beta: true + returns: "A list of [vector store](/docs/api-reference/vector-stores/object)\ + \ objects." + examples: + request: + curl: | + curl https://api.openai.com/v1/vector_stores \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" + python: | + from openai import OpenAI + client = OpenAI() + + vector_stores = client.beta.vector_stores.list() + print(vector_stores) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const vectorStores = await openai.beta.vectorStores.list(); + console.log(vectorStores); + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "vs_abc123", + "object": "vector_store", + "created_at": 1699061776, + "name": "Support FAQ", + "bytes": 139920, + "file_counts": { + "in_progress": 0, + "completed": 3, + "failed": 0, + "cancelled": 0, + "total": 3 + } + }, + { + "id": "vs_abc456", + "object": "vector_store", + "created_at": 1699061776, + "name": "Support FAQ v2", + "bytes": 139920, + "file_counts": { + "in_progress": 0, + "completed": 3, + "failed": 0, + "cancelled": 0, + "total": 3 + } + } + ], + "first_id": "vs_abc123", + "last_id": "vs_abc456", + "has_more": false + } + post: + tags: + - Vector Stores + summary: Create a vector store. + operationId: createVectorStore + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateVectorStoreRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/VectorStoreObject' + x-oaiMeta: + name: Create vector store + group: vector_stores + beta: true + returns: "A [vector store](/docs/api-reference/vector-stores/object) object." + examples: + request: + curl: | + curl https://api.openai.com/v1/vector_stores \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" + -d '{ + "name": "Support FAQ" + }' + python: | + from openai import OpenAI + client = OpenAI() + + vector_store = client.beta.vector_stores.create( + name="Support FAQ" + ) + print(vector_store) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const vectorStore = await openai.beta.vectorStores.create({ + name: "Support FAQ" + }); + console.log(vectorStore); + } + + main(); + response: | + { + "id": "vs_abc123", + "object": "vector_store", + "created_at": 1699061776, + "name": "Support FAQ", + "bytes": 139920, + "file_counts": { + "in_progress": 0, + "completed": 3, + "failed": 0, + "cancelled": 0, + "total": 3 + } + } + /vector_stores/{vectorStoreId}: + get: + tags: + - Vector Stores + summary: Retrieves a vector store. + operationId: getVectorStore + parameters: + - name: vectorStoreId + in: path + description: The ID of the vector store to retrieve + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/VectorStoreObject' + x-oaiMeta: + name: Retrieve vector store + group: vector_stores + beta: true + returns: "The [vector store](/docs/api-reference/vector-stores/object) object\ + \ matching the specified ID." + examples: + request: + curl: | + curl https://api.openai.com/v1/vector_stores/vs_abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" + python: | + from openai import OpenAI + client = OpenAI() + + vector_store = client.beta.vector_stores.retrieve( + vector_store_id="vs_abc123" + ) + print(vector_store) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const vectorStore = await openai.beta.vectorStores.retrieve( + "vs_abc123" + ); + console.log(vectorStore); + } + + main(); + response: | + { + "id": "vs_abc123", + "object": "vector_store", + "created_at": 1699061776 + } + post: + tags: + - Vector Stores + summary: Modifies a vector store. + operationId: modifyVectorStore + parameters: + - name: vectorStoreId + in: path + description: The ID of the vector store to modify + required: true + style: simple + explode: false + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/UpdateVectorStoreRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/VectorStoreObject' + x-oaiMeta: + name: Modify vector store + group: vector_stores + beta: true + returns: "The modified [vector store](/docs/api-reference/vector-stores/object)\ + \ object." + examples: + request: + curl: | + curl https://api.openai.com/v1/vector_stores/vs_abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" + -d '{ + "name": "Support FAQ" + }' + python: | + from openai import OpenAI + client = OpenAI() + + vector_store = client.beta.vector_stores.update( + vector_store_id="vs_abc123", + name="Support FAQ" + ) + print(vector_store) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const vectorStore = await openai.beta.vectorStores.update( + "vs_abc123", + { + name: "Support FAQ" + } + ); + console.log(vectorStore); + } + + main(); + response: | + { + "id": "vs_abc123", + "object": "vector_store", + "created_at": 1699061776, + "name": "Support FAQ", + "bytes": 139920, + "file_counts": { + "in_progress": 0, + "completed": 3, + "failed": 0, + "cancelled": 0, + "total": 3 + } + } + delete: + tags: + - Vector Stores + summary: Delete a vector store. + operationId: deleteVectorStore + parameters: + - name: vectorStoreId + in: path + description: The ID of the vector store to delete + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/DeleteVectorStoreResponse' + x-oaiMeta: + name: Delete vector store + group: vector_stores + beta: true + returns: Deletion status + examples: + request: + curl: | + curl https://api.openai.com/v1/vector_stores/vs_abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" \ + -X DELETE + python: | + from openai import OpenAI + client = OpenAI() + + deleted_vector_store = client.beta.vector_stores.delete( + vector_store_id="vs_abc123" + ) + print(deleted_vector_store) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const deletedVectorStore = await openai.beta.vectorStores.del( + "vs_abc123" + ); + console.log(deletedVectorStore); + } + + main(); + response: | + { + id: "vs_abc123", + object: "vector_store.deleted", + deleted: true + } + /vector_stores/{vectorStoreId}/files: + get: + tags: + - Vector Stores + summary: Returns a list of vector store files. + operationId: listVectorStoreFiles + parameters: + - name: vectorStoreId + in: path + description: The ID of the vector store that the files belong to + required: true + style: simple + explode: false + schema: + type: string + - name: limit + in: query + description: | + A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20 + required: false + style: form + explode: true + schema: + type: integer + default: 20 + - name: order + in: query + description: | + Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order + required: false + style: form + explode: true + schema: + type: string + default: desc + enum: + - asc + - desc + - name: after + in: query + description: | + A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list + required: false + style: form + explode: true + schema: + type: string + - name: before + in: query + description: | + A cursor for use in pagination. `before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list + required: false + style: form + explode: true + schema: + type: string + - name: filter + in: query + description: "Filter by file status. One of `in_progress`, `completed`, `failed`,\ + \ `cancelled`" + required: false + style: form + explode: true + schema: + type: string + enum: + - in_progress + - completed + - failed + - cancelled + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ListVectorStoreFilesResponse' + x-oaiMeta: + name: List vector store files + group: vector_stores + beta: true + returns: "A list of [vector store file](/docs/api-reference/vector-stores-files/file-object)\ + \ objects." + examples: + request: + curl: | + curl https://api.openai.com/v1/vector_stores/vs_abc123/files \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" + python: | + from openai import OpenAI + client = OpenAI() + + vector_store_files = client.beta.vector_stores.files.list( + vector_store_id="vs_abc123" + ) + print(vector_store_files) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const vectorStoreFiles = await openai.beta.vectorStores.files.list( + "vs_abc123" + ); + console.log(vectorStoreFiles); + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "file-abc123", + "object": "vector_store.file", + "created_at": 1699061776, + "vector_store_id": "vs_abc123" + }, + { + "id": "file-abc456", + "object": "vector_store.file", + "created_at": 1699061776, + "vector_store_id": "vs_abc123" + } + ], + "first_id": "file-abc123", + "last_id": "file-abc456", + "has_more": false + } + post: + tags: + - Vector Stores + summary: "Create a vector store file by attaching a [File](/docs/api-reference/files)\ + \ to a [vector store](/docs/api-reference/vector-stores/object)." + operationId: createVectorStoreFile + parameters: + - name: vectorStoreId + in: path + description: | + The ID of the vector store for which to create a File + required: true + style: simple + explode: false + schema: + type: string + example: vs_abc123 + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateVectorStoreFileRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/VectorStoreFileObject' + x-oaiMeta: + name: Create vector store file + group: vector_stores + beta: true + returns: "A [vector store file](/docs/api-reference/vector-stores-files/file-object)\ + \ object." + examples: + request: + curl: | + curl https://api.openai.com/v1/vector_stores/vs_abc123/files \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "file_id": "file-abc123" + }' + python: | + from openai import OpenAI + client = OpenAI() + + vector_store_file = client.beta.vector_stores.files.create( + vector_store_id="vs_abc123", + file_id="file-abc123" + ) + print(vector_store_file) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const myVectorStoreFile = await openai.beta.vectorStores.files.create( + "vs_abc123", + { + file_id: "file-abc123" + } + ); + console.log(myVectorStoreFile); + } + + main(); + response: | + { + "id": "file-abc123", + "object": "vector_store.file", + "created_at": 1699061776, + "usage_bytes": 1234, + "vector_store_id": "vs_abcd", + "status": "completed", + "last_error": null + } + /vector_stores/{vectorStoreId}/files/{fileId}: + get: + tags: + - Vector Stores + summary: Retrieves a vector store file. + operationId: getVectorStoreFile + parameters: + - name: vectorStoreId + in: path + description: The ID of the vector store that the file belongs to + required: true + style: simple + explode: false + schema: + type: string + example: vs_abc123 + - name: fileId + in: path + description: The ID of the file being retrieved + required: true + style: simple + explode: false + schema: + type: string + example: file-abc123 + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/VectorStoreFileObject' + x-oaiMeta: + name: Retrieve vector store file + group: vector_stores + beta: true + returns: "The [vector store file](/docs/api-reference/vector-stores-files/file-object)\ + \ object." + examples: + request: + curl: | + curl https://api.openai.com/v1/vector_stores/vs_abc123/files/file-abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" + python: | + from openai import OpenAI + client = OpenAI() + + vector_store_file = client.beta.vector_stores.files.retrieve( + vector_store_id="vs_abc123", + file_id="file-abc123" + ) + print(vector_store_file) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const vectorStoreFile = await openai.beta.vectorStores.files.retrieve( + "vs_abc123", + "file-abc123" + ); + console.log(vectorStoreFile); + } + + main(); + response: | + { + "id": "file-abc123", + "object": "vector_store.file", + "created_at": 1699061776, + "vector_store_id": "vs_abcd", + "status": "completed", + "last_error": null + } + delete: + tags: + - Vector Stores + summary: "Delete a vector store file. This will remove the file from the vector\ + \ store but the file itself will not be deleted. To delete the file, use the\ + \ [delete file](/docs/api-reference/files/delete) endpoint." + operationId: deleteVectorStoreFile + parameters: + - name: vectorStoreId + in: path + description: The ID of the vector store that the file belongs to + required: true + style: simple + explode: false + schema: + type: string + - name: fileId + in: path + description: The ID of the file to delete + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/DeleteVectorStoreFileResponse' + x-oaiMeta: + name: Delete vector store file + group: vector_stores + beta: true + returns: Deletion status + examples: + request: + curl: | + curl https://api.openai.com/v1/vector_stores/vs_abc123/files/file-abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" \ + -X DELETE + python: | + from openai import OpenAI + client = OpenAI() + + deleted_vector_store_file = client.beta.vector_stores.files.delete( + vector_store_id="vs_abc123", + file_id="file-abc123" + ) + print(deleted_vector_store_file) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const deletedVectorStoreFile = await openai.beta.vectorStores.files.del( + "vs_abc123", + "file-abc123" + ); + console.log(deletedVectorStoreFile); + } + + main(); + response: | + { + id: "file-abc123", + object: "vector_store.file.deleted", + deleted: true + } + /vector_stores/{vectorStoreId}/file_batches: + post: + tags: + - Vector Stores + summary: Create a vector store file batch. + operationId: createVectorStoreFileBatch + parameters: + - name: vectorStoreId + in: path + description: | + The ID of the vector store for which to create a File Batch + required: true + style: simple + explode: false + schema: + type: string + example: vs_abc123 + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateVectorStoreFileBatchRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/VectorStoreFileBatchObject' + x-oaiMeta: + name: Create vector store file batch + group: vector_stores + beta: true + returns: "A [vector store file batch](/docs/api-reference/vector-stores-file-batches/batch-object)\ + \ object." + examples: + request: + curl: | + curl https://api.openai.com/v1/vector_stores/vs_abc123/file_batches \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json \ + -H "OpenAI-Beta: assistants=v2" \ + -d '{ + "file_ids": ["file-abc123", "file-abc456"] + }' + python: | + from openai import OpenAI + client = OpenAI() + + vector_store_file_batch = client.beta.vector_stores.file_batches.create( + vector_store_id="vs_abc123", + file_ids=["file-abc123", "file-abc456"] + ) + print(vector_store_file_batch) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const myVectorStoreFileBatch = await openai.beta.vectorStores.fileBatches.create( + "vs_abc123", + { + file_ids: ["file-abc123", "file-abc456"] + } + ); + console.log(myVectorStoreFileBatch); + } + + main(); + response: | + { + "id": "vsfb_abc123", + "object": "vector_store.file_batch", + "created_at": 1699061776, + "vector_store_id": "vs_abc123", + "status": "in_progress", + "file_counts": { + "in_progress": 1, + "completed": 1, + "failed": 0, + "cancelled": 0, + "total": 0, + } + } + /vector_stores/{vectorStoreId}/file_batches/{batchId}: + get: + tags: + - Vector Stores + summary: Retrieves a vector store file batch. + operationId: getVectorStoreFileBatch + parameters: + - name: vectorStoreId + in: path + description: The ID of the vector store that the file batch belongs to + required: true + style: simple + explode: false + schema: + type: string + example: vs_abc123 + - name: batchId + in: path + description: The ID of the file batch being retrieved + required: true + style: simple + explode: false + schema: + type: string + example: vsfb_abc123 + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/VectorStoreFileBatchObject' + x-oaiMeta: + name: Retrieve vector store file batch + group: vector_stores + beta: true + returns: "The [vector store file batch](/docs/api-reference/vector-stores-file-batches/batch-object)\ + \ object." + examples: + request: + curl: | + curl https://api.openai.com/v1/vector_stores/vs_abc123/files_batches/vsfb_abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" + python: | + from openai import OpenAI + client = OpenAI() + + vector_store_file_batch = client.beta.vector_stores.file_batches.retrieve( + vector_store_id="vs_abc123", + batch_id="vsfb_abc123" + ) + print(vector_store_file_batch) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const vectorStoreFileBatch = await openai.beta.vectorStores.fileBatches.retrieve( + "vs_abc123", + "vsfb_abc123" + ); + console.log(vectorStoreFileBatch); + } + + main(); + response: | + { + "id": "vsfb_abc123", + "object": "vector_store.file_batch", + "created_at": 1699061776, + "vector_store_id": "vs_abc123", + "status": "in_progress", + "file_counts": { + "in_progress": 1, + "completed": 1, + "failed": 0, + "cancelled": 0, + "total": 0, + } + } + /vector_stores/{vectorStoreId}/file_batches/{batchId}/cancel: + post: + tags: + - Vector Stores + summary: Cancel a vector store file batch. This attempts to cancel the processing + of files in this batch as soon as possible. + operationId: cancelVectorStoreFileBatch + parameters: + - name: vectorStoreId + in: path + description: The ID of the vector store that the file batch belongs to + required: true + style: simple + explode: false + schema: + type: string + - name: batchId + in: path + description: The ID of the file batch to cancel + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/VectorStoreFileBatchObject' + x-oaiMeta: + name: Cancel vector store file batch + group: vector_stores + beta: true + returns: The modified vector store file batch object. + examples: + request: + curl: | + curl https://api.openai.com/v1/vector_stores/vs_abc123/files_batches/vsfb_abc123/cancel \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" \ + -X POST + python: | + from openai import OpenAI + client = OpenAI() + + deleted_vector_store_file_batch = client.beta.vector_stores.file_batches.cancel( + vector_store_id="vs_abc123", + file_batch_id="vsfb_abc123" + ) + print(deleted_vector_store_file_batch) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const deletedVectorStoreFileBatch = await openai.vector_stores.fileBatches.cancel( + "vs_abc123", + "vsfb_abc123" + ); + console.log(deletedVectorStoreFileBatch); + } + + main(); + response: | + { + "id": "vsfb_abc123", + "object": "vector_store.file_batch", + "created_at": 1699061776, + "vector_store_id": "vs_abc123", + "status": "cancelling", + "file_counts": { + "in_progress": 12, + "completed": 3, + "failed": 0, + "cancelled": 0, + "total": 15, + } + } + /vector_stores/{vectorStoreId}/file_batches/{batchId}/files: + get: + tags: + - Vector Stores + summary: Returns a list of vector store files in a batch. + operationId: listFilesInVectorStoreBatch + parameters: + - name: vectorStoreId + in: path + description: The ID of the vector store that the files belong to + required: true + style: simple + explode: false + schema: + type: string + - name: batchId + in: path + description: The ID of the file batch that the files belong to + required: true + style: simple + explode: false + schema: + type: string + - name: limit + in: query + description: | + A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20 + required: false + style: form + explode: true + schema: + type: integer + default: 20 + - name: order + in: query + description: | + Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order + required: false + style: form + explode: true + schema: + type: string + default: desc + enum: + - asc + - desc + - name: after + in: query + description: | + A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list + required: false + style: form + explode: true + schema: + type: string + - name: before + in: query + description: | + A cursor for use in pagination. `before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list + required: false + style: form + explode: true + schema: + type: string + - name: filter + in: query + description: "Filter by file status. One of `in_progress`, `completed`, `failed`,\ + \ `cancelled`" + required: false + style: form + explode: true + schema: + type: string + enum: + - in_progress + - completed + - failed + - cancelled + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ListVectorStoreFilesResponse' + x-oaiMeta: + name: List vector store files in a batch + group: vector_stores + beta: true + returns: "A list of [vector store file](/docs/api-reference/vector-stores-files/file-object)\ + \ objects." + examples: + request: + curl: | + curl https://api.openai.com/v1/vector_stores/vs_abc123/files_batches/vsfb_abc123/files \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v2" + python: | + from openai import OpenAI + client = OpenAI() + + vector_store_files = client.beta.vector_stores.file_batches.list_files( + vector_store_id="vs_abc123", + batch_id="vsfb_abc123" + ) + print(vector_store_files) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const vectorStoreFiles = await openai.beta.vectorStores.fileBatches.listFiles( + "vs_abc123", + "vsfb_abc123" + ); + console.log(vectorStoreFiles); + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "file-abc123", + "object": "vector_store.file", + "created_at": 1699061776, + "vector_store_id": "vs_abc123" + }, + { + "id": "file-abc456", + "object": "vector_store.file", + "created_at": 1699061776, + "vector_store_id": "vs_abc123" + } + ], + "first_id": "file-abc123", + "last_id": "file-abc456", + "has_more": false + } + /batches: + get: + tags: + - Batch + summary: List your organization's batches. + operationId: listBatches + parameters: + - name: after + in: query + description: | + A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list + required: false + style: form + explode: true + schema: + type: string + - name: limit + in: query + description: | + A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20 + required: false + style: form + explode: true + schema: + type: integer + default: 20 + responses: + "200": + description: Batch listed successfully + content: + application/json: + schema: + $ref: '#/components/schemas/ListBatchesResponse' + x-oaiMeta: + name: List batch + group: batch + returns: "A list of paginated [Batch](/docs/api-reference/batch/object) objects." + examples: + request: + curl: | + curl https://api.openai.com/v1/batches?limit=2 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" + python: | + from openai import OpenAI + client = OpenAI() + + client.batches.list() + node: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const list = await openai.batches.list(); + + for await (const batch of list) { + console.log(batch); + } + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "batch_abc123", + "object": "batch", + "endpoint": "/v1/chat/completions", + "errors": null, + "input_file_id": "file-abc123", + "completion_window": "24h", + "status": "completed", + "output_file_id": "file-cvaTdG", + "error_file_id": "file-HOWS94", + "created_at": 1711471533, + "in_progress_at": 1711471538, + "expires_at": 1711557933, + "finalizing_at": 1711493133, + "completed_at": 1711493163, + "failed_at": null, + "expired_at": null, + "cancelling_at": null, + "cancelled_at": null, + "request_counts": { + "total": 100, + "completed": 95, + "failed": 5 + }, + "metadata": { + "customer_id": "user_123456789", + "batch_description": "Nightly job", + } + }, + { ... }, + ], + "first_id": "batch_abc123", + "last_id": "batch_abc456", + "has_more": true + } + post: + tags: + - Batch + summary: Creates and executes a batch from an uploaded file of requests + operationId: createBatch + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/BatchesBody' + required: true + responses: + "200": + description: Batch created successfully + content: + application/json: + schema: + $ref: '#/components/schemas/Batch' + x-oaiMeta: + name: Create batch + group: batch + returns: "The created [Batch](/docs/api-reference/batch/object) object." + examples: + request: + curl: | + curl https://api.openai.com/v1/batches \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -d '{ + "input_file_id": "file-abc123", + "endpoint": "/v1/chat/completions", + "completion_window": "24h" + }' + python: | + from openai import OpenAI + client = OpenAI() + + client.batches.create( + input_file_id="file-abc123", + endpoint="/v1/chat/completions", + completion_window="24h" + ) + node: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const batch = await openai.batches.create({ + input_file_id: "file-abc123", + endpoint: "/v1/chat/completions", + completion_window: "24h" + }); + + console.log(batch); + } + + main(); + response: | + { + "id": "batch_abc123", + "object": "batch", + "endpoint": "/v1/chat/completions", + "errors": null, + "input_file_id": "file-abc123", + "completion_window": "24h", + "status": "validating", + "output_file_id": null, + "error_file_id": null, + "created_at": 1711471533, + "in_progress_at": null, + "expires_at": null, + "finalizing_at": null, + "completed_at": null, + "failed_at": null, + "expired_at": null, + "cancelling_at": null, + "cancelled_at": null, + "request_counts": { + "total": 0, + "completed": 0, + "failed": 0 + }, + "metadata": { + "customer_id": "user_123456789", + "batch_description": "Nightly eval job", + } + } + /batches/{batchId}: + get: + tags: + - Batch + summary: Retrieves a batch. + operationId: retrieveBatch + parameters: + - name: batchId + in: path + description: The ID of the batch to retrieve + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: Batch retrieved successfully + content: + application/json: + schema: + $ref: '#/components/schemas/Batch' + x-oaiMeta: + name: Retrieve batch + group: batch + returns: "The [Batch](/docs/api-reference/batch/object) object matching the\ + \ specified ID." + examples: + request: + curl: | + curl https://api.openai.com/v1/batches/batch_abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + python: | + from openai import OpenAI + client = OpenAI() + + client.batches.retrieve("batch_abc123") + node: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const batch = await openai.batches.retrieve("batch_abc123"); + + console.log(batch); + } + + main(); + response: | + { + "id": "batch_abc123", + "object": "batch", + "endpoint": "/v1/completions", + "errors": null, + "input_file_id": "file-abc123", + "completion_window": "24h", + "status": "completed", + "output_file_id": "file-cvaTdG", + "error_file_id": "file-HOWS94", + "created_at": 1711471533, + "in_progress_at": 1711471538, + "expires_at": 1711557933, + "finalizing_at": 1711493133, + "completed_at": 1711493163, + "failed_at": null, + "expired_at": null, + "cancelling_at": null, + "cancelled_at": null, + "request_counts": { + "total": 100, + "completed": 95, + "failed": 5 + }, + "metadata": { + "customer_id": "user_123456789", + "batch_description": "Nightly eval job", + } + } + /batches/{batchId}/cancel: + post: + tags: + - Batch + summary: "Cancels an in-progress batch. The batch will be in status `cancelling`\ + \ for up to 10 minutes, before changing to `cancelled`, where it will have\ + \ partial results (if any) available in the output file." + operationId: cancelBatch + parameters: + - name: batchId + in: path + description: The ID of the batch to cancel + required: true + style: simple + explode: false + schema: + type: string + responses: + "200": + description: Batch is cancelling. Returns the cancelling batch's details + content: + application/json: + schema: + $ref: '#/components/schemas/Batch' + x-oaiMeta: + name: Cancel batch + group: batch + returns: "The [Batch](/docs/api-reference/batch/object) object matching the\ + \ specified ID." + examples: + request: + curl: | + curl https://api.openai.com/v1/batches/batch_abc123/cancel \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -X POST + python: | + from openai import OpenAI + client = OpenAI() + + client.batches.cancel("batch_abc123") + node: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const batch = await openai.batches.cancel("batch_abc123"); + + console.log(batch); + } + + main(); + response: | + { + "id": "batch_abc123", + "object": "batch", + "endpoint": "/v1/chat/completions", + "errors": null, + "input_file_id": "file-abc123", + "completion_window": "24h", + "status": "cancelling", + "output_file_id": null, + "error_file_id": null, + "created_at": 1711471533, + "in_progress_at": 1711471538, + "expires_at": 1711557933, + "finalizing_at": null, + "completed_at": null, + "failed_at": null, + "expired_at": null, + "cancelling_at": 1711475133, + "cancelled_at": null, + "request_counts": { + "total": 100, + "completed": 23, + "failed": 1 + }, + "metadata": { + "customer_id": "user_123456789", + "batch_description": "Nightly eval job", + } + } +components: + schemas: + BatchRequestCounts: + required: + - completed + - failed + - total + type: object + properties: + total: + type: integer + description: Total number of requests in the batch + completed: + type: integer + description: Number of requests that have been completed successfully + failed: + type: integer + description: Number of requests that have failed + description: The request counts for different statuses within the batch + DoneEvent: + required: + - data + - event + type: object + properties: + data: + type: string + enum: + - "[DONE]" + event: + type: string + enum: + - done + description: Occurs when a stream ends + x-oaiMeta: + dataDescription: "`data` is `[DONE]`" + FineTuningJobCheckpoint: + title: FineTuningJobCheckpoint + required: + - created_at + - fine_tuned_model_checkpoint + - fine_tuning_job_id + - id + - metrics + - object + - step_number + type: object + properties: + step_number: + type: integer + description: The step number that the checkpoint was created at + x-ballerina-name: stepNumber + created_at: + type: integer + description: The Unix timestamp (in seconds) for when the checkpoint was + created + x-ballerina-name: createdAt + fine_tuning_job_id: + type: string + description: The name of the fine-tuning job that this checkpoint was created + from + x-ballerina-name: fineTuningJobId + id: + type: string + description: "The checkpoint identifier, which can be referenced in the\ + \ API endpoints" + metrics: + $ref: '#/components/schemas/FineTuningJobCheckpointMetrics' + fine_tuned_model_checkpoint: + type: string + description: The name of the fine-tuned checkpoint model that is created + x-ballerina-name: fineTunedModelCheckpoint + object: + type: string + description: "The object type, which is always \"fine_tuning.job.checkpoint\"" + enum: + - fine_tuning.job.checkpoint + description: | + The `fine_tuning.job.checkpoint` object represents a model checkpoint for a fine-tuning job that is ready to use + x-oaiMeta: + name: The fine-tuning job checkpoint object + example: | + { + "object": "fine_tuning.job.checkpoint", + "id": "ftckpt_qtZ5Gyk4BLq1SfLFWp3RtO3P", + "created_at": 1712211699, + "fine_tuned_model_checkpoint": "ft:gpt-3.5-turbo-0125:my-org:custom_suffix:9ABel2dg:ckpt-step-88", + "fine_tuning_job_id": "ftjob-fpbNQ3H1GrMehXRf8cO97xTN", + "metrics": { + "step": 88, + "train_loss": 0.478, + "train_mean_token_accuracy": 0.924, + "valid_loss": 10.112, + "valid_mean_token_accuracy": 0.145, + "full_valid_loss": 0.567, + "full_valid_mean_token_accuracy": 0.944 + }, + "step_number": 88 + } + MessageDeltaContentTextObjectText: + type: object + properties: + annotations: + type: array + items: + $ref: '#/components/schemas/MessageDeltaContentTextObjectTextAnnotations' + value: + type: string + description: The data that makes up the text + RunStepDeltaStepDetailsToolCallsFileSearchObject: + title: File search tool call + required: + - file_search + - index + - type + type: object + properties: + file_search: + type: object + description: "For now, this is always going to be an empty object" + x-oaiTypeLabel: map + x-ballerina-name: fileSearch + index: + type: integer + description: The index of the tool call in the tool calls array + id: + type: string + description: The ID of the tool call object + type: + type: string + description: The type of tool call. This is always going to be `file_search` + for this type of tool call + enum: + - file_search + AssistantsApiToolChoiceOptionOneOf1: + type: string + description: | + `none` means the model will not call any tools and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `required` means the model must call one or more tools before responding to the user + enum: + - none + - auto + - required + ListRunsResponse: + required: + - data + - first_id + - has_more + - last_id + - object + type: object + properties: + first_id: + type: string + example: run_abc123 + x-ballerina-name: firstId + data: + type: array + items: + $ref: '#/components/schemas/RunObject' + last_id: + type: string + example: run_abc456 + x-ballerina-name: lastId + has_more: + type: boolean + example: false + x-ballerina-name: hasMore + object: + type: string + example: list + AssistantsApiResponseFormatOption: + description: | + Specifies the format that the model must output. Compatible with [GPT-4o](/docs/models/gpt-4o), [GPT-4 Turbo](/docs/models/gpt-4-turbo-and-gpt-4), and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`. + + Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is valid JSON. + + **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length + oneOf: + - $ref: '#/components/schemas/AssistantsApiResponseFormatOptionOneOf1' + - $ref: '#/components/schemas/AssistantsApiResponseFormat' + x-oaiExpandable: true + RunStepDetailsToolCallsFunctionObject: + title: Function tool call + required: + - function + - id + - type + type: object + properties: + function: + $ref: '#/components/schemas/RunStepDetailsToolCallsFunctionObjectFunction' + id: + type: string + description: The ID of the tool call object + type: + type: string + description: The type of tool call. This is always going to be `function` + for this type of tool call + enum: + - function + CreateRunRequest: + required: + - assistant_id + - thread_id + type: object + properties: + instructions: + type: string + description: "Overrides the [instructions](/docs/api-reference/assistants/createAssistant)\ + \ of the assistant. This is useful for modifying the behavior on a per-run\ + \ basis" + nullable: true + additional_instructions: + type: string + description: Appends additional instructions at the end of the instructions + for the run. This is useful for modifying the behavior on a per-run basis + without overriding other instructions + nullable: true + x-ballerina-name: additionalInstructions + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + assistant_id: + type: string + description: "The ID of the [assistant](/docs/api-reference/assistants)\ + \ to use to execute this run" + x-ballerina-name: assistantId + additional_messages: + type: array + description: Adds additional messages to the thread before creating the + run + nullable: true + items: + $ref: '#/components/schemas/CreateMessageRequest' + x-ballerina-name: additionalMessages + tools: + maxItems: 20 + type: array + description: Override the tools the assistant can use for this run. This + is useful for modifying the behavior on a per-run basis + nullable: true + items: + $ref: '#/components/schemas/CreateRunRequestTools' + truncation_strategy: + allOf: + - $ref: '#/components/schemas/TruncationObject' + x-ballerina-name: truncationStrategy + top_p: + maximum: 1 + minimum: 0 + type: number + description: | + An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + + We generally recommend altering this or temperature but not both + nullable: true + example: 1 + default: 1 + x-ballerina-name: topP + max_completion_tokens: + minimum: 256 + type: integer + description: | + The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort to use only the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of completion tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info + nullable: true + x-ballerina-name: maxCompletionTokens + response_format: + allOf: + - $ref: '#/components/schemas/AssistantsApiResponseFormatOption' + x-ballerina-name: responseFormat + parallel_tool_calls: + allOf: + - $ref: '#/components/schemas/ParallelToolCalls' + x-ballerina-name: parallelToolCalls + stream: + type: boolean + description: | + If `true`, returns a stream of events that happen during the Run as server-sent events, terminating when the Run enters a terminal state with a `data: [DONE]` message + nullable: true + temperature: + maximum: 2 + minimum: 0 + type: number + description: | + What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic + nullable: true + example: 1 + default: 1 + tool_choice: + allOf: + - $ref: '#/components/schemas/AssistantsApiToolChoiceOption' + x-ballerina-name: toolChoice + model: + description: "The ID of the [Model](/docs/api-reference/models) to be used\ + \ to execute this run. If a value is provided here, it will override the\ + \ model associated with the assistant. If not, the model associated with\ + \ the assistant will be used" + nullable: true + example: gpt-4-turbo + anyOf: + - type: string + - type: string + enum: + - gpt-4o + - gpt-4o-2024-05-13 + - gpt-4o-mini + - gpt-4o-mini-2024-07-18 + - gpt-4-turbo + - gpt-4-turbo-2024-04-09 + - gpt-4-0125-preview + - gpt-4-turbo-preview + - gpt-4-1106-preview + - gpt-4-vision-preview + - gpt-4 + - gpt-4-0314 + - gpt-4-0613 + - gpt-4-32k + - gpt-4-32k-0314 + - gpt-4-32k-0613 + - gpt-3.5-turbo + - gpt-3.5-turbo-16k + - gpt-3.5-turbo-0613 + - gpt-3.5-turbo-1106 + - gpt-3.5-turbo-0125 + - gpt-3.5-turbo-16k-0613 + x-oaiTypeLabel: string + max_prompt_tokens: + minimum: 256 + type: integer + description: | + The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info + nullable: true + x-ballerina-name: maxPromptTokens + additionalProperties: false + ListFineTuningJobCheckpointsResponse: + required: + - data + - has_more + - object + type: object + properties: + first_id: + type: string + nullable: true + x-ballerina-name: firstId + data: + type: array + items: + $ref: '#/components/schemas/FineTuningJobCheckpoint' + last_id: + type: string + nullable: true + x-ballerina-name: lastId + has_more: + type: boolean + x-ballerina-name: hasMore + object: + type: string + enum: + - list + ChatCompletionToolChoiceOption: + description: | + Controls which (if any) tool is called by the model. + `none` means the model will not call any tool and instead generates a message. + `auto` means the model can pick between generating a message or calling one or more tools. + `required` means the model must call one or more tools. + Specifying a particular tool via `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that tool. + + `none` is the default when no tools are present. `auto` is the default if tools are present + oneOf: + - $ref: '#/components/schemas/ChatCompletionToolChoiceOptionOneOf1' + - $ref: '#/components/schemas/ChatCompletionNamedToolChoice' + x-oaiExpandable: true + RunObjectRequiredAction: + required: + - submit_tool_outputs + - type + type: object + properties: + submit_tool_outputs: + allOf: + - $ref: '#/components/schemas/RunObjectRequiredActionSubmitToolOutputs' + x-ballerina-name: submitToolOutputs + type: + type: string + description: "For now, this is always `submit_tool_outputs`" + enum: + - submit_tool_outputs + description: Details on the action required to continue the run. Will be `null` + if no action is required + nullable: true + AutoChunkingStrategyRequestParam: + title: Auto Chunking Strategy + required: + - type + type: object + properties: + type: + type: string + description: Always `auto` + enum: + - auto + additionalProperties: false + description: The default strategy. This strategy currently uses a `max_chunk_size_tokens` + of `800` and `chunk_overlap_tokens` of `400` + AssistantToolsFileSearchTypeOnly: + title: FileSearch tool + required: + - type + type: object + properties: + type: + type: string + description: "The type of tool being defined: `file_search`" + enum: + - file_search + AssistantToolsFileSearch: + title: FileSearch tool + required: + - type + type: object + properties: + file_search: + allOf: + - $ref: '#/components/schemas/AssistantToolsFileSearchFileSearch' + x-ballerina-name: fileSearch + type: + type: string + description: "The type of tool being defined: `file_search`" + enum: + - file_search + CreateMessageRequestAttachments: + type: object + properties: + file_id: + type: string + description: The ID of the file to attach to the message + x-ballerina-name: fileId + tools: + type: array + description: The tools to add this file to + items: + $ref: '#/components/schemas/CreateMessageRequestTools' + ChatCompletionMessageToolCalls: + type: array + description: "The tool calls generated by the model, such as function calls" + items: + $ref: '#/components/schemas/ChatCompletionMessageToolCall' + MessageDeltaObjectDeltaContent: + oneOf: + - $ref: '#/components/schemas/MessageDeltaContentImageFileObject' + - $ref: '#/components/schemas/MessageDeltaContentTextObject' + - $ref: '#/components/schemas/MessageDeltaContentImageUrlObject' + x-oaiExpandable: true + CreateEmbeddingRequest: + required: + - input + - model + type: object + properties: + input: + description: | + Input text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays. The input must not exceed the max input tokens for the model (8192 tokens for `text-embedding-ada-002`), cannot be an empty string, and any array must be 2048 dimensions or less. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens + example: The quick brown fox jumped over the lazy dog + oneOf: + - title: string + type: string + description: The string that will be turned into an embedding. + example: This is a test. + default: "" + - title: array + maxItems: 2048 + minItems: 1 + type: array + description: The array of strings that will be turned into an embedding. + items: + type: string + example: "['This is a test.']" + default: "" + - title: array + maxItems: 2048 + minItems: 1 + type: array + description: The array of integers that will be turned into an embedding. + example: "[1212, 318, 257, 1332, 13]" + items: + type: integer + - title: array + maxItems: 2048 + minItems: 1 + type: array + description: The array of arrays containing integers that will be turned + into an embedding. + example: "[[1212, 318, 257, 1332, 13]]" + items: + minItems: 1 + type: array + items: + type: integer + x-oaiExpandable: true + encoding_format: + type: string + description: "The format to return the embeddings in. Can be either `float`\ + \ or [`base64`](https://pypi.org/project/pybase64/)" + example: float + default: float + enum: + - float + - base64 + x-ballerina-name: encodingFormat + model: + description: | + ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](/docs/models/overview) for descriptions of them + example: text-embedding-3-small + anyOf: + - type: string + - type: string + enum: + - text-embedding-ada-002 + - text-embedding-3-small + - text-embedding-3-large + x-oaiTypeLabel: string + user: + type: string + description: | + A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids) + example: user-1234 + dimensions: + minimum: 1 + type: integer + description: | + The number of dimensions the resulting output embeddings should have. Only supported in `text-embedding-3` and later models + additionalProperties: false + ChatCompletionTokenLogprobTopLogprobs: + required: + - bytes + - logprob + - token + type: object + properties: + logprob: + type: number + description: "The log probability of this token, if it is within the top\ + \ 20 most likely tokens. Otherwise, the value `-9999.0` is used to signify\ + \ that the token is very unlikely" + bytes: + type: array + description: A list of integers representing the UTF-8 bytes representation + of the token. Useful in instances where characters are represented by + multiple tokens and their byte representations must be combined to generate + the correct text representation. Can be `null` if there is no bytes representation + for the token + nullable: true + items: + type: integer + token: + type: string + description: The token + ParallelToolCalls: + type: boolean + description: "Whether to enable [parallel function calling](/docs/guides/function-calling/parallel-function-calling)\ + \ during tool use" + default: true + CreateModerationRequest: + required: + - input + type: object + properties: + input: + description: The input text to classify + oneOf: + - type: string + example: I want to kill them. + default: "" + - type: array + items: + type: string + example: I want to kill them. + default: "" + model: + description: | + Two content moderations models are available: `text-moderation-stable` and `text-moderation-latest`. + + The default is `text-moderation-latest` which will be automatically upgraded over time. This ensures you are always using our most accurate model. If you use `text-moderation-stable`, we will provide advanced notice before updating the model. Accuracy of `text-moderation-stable` may be slightly lower than for `text-moderation-latest` + nullable: false + example: text-moderation-stable + anyOf: + - type: string + - type: string + enum: + - text-moderation-latest + - text-moderation-stable + default: text-moderation-latest + x-oaiTypeLabel: string + CreateUploadRequest: + required: + - bytes + - filename + - mime_type + - purpose + type: object + properties: + filename: + type: string + description: | + The name of the file to upload + purpose: + type: string + description: | + The intended purpose of the uploaded file. + + See the [documentation on File purposes](/docs/api-reference/files/create#files-create-purpose) + enum: + - assistants + - batch + - fine-tune + - vision + mime_type: + type: string + description: | + The MIME type of the file. - - title: Streaming - request: - curl: | - curl https://api.openai.com/v1/threads/runs \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "assistant_id": "asst_123", - "thread": { - "messages": [ - {"role": "user", "content": "Hello"} - ] - }, - "stream": true - }' - python: | - from openai import OpenAI - client = OpenAI() - - stream = client.beta.threads.create_and_run( - assistant_id="asst_123", - thread={ - "messages": [ - {"role": "user", "content": "Hello"} - ] - }, - stream=True - ) - - for event in stream: - print(event) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const stream = await openai.beta.threads.createAndRun({ - assistant_id: "asst_123", - thread: { - messages: [ - { role: "user", content: "Hello" }, - ], - }, - stream: true - }); - - for await (const event of stream) { - console.log(event); - } - } - - main(); - response: | - event: thread.created - data: {"id":"thread_123","object":"thread","created_at":1710348075,"metadata":{}} - - event: thread.run.created - data: {"id":"run_123","object":"thread.run","created_at":1710348075,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710348675,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"tool_resources":{},"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true} - - event: thread.run.queued - data: {"id":"run_123","object":"thread.run","created_at":1710348075,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710348675,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"tool_resources":{},"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true} - - event: thread.run.in_progress - data: {"id":"run_123","object":"thread.run","created_at":1710348075,"assistant_id":"asst_123","thread_id":"thread_123","status":"in_progress","started_at":null,"expires_at":1710348675,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"tool_resources":{},"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true} - - event: thread.run.step.created - data: {"id":"step_001","object":"thread.run.step","created_at":1710348076,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710348675,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":null} - - event: thread.run.step.in_progress - data: {"id":"step_001","object":"thread.run.step","created_at":1710348076,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710348675,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":null} - - event: thread.message.created - data: {"id":"msg_001","object":"thread.message","created_at":1710348076,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"in_progress","incomplete_details":null,"incomplete_at":null,"completed_at":null,"role":"assistant","content":[], "metadata":{}} - - event: thread.message.in_progress - data: {"id":"msg_001","object":"thread.message","created_at":1710348076,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"in_progress","incomplete_details":null,"incomplete_at":null,"completed_at":null,"role":"assistant","content":[], "metadata":{}} - - event: thread.message.delta - data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":"Hello","annotations":[]}}]}} - - ... - - event: thread.message.delta - data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":" today"}}]}} - - event: thread.message.delta - data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":"?"}}]}} - - event: thread.message.completed - data: {"id":"msg_001","object":"thread.message","created_at":1710348076,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"completed","incomplete_details":null,"incomplete_at":null,"completed_at":1710348077,"role":"assistant","content":[{"type":"text","text":{"value":"Hello! How can I assist you today?","annotations":[]}}], "metadata":{}} - - event: thread.run.step.completed - data: {"id":"step_001","object":"thread.run.step","created_at":1710348076,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"completed","cancelled_at":null,"completed_at":1710348077,"expires_at":1710348675,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":{"prompt_tokens":20,"completion_tokens":11,"total_tokens":31}} - - event: thread.run.completed - {"id":"run_123","object":"thread.run","created_at":1710348076,"assistant_id":"asst_123","thread_id":"thread_123","status":"completed","started_at":1713226836,"expires_at":null,"cancelled_at":null,"failed_at":null,"completed_at":1713226837,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":{"prompt_tokens":345,"completion_tokens":11,"total_tokens":356},"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true} - - event: done - data: [DONE] - - - title: Streaming with Functions - request: - curl: | - curl https://api.openai.com/v1/threads/runs \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "assistant_id": "asst_abc123", - "thread": { - "messages": [ - {"role": "user", "content": "What is the weather like in San Francisco?"} - ] - }, - "tools": [ - { - "type": "function", - "function": { - "name": "get_current_weather", - "description": "Get the current weather in a given location", - "parameters": { - "type": "object", - "properties": { - "location": { - "type": "string", - "description": "The city and state, e.g. San Francisco, CA" - }, - "unit": { - "type": "string", - "enum": ["celsius", "fahrenheit"] - } - }, - "required": ["location"] - } - } - } - ], - "stream": true - }' - python: | - from openai import OpenAI - client = OpenAI() - - tools = [ - { - "type": "function", - "function": { - "name": "get_current_weather", - "description": "Get the current weather in a given location", - "parameters": { - "type": "object", - "properties": { - "location": { - "type": "string", - "description": "The city and state, e.g. San Francisco, CA", - }, - "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, - }, - "required": ["location"], - }, - } - } - ] - - stream = client.beta.threads.create_and_run( - thread={ - "messages": [ - {"role": "user", "content": "What is the weather like in San Francisco?"} - ] - }, - assistant_id="asst_abc123", - tools=tools, - stream=True - ) - - for event in stream: - print(event) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - const tools = [ - { - "type": "function", - "function": { - "name": "get_current_weather", - "description": "Get the current weather in a given location", - "parameters": { - "type": "object", - "properties": { - "location": { - "type": "string", - "description": "The city and state, e.g. San Francisco, CA", - }, - "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, - }, - "required": ["location"], - }, - } - } - ]; - - async function main() { - const stream = await openai.beta.threads.createAndRun({ - assistant_id: "asst_123", - thread: { - messages: [ - { role: "user", content: "What is the weather like in San Francisco?" }, - ], - }, - tools: tools, - stream: true - }); - - for await (const event of stream) { - console.log(event); - } - } - - main(); - response: | - event: thread.created - data: {"id":"thread_123","object":"thread","created_at":1710351818,"metadata":{}} - - event: thread.run.created - data: {"id":"run_123","object":"thread.run","created_at":1710351818,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710352418,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} - - event: thread.run.queued - data: {"id":"run_123","object":"thread.run","created_at":1710351818,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710352418,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} - - event: thread.run.in_progress - data: {"id":"run_123","object":"thread.run","created_at":1710351818,"assistant_id":"asst_123","thread_id":"thread_123","status":"in_progress","started_at":1710351818,"expires_at":1710352418,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} - - event: thread.run.step.created - data: {"id":"step_001","object":"thread.run.step","created_at":1710351819,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"tool_calls","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710352418,"failed_at":null,"last_error":null,"step_details":{"type":"tool_calls","tool_calls":[]},"usage":null} - - event: thread.run.step.in_progress - data: {"id":"step_001","object":"thread.run.step","created_at":1710351819,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"tool_calls","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710352418,"failed_at":null,"last_error":null,"step_details":{"type":"tool_calls","tool_calls":[]},"usage":null} - - event: thread.run.step.delta - data: {"id":"step_001","object":"thread.run.step.delta","delta":{"step_details":{"type":"tool_calls","tool_calls":[{"index":0,"id":"call_XXNp8YGaFrjrSjgqxtC8JJ1B","type":"function","function":{"name":"get_current_weather","arguments":"","output":null}}]}}} - - event: thread.run.step.delta - data: {"id":"step_001","object":"thread.run.step.delta","delta":{"step_details":{"type":"tool_calls","tool_calls":[{"index":0,"type":"function","function":{"arguments":"{\""}}]}}} - - event: thread.run.step.delta - data: {"id":"step_001","object":"thread.run.step.delta","delta":{"step_details":{"type":"tool_calls","tool_calls":[{"index":0,"type":"function","function":{"arguments":"location"}}]}}} - - ... - - event: thread.run.step.delta - data: {"id":"step_001","object":"thread.run.step.delta","delta":{"step_details":{"type":"tool_calls","tool_calls":[{"index":0,"type":"function","function":{"arguments":"ahrenheit"}}]}}} - - event: thread.run.step.delta - data: {"id":"step_001","object":"thread.run.step.delta","delta":{"step_details":{"type":"tool_calls","tool_calls":[{"index":0,"type":"function","function":{"arguments":"\"}"}}]}}} - - event: thread.run.requires_action - data: {"id":"run_123","object":"thread.run","created_at":1710351818,"assistant_id":"asst_123","thread_id":"thread_123","status":"requires_action","started_at":1710351818,"expires_at":1710352418,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":{"type":"submit_tool_outputs","submit_tool_outputs":{"tool_calls":[{"id":"call_XXNp8YGaFrjrSjgqxtC8JJ1B","type":"function","function":{"name":"get_current_weather","arguments":"{\"location\":\"San Francisco, CA\",\"unit\":\"fahrenheit\"}"}}]}},"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":{"prompt_tokens":345,"completion_tokens":11,"total_tokens":356},"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} - - event: done - data: [DONE] - - /threads/{thread_id}/runs: - get: - operationId: listRuns - tags: - - Assistants - summary: Returns a list of runs belonging to a thread. - parameters: - - name: thread_id - in: path - required: true - schema: - type: string - description: The ID of the thread the run belongs to. - - name: limit - in: query - description: *pagination_limit_param_description - required: false - schema: - type: integer - default: 20 - - name: order - in: query - description: *pagination_order_param_description - schema: - type: string - default: desc - enum: ["asc", "desc"] - - name: after - in: query - description: *pagination_after_param_description - schema: - type: string - - name: before - in: query - description: *pagination_before_param_description - schema: - type: string - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ListRunsResponse" - x-oaiMeta: - name: List runs - group: threads - beta: true - returns: A list of [run](/docs/api-reference/runs/object) objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/threads/thread_abc123/runs \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" - python: | - from openai import OpenAI - client = OpenAI() - - runs = client.beta.threads.runs.list( - "thread_abc123" - ) - - print(runs) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const runs = await openai.beta.threads.runs.list( - "thread_abc123" - ); - - console.log(runs); - } + This must fall within the supported MIME types for your file purpose. See the supported MIME types for assistants and vision + x-ballerina-name: mimeType + bytes: + type: integer + description: | + The number of bytes in the file you are uploading + additionalProperties: false + MessageDeltaContentTextAnnotationsFilePathObjectFilePath: + type: object + properties: + file_id: + type: string + description: The ID of the file that was generated + x-ballerina-name: fileId + TranscriptionWord: + required: + - end + - start + - word + type: object + properties: + start: + type: number + description: Start time of the word in seconds + format: float + end: + type: number + description: End time of the word in seconds + format: float + word: + type: string + description: The text content of the word + CreateSpeechRequest: + required: + - input + - model + - voice + type: object + properties: + voice: + type: string + description: "The voice to use when generating the audio. Supported voices\ + \ are `alloy`, `echo`, `fable`, `onyx`, `nova`, and `shimmer`. Previews\ + \ of the voices are available in the [Text to speech guide](/docs/guides/text-to-speech/voice-options)" + enum: + - alloy + - echo + - fable + - onyx + - nova + - shimmer + input: + maxLength: 4096 + type: string + description: The text to generate audio for. The maximum length is 4096 + characters + response_format: + type: string + description: "The format to audio in. Supported formats are `mp3`, `opus`,\ + \ `aac`, `flac`, `wav`, and `pcm`" + default: mp3 + enum: + - mp3 + - opus + - aac + - flac + - wav + - pcm + x-ballerina-name: responseFormat + model: + description: | + One of the available [TTS models](/docs/models/tts): `tts-1` or `tts-1-hd` + anyOf: + - type: string + - type: string + enum: + - tts-1 + - tts-1-hd + x-oaiTypeLabel: string + speed: + maximum: 4.0 + minimum: 0.25 + type: number + description: The speed of the generated audio. Select a value from `0.25` + to `4.0`. `1.0` is the default + default: 1.0 + additionalProperties: false + AssistantObjectToolResources: + type: object + properties: + code_interpreter: + allOf: + - $ref: '#/components/schemas/AssistantObjectToolResourcesCodeInterpreter' + x-ballerina-name: codeInterpreter + file_search: + allOf: + - $ref: '#/components/schemas/AssistantObjectToolResourcesFileSearch' + x-ballerina-name: fileSearch + description: | + A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs + nullable: true + RunStreamEventRunStreamEventOneOf12: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunObject' + event: + type: string + enum: + - thread.run.queued + description: "Occurs when a [run](/docs/api-reference/runs/object) moves to\ + \ a `queued` status" + x-oaiMeta: + dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" + CreateVectorStoreFileRequest: + required: + - file_id + type: object + properties: + chunking_strategy: + allOf: + - $ref: '#/components/schemas/ChunkingStrategyRequestParam' + x-ballerina-name: chunkingStrategy + file_id: + type: string + description: "A [File](/docs/api-reference/files) ID that the vector store\ + \ should use. Useful for tools like `file_search` that can access files" + x-ballerina-name: fileId + additionalProperties: false + MessageStreamEventMessageStreamEventMessageStreamEventOneOf123: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/MessageDeltaObject' + event: + type: string + enum: + - thread.message.delta + description: "Occurs when parts of a [Message](/docs/api-reference/messages/object)\ + \ are being streamed" + x-oaiMeta: + dataDescription: "`data` is a [message delta](/docs/api-reference/assistants-streaming/message-delta-object)" + CreateMessageRequestTools: + oneOf: + - $ref: '#/components/schemas/AssistantToolsCode' + - $ref: '#/components/schemas/AssistantToolsFileSearchTypeOnly' + x-oaiExpandable: true + ChatCompletionRequestMessageContentPartText: + title: Text content part + required: + - text + - type + type: object + properties: + text: + type: string + description: The text content + type: + type: string + description: The type of the content part + enum: + - text + ModifyThreadRequest: + type: object + properties: + tool_resources: + allOf: + - $ref: '#/components/schemas/ModifyThreadRequestToolResources' + x-ballerina-name: toolResources + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + additionalProperties: false + MessageContentTextObject: + title: Text + required: + - text + - type + type: object + properties: + text: + $ref: '#/components/schemas/MessageContentTextObjectText' + type: + type: string + description: Always `text` + enum: + - text + description: The text content that is part of a message + DeleteMessageResponse: + required: + - deleted + - id + - object + type: object + properties: + deleted: + type: boolean + id: + type: string + object: + type: string + enum: + - thread.message.deleted + MessageStreamEvent: + oneOf: + - $ref: '#/components/schemas/MessageStreamEventOneOf1' + - $ref: '#/components/schemas/MessageStreamEventMessageStreamEventOneOf12' + - $ref: '#/components/schemas/MessageStreamEventMessageStreamEventMessageStreamEventOneOf123' + - $ref: '#/components/schemas/MessageStreamEventMessageStreamEventMessageStreamEventMessageStreamEventOneOf1234' + - $ref: '#/components/schemas/MessageStreamEventMessageStreamEventMessageStreamEventMessageStreamEventMessageStreamEventOneOf12345' + RunStepDeltaObjectDelta: + type: object + properties: + step_details: + type: object + description: The details of the run step + oneOf: + - $ref: '#/components/schemas/RunStepDeltaStepDetailsMessageCreationObject' + - $ref: '#/components/schemas/RunStepDeltaStepDetailsToolCallsObject' + x-oaiExpandable: true + x-ballerina-name: stepDetails + description: The delta containing the fields that have changed on the run step + AssistantsNamedToolChoiceFunction: + required: + - name + type: object + properties: + name: + type: string + description: The name of the function to call + Embedding: + required: + - embedding + - index + - object + type: object + properties: + index: + type: integer + description: The index of the embedding in the list of embeddings + embedding: + type: array + description: | + The embedding vector, which is a list of floats. The length of vector depends on the model as listed in the [embedding guide](/docs/guides/embeddings) + items: + type: number + object: + type: string + description: "The object type, which is always \"embedding\"" + enum: + - embedding + description: | + Represents an embedding vector returned by embedding endpoint + x-oaiMeta: + name: The embedding object + example: | + { + "object": "embedding", + "embedding": [ + 0.0023064255, + -0.009327292, + .... (1536 floats total for ada-002) + -0.0028842222, + ], + "index": 0 + } + ChatCompletionMessageToolCallChunkFunction: + type: object + properties: + name: + type: string + description: The name of the function to call + arguments: + type: string + description: "The arguments to call the function with, as generated by the\ + \ model in JSON format. Note that the model does not always generate valid\ + \ JSON, and may hallucinate parameters not defined by your function schema.\ + \ Validate the arguments in your code before calling your function" + RunStepDetailsMessageCreationObjectMessageCreation: + required: + - message_id + type: object + properties: + message_id: + type: string + description: The ID of the message that was created by this run step + x-ballerina-name: messageId + RunStepStreamEventRunStepStreamEventRunStepStreamEventOneOf123: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunStepDeltaObject' + event: + type: string + enum: + - thread.run.step.delta + description: "Occurs when parts of a [run step](/docs/api-reference/runs/step-object)\ + \ are being streamed" + x-oaiMeta: + dataDescription: "`data` is a [run step delta](/docs/api-reference/assistants-streaming/run-step-delta-object)" + RunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventOneOf12345: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunObject' + event: + type: string + enum: + - thread.run.completed + description: "Occurs when a [run](/docs/api-reference/runs/object) is completed" + x-oaiMeta: + dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" + CreateChatCompletionRequest: + required: + - messages + - model + type: object + properties: + top_logprobs: + maximum: 20 + minimum: 0 + type: integer + description: "An integer between 0 and 20 specifying the number of most\ + \ likely tokens to return at each token position, each with an associated\ + \ log probability. `logprobs` must be set to `true` if this parameter\ + \ is used" + nullable: true + x-ballerina-name: topLogprobs + logit_bias: + type: object + additionalProperties: + type: integer + description: | + Modify the likelihood of specified tokens appearing in the completion. + + Accepts a JSON object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token + nullable: true + x-oaiTypeLabel: map + x-ballerina-name: logitBias + seed: + maximum: 9223372036854775807 + minimum: -9223372036854775808 + type: integer + description: | + This feature is in Beta. + If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result. + Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend + nullable: true + x-oaiMeta: + beta: true + functions: + maxItems: 128 + minItems: 1 + type: array + description: | + Deprecated in favor of `tools`. + + A list of functions the model may generate JSON inputs for + deprecated: true + items: + $ref: '#/components/schemas/ChatCompletionFunctions' + max_tokens: + type: integer + description: | + The maximum number of [tokens](/tokenizer) that can be generated in the chat completion. - main(); - response: | - { - "object": "list", - "data": [ - { - "id": "run_abc123", - "object": "thread.run", - "created_at": 1699075072, - "assistant_id": "asst_abc123", - "thread_id": "thread_abc123", - "status": "completed", - "started_at": 1699075072, - "expires_at": null, - "cancelled_at": null, - "failed_at": null, - "completed_at": 1699075073, - "last_error": null, - "model": "gpt-4-turbo", - "instructions": null, - "incomplete_details": null, - "tools": [ - { - "type": "code_interpreter" - } - ], - "tool_resources": { - "code_interpreter": { - "file_ids": [ - "file-abc123", - "file-abc456" - ] - } - }, - "metadata": {}, - "usage": { - "prompt_tokens": 123, - "completion_tokens": 456, - "total_tokens": 579 - }, - "temperature": 1.0, - "top_p": 1.0, - "max_prompt_tokens": 1000, - "max_completion_tokens": 1000, - "truncation_strategy": { - "type": "auto", - "last_messages": null - }, - "response_format": "auto", - "tool_choice": "auto", - "parallel_tool_calls": true - }, - { - "id": "run_abc456", - "object": "thread.run", - "created_at": 1699063290, - "assistant_id": "asst_abc123", - "thread_id": "thread_abc123", - "status": "completed", - "started_at": 1699063290, - "expires_at": null, - "cancelled_at": null, - "failed_at": null, - "completed_at": 1699063291, - "last_error": null, - "model": "gpt-4-turbo", - "instructions": null, - "incomplete_details": null, - "tools": [ - { - "type": "code_interpreter" - } - ], - "tool_resources": { - "code_interpreter": { - "file_ids": [ - "file-abc123", - "file-abc456" - ] - } - }, - "metadata": {}, - "usage": { - "prompt_tokens": 123, - "completion_tokens": 456, - "total_tokens": 579 - }, - "temperature": 1.0, - "top_p": 1.0, - "max_prompt_tokens": 1000, - "max_completion_tokens": 1000, - "truncation_strategy": { - "type": "auto", - "last_messages": null - }, - "response_format": "auto", - "tool_choice": "auto", - "parallel_tool_calls": true - } - ], - "first_id": "run_abc123", - "last_id": "run_abc456", - "has_more": false - } - post: - operationId: createRun - tags: - - Assistants - summary: Create a run. - parameters: - - in: path - name: thread_id - required: true - schema: - type: string - description: The ID of the thread to run. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateRunRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/RunObject" - x-oaiMeta: - name: Create run - group: threads - beta: true - returns: A [run](/docs/api-reference/runs/object) object. - examples: - - title: Default - request: - curl: | - curl https://api.openai.com/v1/threads/thread_abc123/runs \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "assistant_id": "asst_abc123" - }' - python: | - from openai import OpenAI - client = OpenAI() - - run = client.beta.threads.runs.create( - thread_id="thread_abc123", - assistant_id="asst_abc123" - ) - - print(run) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const run = await openai.beta.threads.runs.create( - "thread_abc123", - { assistant_id: "asst_abc123" } - ); - - console.log(run); - } - - main(); - response: &run_object_example | - { - "id": "run_abc123", - "object": "thread.run", - "created_at": 1699063290, - "assistant_id": "asst_abc123", - "thread_id": "thread_abc123", - "status": "queued", - "started_at": 1699063290, - "expires_at": null, - "cancelled_at": null, - "failed_at": null, - "completed_at": 1699063291, - "last_error": null, - "model": "gpt-4-turbo", - "instructions": null, - "incomplete_details": null, - "tools": [ - { - "type": "code_interpreter" - } - ], - "metadata": {}, - "usage": null, - "temperature": 1.0, - "top_p": 1.0, - "max_prompt_tokens": 1000, - "max_completion_tokens": 1000, - "truncation_strategy": { - "type": "auto", - "last_messages": null - }, - "response_format": "auto", - "tool_choice": "auto", - "parallel_tool_calls": true - } - - title: Streaming - request: - curl: | - curl https://api.openai.com/v1/threads/thread_123/runs \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "assistant_id": "asst_123", - "stream": true - }' - python: | - from openai import OpenAI - client = OpenAI() - - stream = client.beta.threads.runs.create( - thread_id="thread_123", - assistant_id="asst_123", - stream=True - ) - - for event in stream: - print(event) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const stream = await openai.beta.threads.runs.create( - "thread_123", - { assistant_id: "asst_123", stream: true } - ); - - for await (const event of stream) { - console.log(event); - } - } - - main(); - response: | - event: thread.run.created - data: {"id":"run_123","object":"thread.run","created_at":1710330640,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710331240,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} - - event: thread.run.queued - data: {"id":"run_123","object":"thread.run","created_at":1710330640,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710331240,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} - - event: thread.run.in_progress - data: {"id":"run_123","object":"thread.run","created_at":1710330640,"assistant_id":"asst_123","thread_id":"thread_123","status":"in_progress","started_at":1710330641,"expires_at":1710331240,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} - - event: thread.run.step.created - data: {"id":"step_001","object":"thread.run.step","created_at":1710330641,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710331240,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":null} - - event: thread.run.step.in_progress - data: {"id":"step_001","object":"thread.run.step","created_at":1710330641,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710331240,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":null} - - event: thread.message.created - data: {"id":"msg_001","object":"thread.message","created_at":1710330641,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"in_progress","incomplete_details":null,"incomplete_at":null,"completed_at":null,"role":"assistant","content":[],"metadata":{}} - - event: thread.message.in_progress - data: {"id":"msg_001","object":"thread.message","created_at":1710330641,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"in_progress","incomplete_details":null,"incomplete_at":null,"completed_at":null,"role":"assistant","content":[],"metadata":{}} - - event: thread.message.delta - data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":"Hello","annotations":[]}}]}} - - ... - - event: thread.message.delta - data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":" today"}}]}} - - event: thread.message.delta - data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":"?"}}]}} - - event: thread.message.completed - data: {"id":"msg_001","object":"thread.message","created_at":1710330641,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"completed","incomplete_details":null,"incomplete_at":null,"completed_at":1710330642,"role":"assistant","content":[{"type":"text","text":{"value":"Hello! How can I assist you today?","annotations":[]}}],"metadata":{}} - - event: thread.run.step.completed - data: {"id":"step_001","object":"thread.run.step","created_at":1710330641,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"completed","cancelled_at":null,"completed_at":1710330642,"expires_at":1710331240,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":{"prompt_tokens":20,"completion_tokens":11,"total_tokens":31}} - - event: thread.run.completed - data: {"id":"run_123","object":"thread.run","created_at":1710330640,"assistant_id":"asst_123","thread_id":"thread_123","status":"completed","started_at":1710330641,"expires_at":null,"cancelled_at":null,"failed_at":null,"completed_at":1710330642,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":{"prompt_tokens":20,"completion_tokens":11,"total_tokens":31},"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} - - event: done - data: [DONE] - - - title: Streaming with Functions - request: - curl: | - curl https://api.openai.com/v1/threads/thread_abc123/runs \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "assistant_id": "asst_abc123", - "tools": [ - { - "type": "function", - "function": { - "name": "get_current_weather", - "description": "Get the current weather in a given location", - "parameters": { - "type": "object", - "properties": { - "location": { - "type": "string", - "description": "The city and state, e.g. San Francisco, CA" - }, - "unit": { - "type": "string", - "enum": ["celsius", "fahrenheit"] - } - }, - "required": ["location"] - } - } - } - ], - "stream": true - }' - python: | - from openai import OpenAI - client = OpenAI() - - tools = [ - { - "type": "function", - "function": { - "name": "get_current_weather", - "description": "Get the current weather in a given location", - "parameters": { - "type": "object", - "properties": { - "location": { - "type": "string", - "description": "The city and state, e.g. San Francisco, CA", - }, - "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, - }, - "required": ["location"], - }, - } - } - ] - - stream = client.beta.threads.runs.create( - thread_id="thread_abc123", - assistant_id="asst_abc123", - tools=tools, - stream=True - ) - - for event in stream: - print(event) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - const tools = [ - { - "type": "function", - "function": { - "name": "get_current_weather", - "description": "Get the current weather in a given location", - "parameters": { - "type": "object", - "properties": { - "location": { - "type": "string", - "description": "The city and state, e.g. San Francisco, CA", - }, - "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, - }, - "required": ["location"], - }, - } - } - ]; - - async function main() { - const stream = await openai.beta.threads.runs.create( - "thread_abc123", - { - assistant_id: "asst_abc123", - tools: tools, - stream: true - } - ); - - for await (const event of stream) { - console.log(event); - } - } - - main(); - response: | - event: thread.run.created - data: {"id":"run_123","object":"thread.run","created_at":1710348075,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710348675,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} - - event: thread.run.queued - data: {"id":"run_123","object":"thread.run","created_at":1710348075,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710348675,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} - - event: thread.run.in_progress - data: {"id":"run_123","object":"thread.run","created_at":1710348075,"assistant_id":"asst_123","thread_id":"thread_123","status":"in_progress","started_at":1710348075,"expires_at":1710348675,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} - - event: thread.run.step.created - data: {"id":"step_001","object":"thread.run.step","created_at":1710348076,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710348675,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":null} - - event: thread.run.step.in_progress - data: {"id":"step_001","object":"thread.run.step","created_at":1710348076,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710348675,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":null} - - event: thread.message.created - data: {"id":"msg_001","object":"thread.message","created_at":1710348076,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"in_progress","incomplete_details":null,"incomplete_at":null,"completed_at":null,"role":"assistant","content":[],"metadata":{}} - - event: thread.message.in_progress - data: {"id":"msg_001","object":"thread.message","created_at":1710348076,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"in_progress","incomplete_details":null,"incomplete_at":null,"completed_at":null,"role":"assistant","content":[],"metadata":{}} - - event: thread.message.delta - data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":"Hello","annotations":[]}}]}} - - ... - - event: thread.message.delta - data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":" today"}}]}} - - event: thread.message.delta - data: {"id":"msg_001","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":"?"}}]}} - - event: thread.message.completed - data: {"id":"msg_001","object":"thread.message","created_at":1710348076,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"completed","incomplete_details":null,"incomplete_at":null,"completed_at":1710348077,"role":"assistant","content":[{"type":"text","text":{"value":"Hello! How can I assist you today?","annotations":[]}}],"metadata":{}} - - event: thread.run.step.completed - data: {"id":"step_001","object":"thread.run.step","created_at":1710348076,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"completed","cancelled_at":null,"completed_at":1710348077,"expires_at":1710348675,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_001"}},"usage":{"prompt_tokens":20,"completion_tokens":11,"total_tokens":31}} - - event: thread.run.completed - data: {"id":"run_123","object":"thread.run","created_at":1710348075,"assistant_id":"asst_123","thread_id":"thread_123","status":"completed","started_at":1710348075,"expires_at":null,"cancelled_at":null,"failed_at":null,"completed_at":1710348077,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":{"prompt_tokens":20,"completion_tokens":11,"total_tokens":31},"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} - - event: done - data: [DONE] - - /threads/{thread_id}/runs/{run_id}: - get: - operationId: getRun - tags: - - Assistants - summary: Retrieves a run. - parameters: - - in: path - name: thread_id - required: true - schema: - type: string - description: The ID of the [thread](/docs/api-reference/threads) that was run. - - in: path - name: run_id - required: true - schema: - type: string - description: The ID of the run to retrieve. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/RunObject" - x-oaiMeta: - name: Retrieve run - group: threads - beta: true - returns: The [run](/docs/api-reference/runs/object) object matching the specified ID. - examples: - request: - curl: | - curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123 \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" - python: | - from openai import OpenAI - client = OpenAI() - - run = client.beta.threads.runs.retrieve( - thread_id="thread_abc123", - run_id="run_abc123" - ) - - print(run) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const run = await openai.beta.threads.runs.retrieve( - "thread_abc123", - "run_abc123" - ); - - console.log(run); - } + The total length of input tokens and generated tokens is limited by the model's context length. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens + nullable: true + x-ballerina-name: maxTokens + function_call: + description: | + Deprecated in favor of `tool_choice`. - main(); - response: | - { - "id": "run_abc123", - "object": "thread.run", - "created_at": 1699075072, - "assistant_id": "asst_abc123", - "thread_id": "thread_abc123", - "status": "completed", - "started_at": 1699075072, - "expires_at": null, - "cancelled_at": null, - "failed_at": null, - "completed_at": 1699075073, - "last_error": null, - "model": "gpt-4-turbo", - "instructions": null, - "incomplete_details": null, - "tools": [ - { - "type": "code_interpreter" - } - ], - "metadata": {}, - "usage": { - "prompt_tokens": 123, - "completion_tokens": 456, - "total_tokens": 579 - }, - "temperature": 1.0, - "top_p": 1.0, - "max_prompt_tokens": 1000, - "max_completion_tokens": 1000, - "truncation_strategy": { - "type": "auto", - "last_messages": null - }, - "response_format": "auto", - "tool_choice": "auto", - "parallel_tool_calls": true - } - post: - operationId: modifyRun - tags: - - Assistants - summary: Modifies a run. - parameters: - - in: path - name: thread_id - required: true - schema: - type: string - description: The ID of the [thread](/docs/api-reference/threads) that was run. - - in: path - name: run_id - required: true - schema: - type: string - description: The ID of the run to modify. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/ModifyRunRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/RunObject" - x-oaiMeta: - name: Modify run - group: threads - beta: true - returns: The modified [run](/docs/api-reference/runs/object) object matching the specified ID. - examples: - request: - curl: | - curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123 \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "metadata": { - "user_id": "user_abc123" - } - }' - python: | - from openai import OpenAI - client = OpenAI() - - run = client.beta.threads.runs.update( - thread_id="thread_abc123", - run_id="run_abc123", - metadata={"user_id": "user_abc123"}, - ) - - print(run) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const run = await openai.beta.threads.runs.update( - "thread_abc123", - "run_abc123", - { - metadata: { - user_id: "user_abc123", - }, - } - ); - - console.log(run); - } + Controls which (if any) function is called by the model. + `none` means the model will not call a function and instead generates a message. + `auto` means the model can pick between generating a message or calling a function. + Specifying a particular function via `{"name": "my_function"}` forces the model to call that function. - main(); - response: | - { - "id": "run_abc123", - "object": "thread.run", - "created_at": 1699075072, - "assistant_id": "asst_abc123", - "thread_id": "thread_abc123", - "status": "completed", - "started_at": 1699075072, - "expires_at": null, - "cancelled_at": null, - "failed_at": null, - "completed_at": 1699075073, - "last_error": null, - "model": "gpt-4-turbo", - "instructions": null, - "incomplete_details": null, - "tools": [ - { - "type": "code_interpreter" - } - ], - "tool_resources": { - "code_interpreter": { - "file_ids": [ - "file-abc123", - "file-abc456" - ] - } - }, - "metadata": { - "user_id": "user_abc123" - }, - "usage": { - "prompt_tokens": 123, - "completion_tokens": 456, - "total_tokens": 579 - }, - "temperature": 1.0, - "top_p": 1.0, - "max_prompt_tokens": 1000, - "max_completion_tokens": 1000, - "truncation_strategy": { - "type": "auto", - "last_messages": null - }, - "response_format": "auto", - "tool_choice": "auto", - "parallel_tool_calls": true - } + `none` is the default when no functions are present. `auto` is the default if functions are present + deprecated: true + oneOf: + - type: string + description: | + `none` means the model will not call a function and instead generates a message. `auto` means the model can pick between generating a message or calling a function. + enum: + - none + - auto + - $ref: '#/components/schemas/ChatCompletionFunctionCallOption' + x-oaiExpandable: true + x-ballerina-name: functionCall + presence_penalty: + maximum: 2 + minimum: -2 + type: number + description: | + Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. + + [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) + nullable: true + default: 0 + x-ballerina-name: presencePenalty + tools: + type: array + description: | + A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported + items: + $ref: '#/components/schemas/ChatCompletionTool' + "n": + maximum: 128 + minimum: 1 + type: integer + description: How many chat completion choices to generate for each input + message. Note that you will be charged based on the number of generated + tokens across all of the choices. Keep `n` as `1` to minimize costs + nullable: true + example: 1 + default: 1 + logprobs: + type: boolean + description: "Whether to return log probabilities of the output tokens or\ + \ not. If true, returns the log probabilities of each output token returned\ + \ in the `content` of `message`" + nullable: true + default: false + top_p: + maximum: 1 + minimum: 0 + type: number + description: | + An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + + We generally recommend altering this or `temperature` but not both + nullable: true + example: 1 + default: 1 + x-ballerina-name: topP + frequency_penalty: + maximum: 2 + minimum: -2 + type: number + description: | + Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. + + [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) + nullable: true + default: 0 + x-ballerina-name: frequencyPenalty + response_format: + allOf: + - $ref: '#/components/schemas/CreateChatCompletionRequestResponseFormat' + x-ballerina-name: responseFormat + stop: + description: | + Up to 4 sequences where the API will stop generating further tokens + oneOf: + - type: string + nullable: true + - maxItems: 4 + minItems: 1 + type: array + items: + type: string + parallel_tool_calls: + allOf: + - $ref: '#/components/schemas/ParallelToolCalls' + x-ballerina-name: parallelToolCalls + stream: + type: boolean + description: | + If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) as they become available, with the stream terminated by a `data: [DONE]` message. [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions) + nullable: true + default: false + temperature: + maximum: 2 + minimum: 0 + type: number + description: | + What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. + + We generally recommend altering this or `top_p` but not both + nullable: true + example: 1 + default: 1 + messages: + minItems: 1 + type: array + description: "A list of messages comprising the conversation so far. [Example\ + \ Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models)" + items: + $ref: '#/components/schemas/ChatCompletionRequestMessage' + tool_choice: + allOf: + - $ref: '#/components/schemas/ChatCompletionToolChoiceOption' + x-ballerina-name: toolChoice + model: + description: "ID of the model to use. See the [model endpoint compatibility](/docs/models/model-endpoint-compatibility)\ + \ table for details on which models work with the Chat API" + example: gpt-4-turbo + anyOf: + - type: string + - type: string + enum: + - gpt-4o + - gpt-4o-2024-05-13 + - gpt-4o-mini + - gpt-4o-mini-2024-07-18 + - gpt-4-turbo + - gpt-4-turbo-2024-04-09 + - gpt-4-0125-preview + - gpt-4-turbo-preview + - gpt-4-1106-preview + - gpt-4-vision-preview + - gpt-4 + - gpt-4-0314 + - gpt-4-0613 + - gpt-4-32k + - gpt-4-32k-0314 + - gpt-4-32k-0613 + - gpt-3.5-turbo + - gpt-3.5-turbo-16k + - gpt-3.5-turbo-0301 + - gpt-3.5-turbo-0613 + - gpt-3.5-turbo-1106 + - gpt-3.5-turbo-0125 + - gpt-3.5-turbo-16k-0613 + x-oaiTypeLabel: string + service_tier: + type: string + description: | + Specifies the latency tier to use for processing the request. This parameter is relevant for customers subscribed to the scale tier service: + - If set to 'auto', the system will utilize scale tier credits until they are exhausted. + - If set to 'default', the request will be processed using the default service tier with a lower uptime SLA and no latency guarentee. + - When not set, the default behavior is 'auto'. + + When this parameter is set, the response body will include the `service_tier` utilized + nullable: true + enum: + - auto + - default + x-ballerina-name: serviceTier + stream_options: + allOf: + - $ref: '#/components/schemas/ChatCompletionStreamOptions' + x-ballerina-name: streamOptions + user: + type: string + description: | + A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids) + example: user-1234 + CreateModerationResponseCategories: + required: + - harassment + - harassment/threatening + - hate + - hate/threatening + - self-harm + - self-harm/instructions + - self-harm/intent + - sexual + - sexual/minors + - violence + - violence/graphic + type: object + properties: + self-harm/intent: + type: boolean + description: "Content where the speaker expresses that they are engaging\ + \ or intend to engage in acts of self-harm, such as suicide, cutting,\ + \ and eating disorders" + x-ballerina-name: selfHarmIntent + hate/threatening: + type: boolean + description: "Hateful content that also includes violence or serious harm\ + \ towards the targeted group based on race, gender, ethnicity, religion,\ + \ nationality, sexual orientation, disability status, or caste" + x-ballerina-name: hateThreatening + self-harm/instructions: + type: boolean + description: "Content that encourages performing acts of self-harm, such\ + \ as suicide, cutting, and eating disorders, or that gives instructions\ + \ or advice on how to commit such acts" + x-ballerina-name: selfHarmInstructions + sexual/minors: + type: boolean + description: Sexual content that includes an individual who is under 18 + years old + x-ballerina-name: sexualMinors + harassment/threatening: + type: boolean + description: Harassment content that also includes violence or serious harm + towards any target + x-ballerina-name: harassmentThreatening + hate: + type: boolean + description: "Content that expresses, incites, or promotes hate based on\ + \ race, gender, ethnicity, religion, nationality, sexual orientation,\ + \ disability status, or caste. Hateful content aimed at non-protected\ + \ groups (e.g., chess players) is harassment" + self-harm: + type: boolean + description: "Content that promotes, encourages, or depicts acts of self-harm,\ + \ such as suicide, cutting, and eating disorders" + x-ballerina-name: selfHarm + harassment: + type: boolean + description: "Content that expresses, incites, or promotes harassing language\ + \ towards any target" + sexual: + type: boolean + description: "Content meant to arouse sexual excitement, such as the description\ + \ of sexual activity, or that promotes sexual services (excluding sex\ + \ education and wellness)" + violence/graphic: + type: boolean + description: "Content that depicts death, violence, or physical injury in\ + \ graphic detail" + x-ballerina-name: violenceGraphic + violence: + type: boolean + description: "Content that depicts death, violence, or physical injury" + description: "A list of the categories, and whether they are flagged or not" + RunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventOneOf1234567: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunObject' + event: + type: string + enum: + - thread.run.failed + description: "Occurs when a [run](/docs/api-reference/runs/object) fails" + x-oaiMeta: + dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" + ModifyAssistantRequestToolResources: + type: object + properties: + code_interpreter: + allOf: + - $ref: '#/components/schemas/ModifyAssistantRequestToolResourcesCodeInterpreter' + x-ballerina-name: codeInterpreter + file_search: + allOf: + - $ref: '#/components/schemas/ModifyAssistantRequestToolResourcesFileSearch' + x-ballerina-name: fileSearch + description: | + A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs + nullable: true + MessageDeltaContentTextObjectTextAnnotations: + oneOf: + - $ref: '#/components/schemas/MessageDeltaContentTextAnnotationsFileCitationObject' + - $ref: '#/components/schemas/MessageDeltaContentTextAnnotationsFilePathObject' + x-oaiExpandable: true + RunStepDeltaStepDetailsToolCallsCodeOutputImageObject: + title: Code interpreter image output + required: + - index + - type + type: object + properties: + image: + $ref: '#/components/schemas/RunStepDeltaStepDetailsToolCallsCodeOutputImageObjectImage' + index: + type: integer + description: The index of the output in the outputs array + type: + type: string + description: Always `image` + enum: + - image + MessageDeltaObjectDelta: + type: object + properties: + role: + type: string + description: The entity that produced the message. One of `user` or `assistant` + enum: + - user + - assistant + content: + type: array + description: The content of the message in array of text and/or images + items: + $ref: '#/components/schemas/MessageDeltaObjectDeltaContent' + description: The delta containing the fields that have changed on the Message + CompletionUsage: + required: + - completion_tokens + - prompt_tokens + - total_tokens + type: object + properties: + completion_tokens: + type: integer + description: Number of tokens in the generated completion + x-ballerina-name: completionTokens + prompt_tokens: + type: integer + description: Number of tokens in the prompt + x-ballerina-name: promptTokens + total_tokens: + type: integer + description: Total number of tokens used in the request (prompt + completion) + x-ballerina-name: totalTokens + description: Usage statistics for the completion request + FinetuneCompletionRequestInput: + type: object + properties: + completion: + type: string + description: The desired completion for this training example + prompt: + type: string + description: The input prompt for this training example + description: The per-line training example of a fine-tuning input file for completions + models + x-oaiMeta: + name: Training format for completions models + example: | + { + "prompt": "What is the answer to 2+2", + "completion": "4" + } + RunToolCallObject: + required: + - function + - id + - type + type: object + properties: + function: + $ref: '#/components/schemas/RunToolCallObjectFunction' + id: + type: string + description: "The ID of the tool call. This ID must be referenced when you\ + \ submit the tool outputs in using the [Submit tool outputs to run](/docs/api-reference/runs/submitToolOutputs)\ + \ endpoint" + type: + type: string + description: "The type of tool call the output is required for. For now,\ + \ this is always `function`" + enum: + - function + description: Tool call objects + RunStepDetailsToolCallsObject: + title: Tool calls + required: + - tool_calls + - type + type: object + properties: + tool_calls: + type: array + description: | + An array of tool calls the run step was involved in. These can be associated with one of three types of tools: `code_interpreter`, `file_search`, or `function` + items: + $ref: '#/components/schemas/RunStepDetailsToolCallsObjectToolCalls' + x-ballerina-name: toolCalls + type: + type: string + description: Always `tool_calls` + enum: + - tool_calls + description: Details of the tool call + VectorStoreObject: + title: Vector store + required: + - created_at + - file_counts + - id + - last_active_at + - metadata + - name + - object + - status + - usage_bytes + type: object + properties: + file_counts: + allOf: + - $ref: '#/components/schemas/VectorStoreObjectFileCounts' + x-ballerina-name: fileCounts + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + expires_at: + type: integer + description: The Unix timestamp (in seconds) for when the vector store will + expire + nullable: true + x-ballerina-name: expiresAt + expires_after: + allOf: + - $ref: '#/components/schemas/VectorStoreExpirationAfter' + x-ballerina-name: expiresAfter + last_active_at: + type: integer + description: The Unix timestamp (in seconds) for when the vector store was + last active + nullable: true + x-ballerina-name: lastActiveAt + usage_bytes: + type: integer + description: The total number of bytes used by the files in the vector store + x-ballerina-name: usageBytes + name: + type: string + description: The name of the vector store + created_at: + type: integer + description: The Unix timestamp (in seconds) for when the vector store was + created + x-ballerina-name: createdAt + id: + type: string + description: "The identifier, which can be referenced in API endpoints" + object: + type: string + description: "The object type, which is always `vector_store`" + enum: + - vector_store + status: + type: string + description: "The status of the vector store, which can be either `expired`,\ + \ `in_progress`, or `completed`. A status of `completed` indicates that\ + \ the vector store is ready for use" + enum: + - expired + - in_progress + - completed + description: A vector store is a collection of processed files can be used by + the `file_search` tool + x-oaiMeta: + name: The vector store object + beta: true + example: | + { + "id": "vs_123", + "object": "vector_store", + "created_at": 1698107661, + "usage_bytes": 123456, + "last_active_at": 1698107661, + "name": "my_vector_store", + "status": "completed", + "file_counts": { + "in_progress": 0, + "completed": 100, + "cancelled": 0, + "failed": 0, + "total": 100 + }, + "metadata": {}, + "last_used_at": 1698107661 + } + RunToolCallObjectFunction: + required: + - arguments + - name + type: object + properties: + name: + type: string + description: The name of the function + arguments: + type: string + description: The arguments that the model expects you to pass to the function + description: The function definition + ModifyThreadRequestToolResourcesCodeInterpreter: + type: object + properties: + file_ids: + maxItems: 20 + type: array + description: | + A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool + items: + type: string + default: [] + x-ballerina-name: fileIds + CreateCompletionRequest: + required: + - model + - prompt + type: object + properties: + logit_bias: + type: object + additionalProperties: + type: integer + description: | + Modify the likelihood of specified tokens appearing in the completion. + + Accepts a JSON object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100. You can use this [tokenizer tool](/tokenizer?view=bpe) to convert text to token IDs. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token. + + As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being generated + nullable: true + x-oaiTypeLabel: map + x-ballerina-name: logitBias + seed: + maximum: 9223372036854775807 + minimum: -9223372036854775808 + type: integer + description: | + If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result. - /threads/{thread_id}/runs/{run_id}/submit_tool_outputs: - post: - operationId: submitToolOuputsToRun - tags: - - Assistants - summary: | - When a run has the `status: "requires_action"` and `required_action.type` is `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request. - parameters: - - in: path - name: thread_id - required: true - schema: - type: string - description: The ID of the [thread](/docs/api-reference/threads) to which this run belongs. - - in: path - name: run_id - required: true - schema: - type: string - description: The ID of the run that requires the tool output submission. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/SubmitToolOutputsRunRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/RunObject" - x-oaiMeta: - name: Submit tool outputs to run - group: threads - beta: true - returns: The modified [run](/docs/api-reference/runs/object) object matching the specified ID. - examples: - - title: Default - request: - curl: | - curl https://api.openai.com/v1/threads/thread_123/runs/run_123/submit_tool_outputs \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "tool_outputs": [ - { - "tool_call_id": "call_001", - "output": "70 degrees and sunny." - } - ] - }' - python: | - from openai import OpenAI - client = OpenAI() - - run = client.beta.threads.runs.submit_tool_outputs( - thread_id="thread_123", - run_id="run_123", - tool_outputs=[ - { - "tool_call_id": "call_001", - "output": "70 degrees and sunny." - } - ] - ) - - print(run) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const run = await openai.beta.threads.runs.submitToolOutputs( - "thread_123", - "run_123", - { - tool_outputs: [ - { - tool_call_id: "call_001", - output: "70 degrees and sunny.", - }, - ], - } - ); - - console.log(run); - } - - main(); - response: | - { - "id": "run_123", - "object": "thread.run", - "created_at": 1699075592, - "assistant_id": "asst_123", - "thread_id": "thread_123", - "status": "queued", - "started_at": 1699075592, - "expires_at": 1699076192, - "cancelled_at": null, - "failed_at": null, - "completed_at": null, - "last_error": null, - "model": "gpt-4-turbo", - "instructions": null, - "tools": [ - { - "type": "function", - "function": { - "name": "get_current_weather", - "description": "Get the current weather in a given location", - "parameters": { - "type": "object", - "properties": { - "location": { - "type": "string", - "description": "The city and state, e.g. San Francisco, CA" - }, - "unit": { - "type": "string", - "enum": ["celsius", "fahrenheit"] - } - }, - "required": ["location"] - } - } - } - ], - "metadata": {}, - "usage": null, - "temperature": 1.0, - "top_p": 1.0, - "max_prompt_tokens": 1000, - "max_completion_tokens": 1000, - "truncation_strategy": { - "type": "auto", - "last_messages": null - }, - "response_format": "auto", - "tool_choice": "auto", - "parallel_tool_calls": true - } + Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend + nullable: true + max_tokens: + minimum: 0 + type: integer + description: | + The maximum number of [tokens](/tokenizer) that can be generated in the completion. + + The token count of your prompt plus `max_tokens` cannot exceed the model's context length. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens + nullable: true + example: 16 + default: 16 + x-ballerina-name: maxTokens + presence_penalty: + maximum: 2 + minimum: -2 + type: number + description: | + Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. + + [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) + nullable: true + default: 0 + x-ballerina-name: presencePenalty + echo: + type: boolean + description: | + Echo back the prompt in addition to the completion + nullable: true + default: false + suffix: + type: string + description: | + The suffix that comes after a completion of inserted text. + + This parameter is only supported for `gpt-3.5-turbo-instruct` + nullable: true + example: test. + "n": + maximum: 128 + minimum: 1 + type: integer + description: | + How many completions to generate for each prompt. + + **Note:** Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop` + nullable: true + example: 1 + default: 1 + logprobs: + maximum: 5 + minimum: 0 + type: integer + description: | + Include the log probabilities on the `logprobs` most likely output tokens, as well the chosen tokens. For example, if `logprobs` is 5, the API will return a list of the 5 most likely tokens. The API will always return the `logprob` of the sampled token, so there may be up to `logprobs+1` elements in the response. + + The maximum value for `logprobs` is 5 + nullable: true + top_p: + maximum: 1 + minimum: 0 + type: number + description: | + An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + + We generally recommend altering this or `temperature` but not both + nullable: true + example: 1 + default: 1 + x-ballerina-name: topP + frequency_penalty: + maximum: 2 + minimum: -2 + type: number + description: | + Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. + + [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) + nullable: true + default: 0 + x-ballerina-name: frequencyPenalty + best_of: + maximum: 20 + minimum: 0 + type: integer + description: | + Generates `best_of` completions server-side and returns the "best" (the one with the highest log probability per token). Results cannot be streamed. - - title: Streaming - request: - curl: | - curl https://api.openai.com/v1/threads/thread_123/runs/run_123/submit_tool_outputs \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "tool_outputs": [ - { - "tool_call_id": "call_001", - "output": "70 degrees and sunny." - } - ], - "stream": true - }' - python: | - from openai import OpenAI - client = OpenAI() - - stream = client.beta.threads.runs.submit_tool_outputs( - thread_id="thread_123", - run_id="run_123", - tool_outputs=[ - { - "tool_call_id": "call_001", - "output": "70 degrees and sunny." - } - ], - stream=True - ) - - for event in stream: - print(event) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const stream = await openai.beta.threads.runs.submitToolOutputs( - "thread_123", - "run_123", - { - tool_outputs: [ - { - tool_call_id: "call_001", - output: "70 degrees and sunny.", - }, - ], - } - ); - - for await (const event of stream) { - console.log(event); - } - } - - main(); - response: | - event: thread.run.step.completed - data: {"id":"step_001","object":"thread.run.step","created_at":1710352449,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"tool_calls","status":"completed","cancelled_at":null,"completed_at":1710352475,"expires_at":1710353047,"failed_at":null,"last_error":null,"step_details":{"type":"tool_calls","tool_calls":[{"id":"call_iWr0kQ2EaYMaxNdl0v3KYkx7","type":"function","function":{"name":"get_current_weather","arguments":"{\"location\":\"San Francisco, CA\",\"unit\":\"fahrenheit\"}","output":"70 degrees and sunny."}}]},"usage":{"prompt_tokens":291,"completion_tokens":24,"total_tokens":315}} - - event: thread.run.queued - data: {"id":"run_123","object":"thread.run","created_at":1710352447,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":1710352448,"expires_at":1710353047,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} - - event: thread.run.in_progress - data: {"id":"run_123","object":"thread.run","created_at":1710352447,"assistant_id":"asst_123","thread_id":"thread_123","status":"in_progress","started_at":1710352475,"expires_at":1710353047,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":null,"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} - - event: thread.run.step.created - data: {"id":"step_002","object":"thread.run.step","created_at":1710352476,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710353047,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_002"}},"usage":null} - - event: thread.run.step.in_progress - data: {"id":"step_002","object":"thread.run.step","created_at":1710352476,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"in_progress","cancelled_at":null,"completed_at":null,"expires_at":1710353047,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_002"}},"usage":null} - - event: thread.message.created - data: {"id":"msg_002","object":"thread.message","created_at":1710352476,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"in_progress","incomplete_details":null,"incomplete_at":null,"completed_at":null,"role":"assistant","content":[],"metadata":{}} - - event: thread.message.in_progress - data: {"id":"msg_002","object":"thread.message","created_at":1710352476,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"in_progress","incomplete_details":null,"incomplete_at":null,"completed_at":null,"role":"assistant","content":[],"metadata":{}} - - event: thread.message.delta - data: {"id":"msg_002","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":"The","annotations":[]}}]}} - - event: thread.message.delta - data: {"id":"msg_002","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":" current"}}]}} - - event: thread.message.delta - data: {"id":"msg_002","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":" weather"}}]}} - - ... - - event: thread.message.delta - data: {"id":"msg_002","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":" sunny"}}]}} - - event: thread.message.delta - data: {"id":"msg_002","object":"thread.message.delta","delta":{"content":[{"index":0,"type":"text","text":{"value":"."}}]}} - - event: thread.message.completed - data: {"id":"msg_002","object":"thread.message","created_at":1710352476,"assistant_id":"asst_123","thread_id":"thread_123","run_id":"run_123","status":"completed","incomplete_details":null,"incomplete_at":null,"completed_at":1710352477,"role":"assistant","content":[{"type":"text","text":{"value":"The current weather in San Francisco, CA is 70 degrees Fahrenheit and sunny.","annotations":[]}}],"metadata":{}} - - event: thread.run.step.completed - data: {"id":"step_002","object":"thread.run.step","created_at":1710352476,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"message_creation","status":"completed","cancelled_at":null,"completed_at":1710352477,"expires_at":1710353047,"failed_at":null,"last_error":null,"step_details":{"type":"message_creation","message_creation":{"message_id":"msg_002"}},"usage":{"prompt_tokens":329,"completion_tokens":18,"total_tokens":347}} - - event: thread.run.completed - data: {"id":"run_123","object":"thread.run","created_at":1710352447,"assistant_id":"asst_123","thread_id":"thread_123","status":"completed","started_at":1710352475,"expires_at":null,"cancelled_at":null,"failed_at":null,"completed_at":1710352477,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"metadata":{},"temperature":1.0,"top_p":1.0,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":{"prompt_tokens":20,"completion_tokens":11,"total_tokens":31},"response_format":"auto","tool_choice":"auto","parallel_tool_calls":true}} - - event: done - data: [DONE] - - /threads/{thread_id}/runs/{run_id}/cancel: - post: - operationId: cancelRun - tags: - - Assistants - summary: Cancels a run that is `in_progress`. - parameters: - - in: path - name: thread_id - required: true - schema: - type: string - description: The ID of the thread to which this run belongs. - - in: path - name: run_id - required: true - schema: - type: string - description: The ID of the run to cancel. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/RunObject" - x-oaiMeta: - name: Cancel a run - group: threads - beta: true - returns: The modified [run](/docs/api-reference/runs/object) object matching the specified ID. - examples: - request: - curl: | - curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/cancel \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "OpenAI-Beta: assistants=v2" \ - -X POST - python: | - from openai import OpenAI - client = OpenAI() - - run = client.beta.threads.runs.cancel( - thread_id="thread_abc123", - run_id="run_abc123" - ) - - print(run) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const run = await openai.beta.threads.runs.cancel( - "thread_abc123", - "run_abc123" - ); - - console.log(run); - } + When used with `n`, `best_of` controls the number of candidate completions and `n` specifies how many to return – `best_of` must be greater than `n`. - main(); - response: | - { - "id": "run_abc123", - "object": "thread.run", - "created_at": 1699076126, - "assistant_id": "asst_abc123", - "thread_id": "thread_abc123", - "status": "cancelling", - "started_at": 1699076126, - "expires_at": 1699076726, - "cancelled_at": null, - "failed_at": null, - "completed_at": null, - "last_error": null, - "model": "gpt-4-turbo", - "instructions": "You summarize books.", - "tools": [ - { - "type": "file_search" - } - ], - "tool_resources": { - "file_search": { - "vector_store_ids": ["vs_123"] - } - }, - "metadata": {}, - "usage": null, - "temperature": 1.0, - "top_p": 1.0, - "response_format": "auto", - "tool_choice": "auto", - "parallel_tool_calls": true - } - - /threads/{thread_id}/runs/{run_id}/steps: - get: - operationId: listRunSteps - tags: - - Assistants - summary: Returns a list of run steps belonging to a run. - parameters: - - name: thread_id - in: path - required: true - schema: - type: string - description: The ID of the thread the run and run steps belong to. - - name: run_id - in: path - required: true - schema: - type: string - description: The ID of the run the run steps belong to. - - name: limit - in: query - description: *pagination_limit_param_description - required: false - schema: - type: integer - default: 20 - - name: order - in: query - description: *pagination_order_param_description - schema: - type: string - default: desc - enum: ["asc", "desc"] - - name: after - in: query - description: *pagination_after_param_description - schema: - type: string - - name: before - in: query - description: *pagination_before_param_description - schema: - type: string - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ListRunStepsResponse" - x-oaiMeta: - name: List run steps - group: threads - beta: true - returns: A list of [run step](/docs/api-reference/runs/step-object) objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/steps \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" - python: | - from openai import OpenAI - client = OpenAI() - - run_steps = client.beta.threads.runs.steps.list( - thread_id="thread_abc123", - run_id="run_abc123" - ) - - print(run_steps) - node.js: | - import OpenAI from "openai"; - const openai = new OpenAI(); - - async function main() { - const runStep = await openai.beta.threads.runs.steps.list( - "thread_abc123", - "run_abc123" - ); - console.log(runStep); - } - - main(); - response: | - { - "object": "list", - "data": [ - { - "id": "step_abc123", - "object": "thread.run.step", - "created_at": 1699063291, - "run_id": "run_abc123", - "assistant_id": "asst_abc123", - "thread_id": "thread_abc123", - "type": "message_creation", - "status": "completed", - "cancelled_at": null, - "completed_at": 1699063291, - "expired_at": null, - "failed_at": null, - "last_error": null, - "step_details": { - "type": "message_creation", - "message_creation": { - "message_id": "msg_abc123" - } - }, - "usage": { - "prompt_tokens": 123, - "completion_tokens": 456, - "total_tokens": 579 - } - } - ], - "first_id": "step_abc123", - "last_id": "step_abc456", - "has_more": false - } - - /threads/{thread_id}/runs/{run_id}/steps/{step_id}: - get: - operationId: getRunStep - tags: - - Assistants - summary: Retrieves a run step. - parameters: - - in: path - name: thread_id - required: true - schema: - type: string - description: The ID of the thread to which the run and run step belongs. - - in: path - name: run_id - required: true - schema: - type: string - description: The ID of the run to which the run step belongs. - - in: path - name: step_id - required: true - schema: - type: string - description: The ID of the run step to retrieve. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/RunStepObject" - x-oaiMeta: - name: Retrieve run step - group: threads - beta: true - returns: The [run step](/docs/api-reference/runs/step-object) object matching the specified ID. - examples: - request: - curl: | - curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/steps/step_abc123 \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" - python: | - from openai import OpenAI - client = OpenAI() - - run_step = client.beta.threads.runs.steps.retrieve( - thread_id="thread_abc123", - run_id="run_abc123", - step_id="step_abc123" - ) - - print(run_step) - node.js: | - import OpenAI from "openai"; - const openai = new OpenAI(); - - async function main() { - const runStep = await openai.beta.threads.runs.steps.retrieve( - "thread_abc123", - "run_abc123", - "step_abc123" - ); - console.log(runStep); - } - - main(); - response: &run_step_object_example | - { - "id": "step_abc123", - "object": "thread.run.step", - "created_at": 1699063291, - "run_id": "run_abc123", - "assistant_id": "asst_abc123", - "thread_id": "thread_abc123", - "type": "message_creation", - "status": "completed", - "cancelled_at": null, - "completed_at": 1699063291, - "expired_at": null, - "failed_at": null, - "last_error": null, - "step_details": { - "type": "message_creation", - "message_creation": { - "message_id": "msg_abc123" - } - }, - "usage": { - "prompt_tokens": 123, - "completion_tokens": 456, - "total_tokens": 579 - } - } - - /vector_stores: - get: - operationId: listVectorStores - tags: - - Vector Stores - summary: Returns a list of vector stores. - parameters: - - name: limit - in: query - description: *pagination_limit_param_description - required: false - schema: - type: integer - default: 20 - - name: order - in: query - description: *pagination_order_param_description - schema: - type: string - default: desc - enum: ["asc", "desc"] - - name: after - in: query - description: *pagination_after_param_description - schema: - type: string - - name: before - in: query - description: *pagination_before_param_description - schema: - type: string - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ListVectorStoresResponse" - x-oaiMeta: - name: List vector stores - group: vector_stores - beta: true - returns: A list of [vector store](/docs/api-reference/vector-stores/object) objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/vector_stores \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" - python: | - from openai import OpenAI - client = OpenAI() - - vector_stores = client.beta.vector_stores.list() - print(vector_stores) - node.js: | - import OpenAI from "openai"; - const openai = new OpenAI(); - - async function main() { - const vectorStores = await openai.beta.vectorStores.list(); - console.log(vectorStores); - } - - main(); - response: | - { - "object": "list", - "data": [ - { - "id": "vs_abc123", - "object": "vector_store", - "created_at": 1699061776, - "name": "Support FAQ", - "bytes": 139920, - "file_counts": { - "in_progress": 0, - "completed": 3, - "failed": 0, - "cancelled": 0, - "total": 3 - } - }, - { - "id": "vs_abc456", - "object": "vector_store", - "created_at": 1699061776, - "name": "Support FAQ v2", - "bytes": 139920, - "file_counts": { - "in_progress": 0, - "completed": 3, - "failed": 0, - "cancelled": 0, - "total": 3 - } - } - ], - "first_id": "vs_abc123", - "last_id": "vs_abc456", - "has_more": false - } - post: - operationId: createVectorStore - tags: - - Vector Stores - summary: Create a vector store. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateVectorStoreRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/VectorStoreObject" - x-oaiMeta: - name: Create vector store - group: vector_stores - beta: true - returns: A [vector store](/docs/api-reference/vector-stores/object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/vector_stores \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" - -d '{ - "name": "Support FAQ" - }' - python: | - from openai import OpenAI - client = OpenAI() - - vector_store = client.beta.vector_stores.create( - name="Support FAQ" - ) - print(vector_store) - node.js: | - import OpenAI from "openai"; - const openai = new OpenAI(); - - async function main() { - const vectorStore = await openai.beta.vectorStores.create({ - name: "Support FAQ" - }); - console.log(vectorStore); - } - - main(); - response: | - { - "id": "vs_abc123", - "object": "vector_store", - "created_at": 1699061776, - "name": "Support FAQ", - "bytes": 139920, - "file_counts": { - "in_progress": 0, - "completed": 3, - "failed": 0, - "cancelled": 0, - "total": 3 - } - } - - /vector_stores/{vector_store_id}: - get: - operationId: getVectorStore - tags: - - Vector Stores - summary: Retrieves a vector store. - parameters: - - in: path - name: vector_store_id - required: true - schema: - type: string - description: The ID of the vector store to retrieve. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/VectorStoreObject" - x-oaiMeta: - name: Retrieve vector store - group: vector_stores - beta: true - returns: The [vector store](/docs/api-reference/vector-stores/object) object matching the specified ID. - examples: - request: - curl: | - curl https://api.openai.com/v1/vector_stores/vs_abc123 \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" - python: | - from openai import OpenAI - client = OpenAI() - - vector_store = client.beta.vector_stores.retrieve( - vector_store_id="vs_abc123" - ) - print(vector_store) - node.js: | - import OpenAI from "openai"; - const openai = new OpenAI(); - - async function main() { - const vectorStore = await openai.beta.vectorStores.retrieve( - "vs_abc123" - ); - console.log(vectorStore); - } - - main(); - response: | - { - "id": "vs_abc123", - "object": "vector_store", - "created_at": 1699061776 - } - post: - operationId: modifyVectorStore - tags: - - Vector Stores - summary: Modifies a vector store. - parameters: - - in: path - name: vector_store_id - required: true - schema: - type: string - description: The ID of the vector store to modify. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/UpdateVectorStoreRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/VectorStoreObject" - x-oaiMeta: - name: Modify vector store - group: vector_stores - beta: true - returns: The modified [vector store](/docs/api-reference/vector-stores/object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/vector_stores/vs_abc123 \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" - -d '{ - "name": "Support FAQ" - }' - python: | - from openai import OpenAI - client = OpenAI() - - vector_store = client.beta.vector_stores.update( - vector_store_id="vs_abc123", - name="Support FAQ" - ) - print(vector_store) - node.js: | - import OpenAI from "openai"; - const openai = new OpenAI(); - - async function main() { - const vectorStore = await openai.beta.vectorStores.update( - "vs_abc123", - { - name: "Support FAQ" - } - ); - console.log(vectorStore); - } - - main(); - response: | - { - "id": "vs_abc123", - "object": "vector_store", - "created_at": 1699061776, - "name": "Support FAQ", - "bytes": 139920, - "file_counts": { - "in_progress": 0, - "completed": 3, - "failed": 0, - "cancelled": 0, - "total": 3 - } - } - - delete: - operationId: deleteVectorStore - tags: - - Vector Stores - summary: Delete a vector store. - parameters: - - in: path - name: vector_store_id - required: true - schema: - type: string - description: The ID of the vector store to delete. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/DeleteVectorStoreResponse" - x-oaiMeta: - name: Delete vector store - group: vector_stores - beta: true - returns: Deletion status - examples: - request: - curl: | - curl https://api.openai.com/v1/vector_stores/vs_abc123 \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" \ - -X DELETE - python: | - from openai import OpenAI - client = OpenAI() - - deleted_vector_store = client.beta.vector_stores.delete( - vector_store_id="vs_abc123" - ) - print(deleted_vector_store) - node.js: | - import OpenAI from "openai"; - const openai = new OpenAI(); - - async function main() { - const deletedVectorStore = await openai.beta.vectorStores.del( - "vs_abc123" - ); - console.log(deletedVectorStore); - } - - main(); - response: | - { - id: "vs_abc123", - object: "vector_store.deleted", - deleted: true - } - - /vector_stores/{vector_store_id}/files: - get: - operationId: listVectorStoreFiles - tags: - - Vector Stores - summary: Returns a list of vector store files. - parameters: - - name: vector_store_id - in: path - description: The ID of the vector store that the files belong to. - required: true - schema: - type: string - - name: limit - in: query - description: *pagination_limit_param_description - required: false - schema: - type: integer - default: 20 - - name: order - in: query - description: *pagination_order_param_description - schema: - type: string - default: desc - enum: ["asc", "desc"] - - name: after - in: query - description: *pagination_after_param_description - schema: - type: string - - name: before - in: query - description: *pagination_before_param_description - schema: - type: string - - name: filter - in: query - description: "Filter by file status. One of `in_progress`, `completed`, `failed`, `cancelled`." - schema: - type: string - enum: ["in_progress", "completed", "failed", "cancelled"] - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ListVectorStoreFilesResponse" - x-oaiMeta: - name: List vector store files - group: vector_stores - beta: true - returns: A list of [vector store file](/docs/api-reference/vector-stores-files/file-object) objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/vector_stores/vs_abc123/files \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" - python: | - from openai import OpenAI - client = OpenAI() - - vector_store_files = client.beta.vector_stores.files.list( - vector_store_id="vs_abc123" - ) - print(vector_store_files) - node.js: | - import OpenAI from "openai"; - const openai = new OpenAI(); - - async function main() { - const vectorStoreFiles = await openai.beta.vectorStores.files.list( - "vs_abc123" - ); - console.log(vectorStoreFiles); - } - - main(); - response: | - { - "object": "list", - "data": [ - { - "id": "file-abc123", - "object": "vector_store.file", - "created_at": 1699061776, - "vector_store_id": "vs_abc123" - }, - { - "id": "file-abc456", - "object": "vector_store.file", - "created_at": 1699061776, - "vector_store_id": "vs_abc123" - } - ], - "first_id": "file-abc123", - "last_id": "file-abc456", - "has_more": false - } - post: - operationId: createVectorStoreFile - tags: - - Vector Stores - summary: Create a vector store file by attaching a [File](/docs/api-reference/files) to a [vector store](/docs/api-reference/vector-stores/object). - parameters: - - in: path - name: vector_store_id - required: true - schema: - type: string - example: vs_abc123 - description: | - The ID of the vector store for which to create a File. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateVectorStoreFileRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/VectorStoreFileObject" - x-oaiMeta: - name: Create vector store file - group: vector_stores - beta: true - returns: A [vector store file](/docs/api-reference/vector-stores-files/file-object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/vector_stores/vs_abc123/files \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "file_id": "file-abc123" - }' - python: | - from openai import OpenAI - client = OpenAI() - - vector_store_file = client.beta.vector_stores.files.create( - vector_store_id="vs_abc123", - file_id="file-abc123" - ) - print(vector_store_file) - node.js: | - import OpenAI from "openai"; - const openai = new OpenAI(); - - async function main() { - const myVectorStoreFile = await openai.beta.vectorStores.files.create( - "vs_abc123", - { - file_id: "file-abc123" - } - ); - console.log(myVectorStoreFile); - } - - main(); - response: | - { - "id": "file-abc123", - "object": "vector_store.file", - "created_at": 1699061776, - "usage_bytes": 1234, - "vector_store_id": "vs_abcd", - "status": "completed", - "last_error": null - } - - /vector_stores/{vector_store_id}/files/{file_id}: - get: - operationId: getVectorStoreFile - tags: - - Vector Stores - summary: Retrieves a vector store file. - parameters: - - in: path - name: vector_store_id - required: true - schema: - type: string - example: vs_abc123 - description: The ID of the vector store that the file belongs to. - - in: path - name: file_id - required: true - schema: - type: string - example: file-abc123 - description: The ID of the file being retrieved. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/VectorStoreFileObject" - x-oaiMeta: - name: Retrieve vector store file - group: vector_stores - beta: true - returns: The [vector store file](/docs/api-reference/vector-stores-files/file-object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/vector_stores/vs_abc123/files/file-abc123 \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" - python: | - from openai import OpenAI - client = OpenAI() - - vector_store_file = client.beta.vector_stores.files.retrieve( - vector_store_id="vs_abc123", - file_id="file-abc123" - ) - print(vector_store_file) - node.js: | - import OpenAI from "openai"; - const openai = new OpenAI(); - - async function main() { - const vectorStoreFile = await openai.beta.vectorStores.files.retrieve( - "vs_abc123", - "file-abc123" - ); - console.log(vectorStoreFile); - } - - main(); - response: | - { - "id": "file-abc123", - "object": "vector_store.file", - "created_at": 1699061776, - "vector_store_id": "vs_abcd", - "status": "completed", - "last_error": null - } - delete: - operationId: deleteVectorStoreFile - tags: - - Vector Stores - summary: Delete a vector store file. This will remove the file from the vector store but the file itself will not be deleted. To delete the file, use the [delete file](/docs/api-reference/files/delete) endpoint. - parameters: - - in: path - name: vector_store_id - required: true - schema: - type: string - description: The ID of the vector store that the file belongs to. - - in: path - name: file_id - required: true - schema: - type: string - description: The ID of the file to delete. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/DeleteVectorStoreFileResponse" - x-oaiMeta: - name: Delete vector store file - group: vector_stores - beta: true - returns: Deletion status - examples: - request: - curl: | - curl https://api.openai.com/v1/vector_stores/vs_abc123/files/file-abc123 \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" \ - -X DELETE - python: | - from openai import OpenAI - client = OpenAI() - - deleted_vector_store_file = client.beta.vector_stores.files.delete( - vector_store_id="vs_abc123", - file_id="file-abc123" - ) - print(deleted_vector_store_file) - node.js: | - import OpenAI from "openai"; - const openai = new OpenAI(); - - async function main() { - const deletedVectorStoreFile = await openai.beta.vectorStores.files.del( - "vs_abc123", - "file-abc123" - ); - console.log(deletedVectorStoreFile); - } - - main(); - response: | - { - id: "file-abc123", - object: "vector_store.file.deleted", - deleted: true - } - - /vector_stores/{vector_store_id}/file_batches: - post: - operationId: createVectorStoreFileBatch - tags: - - Vector Stores - summary: Create a vector store file batch. - parameters: - - in: path - name: vector_store_id - required: true - schema: - type: string - example: vs_abc123 - description: | - The ID of the vector store for which to create a File Batch. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateVectorStoreFileBatchRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/VectorStoreFileBatchObject" - x-oaiMeta: - name: Create vector store file batch - group: vector_stores - beta: true - returns: A [vector store file batch](/docs/api-reference/vector-stores-file-batches/batch-object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/vector_stores/vs_abc123/file_batches \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json \ - -H "OpenAI-Beta: assistants=v2" \ - -d '{ - "file_ids": ["file-abc123", "file-abc456"] - }' - python: | - from openai import OpenAI - client = OpenAI() - - vector_store_file_batch = client.beta.vector_stores.file_batches.create( - vector_store_id="vs_abc123", - file_ids=["file-abc123", "file-abc456"] - ) - print(vector_store_file_batch) - node.js: | - import OpenAI from "openai"; - const openai = new OpenAI(); - - async function main() { - const myVectorStoreFileBatch = await openai.beta.vectorStores.fileBatches.create( - "vs_abc123", - { - file_ids: ["file-abc123", "file-abc456"] - } - ); - console.log(myVectorStoreFileBatch); - } - - main(); - response: | - { - "id": "vsfb_abc123", - "object": "vector_store.file_batch", - "created_at": 1699061776, - "vector_store_id": "vs_abc123", - "status": "in_progress", - "file_counts": { - "in_progress": 1, - "completed": 1, - "failed": 0, - "cancelled": 0, - "total": 0, - } - } - - /vector_stores/{vector_store_id}/file_batches/{batch_id}: - get: - operationId: getVectorStoreFileBatch - tags: - - Vector Stores - summary: Retrieves a vector store file batch. - parameters: - - in: path - name: vector_store_id - required: true - schema: - type: string - example: vs_abc123 - description: The ID of the vector store that the file batch belongs to. - - in: path - name: batch_id - required: true - schema: - type: string - example: vsfb_abc123 - description: The ID of the file batch being retrieved. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/VectorStoreFileBatchObject" - x-oaiMeta: - name: Retrieve vector store file batch - group: vector_stores - beta: true - returns: The [vector store file batch](/docs/api-reference/vector-stores-file-batches/batch-object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/vector_stores/vs_abc123/files_batches/vsfb_abc123 \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" - python: | - from openai import OpenAI - client = OpenAI() - - vector_store_file_batch = client.beta.vector_stores.file_batches.retrieve( - vector_store_id="vs_abc123", - batch_id="vsfb_abc123" - ) - print(vector_store_file_batch) - node.js: | - import OpenAI from "openai"; - const openai = new OpenAI(); - - async function main() { - const vectorStoreFileBatch = await openai.beta.vectorStores.fileBatches.retrieve( - "vs_abc123", - "vsfb_abc123" - ); - console.log(vectorStoreFileBatch); - } - - main(); - response: | - { - "id": "vsfb_abc123", - "object": "vector_store.file_batch", - "created_at": 1699061776, - "vector_store_id": "vs_abc123", - "status": "in_progress", - "file_counts": { - "in_progress": 1, - "completed": 1, - "failed": 0, - "cancelled": 0, - "total": 0, - } - } - - /vector_stores/{vector_store_id}/file_batches/{batch_id}/cancel: - post: - operationId: cancelVectorStoreFileBatch - tags: - - Vector Stores - summary: Cancel a vector store file batch. This attempts to cancel the processing of files in this batch as soon as possible. - parameters: - - in: path - name: vector_store_id - required: true - schema: - type: string - description: The ID of the vector store that the file batch belongs to. - - in: path - name: batch_id - required: true - schema: - type: string - description: The ID of the file batch to cancel. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/VectorStoreFileBatchObject" - x-oaiMeta: - name: Cancel vector store file batch - group: vector_stores - beta: true - returns: The modified vector store file batch object. - examples: - request: - curl: | - curl https://api.openai.com/v1/vector_stores/vs_abc123/files_batches/vsfb_abc123/cancel \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" \ - -X POST - python: | - from openai import OpenAI - client = OpenAI() - - deleted_vector_store_file_batch = client.beta.vector_stores.file_batches.cancel( - vector_store_id="vs_abc123", - file_batch_id="vsfb_abc123" - ) - print(deleted_vector_store_file_batch) - node.js: | - import OpenAI from "openai"; - const openai = new OpenAI(); - - async function main() { - const deletedVectorStoreFileBatch = await openai.vector_stores.fileBatches.cancel( - "vs_abc123", - "vsfb_abc123" - ); - console.log(deletedVectorStoreFileBatch); - } - - main(); - response: | - { - "id": "vsfb_abc123", - "object": "vector_store.file_batch", - "created_at": 1699061776, - "vector_store_id": "vs_abc123", - "status": "cancelling", - "file_counts": { - "in_progress": 12, - "completed": 3, - "failed": 0, - "cancelled": 0, - "total": 15, - } - } - - /vector_stores/{vector_store_id}/file_batches/{batch_id}/files: - get: - operationId: listFilesInVectorStoreBatch - tags: - - Vector Stores - summary: Returns a list of vector store files in a batch. - parameters: - - name: vector_store_id - in: path - description: The ID of the vector store that the files belong to. - required: true - schema: - type: string - - name: batch_id - in: path - description: The ID of the file batch that the files belong to. - required: true - schema: - type: string - - name: limit - in: query - description: *pagination_limit_param_description - required: false - schema: - type: integer - default: 20 - - name: order - in: query - description: *pagination_order_param_description - schema: - type: string - default: desc - enum: ["asc", "desc"] - - name: after - in: query - description: *pagination_after_param_description - schema: - type: string - - name: before - in: query - description: *pagination_before_param_description - schema: - type: string - - name: filter - in: query - description: "Filter by file status. One of `in_progress`, `completed`, `failed`, `cancelled`." - schema: - type: string - enum: ["in_progress", "completed", "failed", "cancelled"] - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ListVectorStoreFilesResponse" - x-oaiMeta: - name: List vector store files in a batch - group: vector_stores - beta: true - returns: A list of [vector store file](/docs/api-reference/vector-stores-files/file-object) objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/vector_stores/vs_abc123/files_batches/vsfb_abc123/files \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -H "OpenAI-Beta: assistants=v2" - python: | - from openai import OpenAI - client = OpenAI() - - vector_store_files = client.beta.vector_stores.file_batches.list_files( - vector_store_id="vs_abc123", - batch_id="vsfb_abc123" - ) - print(vector_store_files) - node.js: | - import OpenAI from "openai"; - const openai = new OpenAI(); - - async function main() { - const vectorStoreFiles = await openai.beta.vectorStores.fileBatches.listFiles( - "vs_abc123", - "vsfb_abc123" - ); - console.log(vectorStoreFiles); - } - - main(); - response: | - { - "object": "list", - "data": [ - { - "id": "file-abc123", - "object": "vector_store.file", - "created_at": 1699061776, - "vector_store_id": "vs_abc123" - }, - { - "id": "file-abc456", - "object": "vector_store.file", - "created_at": 1699061776, - "vector_store_id": "vs_abc123" - } - ], - "first_id": "file-abc123", - "last_id": "file-abc456", - "has_more": false - } - - /batches: - post: - summary: Creates and executes a batch from an uploaded file of requests - operationId: createBatch - tags: - - Batch - requestBody: - required: true - content: - application/json: - schema: - type: object - required: - - input_file_id - - endpoint - - completion_window - properties: - input_file_id: - type: string - description: | - The ID of an uploaded file that contains requests for the new batch. - - See [upload file](/docs/api-reference/files/create) for how to upload a file. - - Your input file must be formatted as a [JSONL file](/docs/api-reference/batch/request-input), and must be uploaded with the purpose `batch`. The file can contain up to 50,000 requests, and can be up to 100 MB in size. - endpoint: - type: string - enum: - [ - "/v1/chat/completions", - "/v1/embeddings", - "/v1/completions", - ] - description: The endpoint to be used for all requests in the batch. Currently `/v1/chat/completions`, `/v1/embeddings`, and `/v1/completions` are supported. Note that `/v1/embeddings` batches are also restricted to a maximum of 50,000 embedding inputs across all requests in the batch. - completion_window: - type: string - enum: ["24h"] - description: The time frame within which the batch should be processed. Currently only `24h` is supported. - metadata: - type: object - additionalProperties: - type: string - description: Optional custom metadata for the batch. - nullable: true - responses: - "200": - description: Batch created successfully. - content: - application/json: - schema: - $ref: "#/components/schemas/Batch" - x-oaiMeta: - name: Create batch - group: batch - returns: The created [Batch](/docs/api-reference/batch/object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/batches \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -d '{ - "input_file_id": "file-abc123", - "endpoint": "/v1/chat/completions", - "completion_window": "24h" - }' - python: | - from openai import OpenAI - client = OpenAI() - - client.batches.create( - input_file_id="file-abc123", - endpoint="/v1/chat/completions", - completion_window="24h" - ) - node: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const batch = await openai.batches.create({ - input_file_id: "file-abc123", - endpoint: "/v1/chat/completions", - completion_window: "24h" - }); - - console.log(batch); - } - - main(); - response: | - { - "id": "batch_abc123", - "object": "batch", - "endpoint": "/v1/chat/completions", - "errors": null, - "input_file_id": "file-abc123", - "completion_window": "24h", - "status": "validating", - "output_file_id": null, - "error_file_id": null, - "created_at": 1711471533, - "in_progress_at": null, - "expires_at": null, - "finalizing_at": null, - "completed_at": null, - "failed_at": null, - "expired_at": null, - "cancelling_at": null, - "cancelled_at": null, - "request_counts": { - "total": 0, - "completed": 0, - "failed": 0 - }, - "metadata": { - "customer_id": "user_123456789", - "batch_description": "Nightly eval job", - } - } - get: - operationId: listBatches - tags: - - Batch - summary: List your organization's batches. - parameters: - - in: query - name: after - required: false - schema: - type: string - description: *pagination_after_param_description - - name: limit - in: query - description: *pagination_limit_param_description - required: false - schema: - type: integer - default: 20 - responses: - "200": - description: Batch listed successfully. - content: - application/json: - schema: - $ref: "#/components/schemas/ListBatchesResponse" - x-oaiMeta: - name: List batch - group: batch - returns: A list of paginated [Batch](/docs/api-reference/batch/object) objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/batches?limit=2 \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" - python: | - from openai import OpenAI - client = OpenAI() - - client.batches.list() - node: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const list = await openai.batches.list(); - - for await (const batch of list) { - console.log(batch); - } - } - - main(); - response: | - { - "object": "list", - "data": [ - { - "id": "batch_abc123", - "object": "batch", - "endpoint": "/v1/chat/completions", - "errors": null, - "input_file_id": "file-abc123", - "completion_window": "24h", - "status": "completed", - "output_file_id": "file-cvaTdG", - "error_file_id": "file-HOWS94", - "created_at": 1711471533, - "in_progress_at": 1711471538, - "expires_at": 1711557933, - "finalizing_at": 1711493133, - "completed_at": 1711493163, - "failed_at": null, - "expired_at": null, - "cancelling_at": null, - "cancelled_at": null, - "request_counts": { - "total": 100, - "completed": 95, - "failed": 5 - }, - "metadata": { - "customer_id": "user_123456789", - "batch_description": "Nightly job", - } - }, - { ... }, - ], - "first_id": "batch_abc123", - "last_id": "batch_abc456", - "has_more": true - } - - /batches/{batch_id}: - get: - operationId: retrieveBatch - tags: - - Batch - summary: Retrieves a batch. - parameters: - - in: path - name: batch_id - required: true - schema: - type: string - description: The ID of the batch to retrieve. - responses: - "200": - description: Batch retrieved successfully. - content: - application/json: - schema: - $ref: "#/components/schemas/Batch" - x-oaiMeta: - name: Retrieve batch - group: batch - returns: The [Batch](/docs/api-reference/batch/object) object matching the specified ID. - examples: - request: - curl: | - curl https://api.openai.com/v1/batches/batch_abc123 \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - python: | - from openai import OpenAI - client = OpenAI() - - client.batches.retrieve("batch_abc123") - node: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const batch = await openai.batches.retrieve("batch_abc123"); - - console.log(batch); - } - - main(); - response: &batch_object | - { - "id": "batch_abc123", - "object": "batch", - "endpoint": "/v1/completions", - "errors": null, - "input_file_id": "file-abc123", - "completion_window": "24h", - "status": "completed", - "output_file_id": "file-cvaTdG", - "error_file_id": "file-HOWS94", - "created_at": 1711471533, - "in_progress_at": 1711471538, - "expires_at": 1711557933, - "finalizing_at": 1711493133, - "completed_at": 1711493163, - "failed_at": null, - "expired_at": null, - "cancelling_at": null, - "cancelled_at": null, - "request_counts": { - "total": 100, - "completed": 95, - "failed": 5 - }, - "metadata": { - "customer_id": "user_123456789", - "batch_description": "Nightly eval job", - } - } - - /batches/{batch_id}/cancel: - post: - operationId: cancelBatch - tags: - - Batch - summary: Cancels an in-progress batch. The batch will be in status `cancelling` for up to 10 minutes, before changing to `cancelled`, where it will have partial results (if any) available in the output file. - parameters: - - in: path - name: batch_id - required: true - schema: - type: string - description: The ID of the batch to cancel. - responses: - "200": - description: Batch is cancelling. Returns the cancelling batch's details. - content: - application/json: - schema: - $ref: "#/components/schemas/Batch" - x-oaiMeta: - name: Cancel batch - group: batch - returns: The [Batch](/docs/api-reference/batch/object) object matching the specified ID. - examples: - request: - curl: | - curl https://api.openai.com/v1/batches/batch_abc123/cancel \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -X POST - python: | - from openai import OpenAI - client = OpenAI() - - client.batches.cancel("batch_abc123") - node: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const batch = await openai.batches.cancel("batch_abc123"); - - console.log(batch); - } - - main(); - response: | - { - "id": "batch_abc123", - "object": "batch", - "endpoint": "/v1/chat/completions", - "errors": null, - "input_file_id": "file-abc123", - "completion_window": "24h", - "status": "cancelling", - "output_file_id": null, - "error_file_id": null, - "created_at": 1711471533, - "in_progress_at": 1711471538, - "expires_at": 1711557933, - "finalizing_at": null, - "completed_at": null, - "failed_at": null, - "expired_at": null, - "cancelling_at": 1711475133, - "cancelled_at": null, - "request_counts": { - "total": 100, - "completed": 23, - "failed": 1 - }, - "metadata": { - "customer_id": "user_123456789", - "batch_description": "Nightly eval job", - } - } - -components: - securitySchemes: - ApiKeyAuth: - type: http - scheme: "bearer" - - schemas: - Error: - type: object - properties: - code: - type: string - nullable: true - message: - type: string - nullable: false - param: - type: string - nullable: true - type: - type: string - nullable: false - required: - - type - - message - - param - - code - ErrorResponse: - type: object - properties: - error: - $ref: "#/components/schemas/Error" - required: - - error - - ListModelsResponse: - type: object - properties: - object: - type: string - enum: [list] - data: - type: array - items: - $ref: "#/components/schemas/Model" - required: - - object - - data - DeleteModelResponse: - type: object - properties: - id: - type: string - deleted: - type: boolean - object: - type: string - required: - - id - - object - - deleted - - CreateCompletionRequest: - type: object - properties: - model: - description: &model_description | - ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](/docs/models/overview) for descriptions of them. - anyOf: - - type: string - - type: string - enum: ["gpt-3.5-turbo-instruct", "davinci-002", "babbage-002"] - x-oaiTypeLabel: string - prompt: - description: &completions_prompt_description | - The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays. - - Note that <|endoftext|> is the document separator that the model sees during training, so if a prompt is not specified the model will generate as if from the beginning of a new document. - default: "<|endoftext|>" - nullable: true - oneOf: - - type: string - default: "" - example: "This is a test." - - type: array - items: - type: string - default: "" - example: "This is a test." - - type: array - minItems: 1 - items: - type: integer - example: "[1212, 318, 257, 1332, 13]" - - type: array - minItems: 1 - items: - type: array - minItems: 1 - items: - type: integer - example: "[[1212, 318, 257, 1332, 13]]" - best_of: - type: integer - default: 1 - minimum: 0 - maximum: 20 - nullable: true - description: &completions_best_of_description | - Generates `best_of` completions server-side and returns the "best" (the one with the highest log probability per token). Results cannot be streamed. - - When used with `n`, `best_of` controls the number of candidate completions and `n` specifies how many to return – `best_of` must be greater than `n`. - - **Note:** Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop`. - echo: - type: boolean - default: false - nullable: true - description: &completions_echo_description > - Echo back the prompt in addition to the completion - frequency_penalty: - type: number - default: 0 - minimum: -2 - maximum: 2 - nullable: true - description: &completions_frequency_penalty_description | - Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. - - [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) - logit_bias: &completions_logit_bias - type: object - x-oaiTypeLabel: map - # default: null - nullable: true - additionalProperties: - type: integer - description: &completions_logit_bias_description | - Modify the likelihood of specified tokens appearing in the completion. - - Accepts a JSON object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100. You can use this [tokenizer tool](/tokenizer?view=bpe) to convert text to token IDs. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token. - - As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being generated. - logprobs: &completions_logprobs_configuration - type: integer - minimum: 0 - maximum: 5 - # default: null - nullable: true - description: &completions_logprobs_description | - Include the log probabilities on the `logprobs` most likely output tokens, as well the chosen tokens. For example, if `logprobs` is 5, the API will return a list of the 5 most likely tokens. The API will always return the `logprob` of the sampled token, so there may be up to `logprobs+1` elements in the response. - - The maximum value for `logprobs` is 5. - max_tokens: - type: integer - minimum: 0 - default: 16 - example: 16 - nullable: true - description: &completions_max_tokens_description | - The maximum number of [tokens](/tokenizer) that can be generated in the completion. - - The token count of your prompt plus `max_tokens` cannot exceed the model's context length. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens. - n: - type: integer - minimum: 1 - maximum: 128 - default: 1 - example: 1 - nullable: true - description: &completions_completions_description | - How many completions to generate for each prompt. - - **Note:** Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop`. - presence_penalty: - type: number - default: 0 - minimum: -2 - maximum: 2 - nullable: true - description: &completions_presence_penalty_description | - Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. - - [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) - seed: &completions_seed_param - type: integer - minimum: -9223372036854775808 - maximum: 9223372036854775807 - nullable: true - description: | - If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result. - - Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend. - stop: - description: &completions_stop_description > - Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence. - # default: null - nullable: true - oneOf: - - type: string - default: <|endoftext|> - example: "\n" - nullable: true - - type: array - minItems: 1 - maxItems: 4 - items: - type: string - example: '["\n"]' - stream: - description: > - Whether to stream back partial progress. If set, tokens will be sent as data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) - as they become available, with the stream terminated by a `data: [DONE]` message. [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions). - type: boolean - nullable: true - default: false - stream_options: - $ref: "#/components/schemas/ChatCompletionStreamOptions" - suffix: - description: | - The suffix that comes after a completion of inserted text. - - This parameter is only supported for `gpt-3.5-turbo-instruct`. - # default: null - nullable: true - type: string - example: "test." - temperature: - type: number - minimum: 0 - maximum: 2 - default: 1 - example: 1 - nullable: true - description: &completions_temperature_description | - What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. - - We generally recommend altering this or `top_p` but not both. - top_p: - type: number - minimum: 0 - maximum: 1 - default: 1 - example: 1 - nullable: true - description: &completions_top_p_description | - An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. - - We generally recommend altering this or `temperature` but not both. - user: &end_user_param_configuration - type: string - example: user-1234 - description: | - A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids). - required: - - model - - prompt - - CreateCompletionResponse: - type: object - description: | - Represents a completion response from the API. Note: both the streamed and non-streamed response objects share the same shape (unlike the chat endpoint). - properties: - id: - type: string - description: A unique identifier for the completion. - choices: - type: array - description: The list of completion choices the model generated for the input prompt. - items: - type: object - required: - - finish_reason - - index - - logprobs - - text - properties: - finish_reason: - type: string - description: &completion_finish_reason_description | - The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence, - `length` if the maximum number of tokens specified in the request was reached, - or `content_filter` if content was omitted due to a flag from our content filters. - enum: ["stop", "length", "content_filter"] - index: - type: integer - logprobs: - type: object - nullable: true - properties: - text_offset: - type: array - items: - type: integer - token_logprobs: - type: array - items: - type: number - tokens: - type: array - items: - type: string - top_logprobs: - type: array - items: - type: object - additionalProperties: - type: number - text: - type: string - created: - type: integer - description: The Unix timestamp (in seconds) of when the completion was created. - model: - type: string - description: The model used for completion. - system_fingerprint: - type: string - description: | - This fingerprint represents the backend configuration that the model runs with. - - Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism. - object: - type: string - description: The object type, which is always "text_completion" - enum: [text_completion] - usage: - $ref: "#/components/schemas/CompletionUsage" - required: - - id - - object - - created - - model - - choices - x-oaiMeta: - name: The completion object - legacy: true - example: | - { - "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7", - "object": "text_completion", - "created": 1589478378, - "model": "gpt-4-turbo", - "choices": [ - { - "text": "\n\nThis is indeed a test", - "index": 0, - "logprobs": null, - "finish_reason": "length" - } - ], - "usage": { - "prompt_tokens": 5, - "completion_tokens": 7, - "total_tokens": 12 - } - } - - ChatCompletionRequestMessageContentPart: - oneOf: - - $ref: "#/components/schemas/ChatCompletionRequestMessageContentPartText" - - $ref: "#/components/schemas/ChatCompletionRequestMessageContentPartImage" - x-oaiExpandable: true - - ChatCompletionRequestMessageContentPartImage: - type: object - title: Image content part - properties: - type: - type: string - enum: ["image_url"] - description: The type of the content part. - image_url: - type: object - properties: - url: - type: string - description: Either a URL of the image or the base64 encoded image data. - format: uri - detail: - type: string - description: Specifies the detail level of the image. Learn more in the [Vision guide](/docs/guides/vision/low-or-high-fidelity-image-understanding). - enum: ["auto", "low", "high"] - default: "auto" - required: - - url - required: - - type - - image_url - - ChatCompletionRequestMessageContentPartText: - type: object - title: Text content part - properties: - type: - type: string - enum: ["text"] - description: The type of the content part. - text: - type: string - description: The text content. - required: - - type - - text - - ChatCompletionRequestMessage: - oneOf: - - $ref: "#/components/schemas/ChatCompletionRequestSystemMessage" - - $ref: "#/components/schemas/ChatCompletionRequestUserMessage" - - $ref: "#/components/schemas/ChatCompletionRequestAssistantMessage" - - $ref: "#/components/schemas/ChatCompletionRequestToolMessage" - - $ref: "#/components/schemas/ChatCompletionRequestFunctionMessage" - x-oaiExpandable: true - - ChatCompletionRequestSystemMessage: - type: object - title: System message - properties: - content: - description: The contents of the system message. - type: string - role: - type: string - enum: ["system"] - description: The role of the messages author, in this case `system`. - name: - type: string - description: An optional name for the participant. Provides the model information to differentiate between participants of the same role. - required: - - content - - role - - ChatCompletionRequestUserMessage: - type: object - title: User message - properties: - content: - description: | - The contents of the user message. - oneOf: - - type: string - description: The text contents of the message. - title: Text content - - type: array - description: An array of content parts with a defined type, each can be of type `text` or `image_url` when passing in images. You can pass multiple images by adding multiple `image_url` content parts. Image input is only supported when using the `gpt-4o` model. - title: Array of content parts - items: - $ref: "#/components/schemas/ChatCompletionRequestMessageContentPart" - minItems: 1 - x-oaiExpandable: true - role: - type: string - enum: ["user"] - description: The role of the messages author, in this case `user`. - name: - type: string - description: An optional name for the participant. Provides the model information to differentiate between participants of the same role. - required: - - content - - role - - ChatCompletionRequestAssistantMessage: - type: object - title: Assistant message - properties: - content: - nullable: true - type: string - description: | - The contents of the assistant message. Required unless `tool_calls` or `function_call` is specified. - role: - type: string - enum: ["assistant"] - description: The role of the messages author, in this case `assistant`. - name: - type: string - description: An optional name for the participant. Provides the model information to differentiate between participants of the same role. - tool_calls: - $ref: "#/components/schemas/ChatCompletionMessageToolCalls" - function_call: - type: object - deprecated: true - description: "Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model." - nullable: true - properties: - arguments: - type: string - description: The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function. - name: - type: string - description: The name of the function to call. - required: - - arguments - - name - required: - - role - - FineTuneChatCompletionRequestAssistantMessage: - allOf: - - type: object - title: Assistant message - deprecated: false - properties: - weight: - type: integer - enum: [0, 1] - description: "Controls whether the assistant message is trained against (0 or 1)" - - $ref: "#/components/schemas/ChatCompletionRequestAssistantMessage" - required: - - role - - ChatCompletionRequestToolMessage: - type: object - title: Tool message - properties: - role: - type: string - enum: ["tool"] - description: The role of the messages author, in this case `tool`. - content: - type: string - description: The contents of the tool message. - tool_call_id: - type: string - description: Tool call that this message is responding to. - required: - - role - - content - - tool_call_id - - ChatCompletionRequestFunctionMessage: - type: object - title: Function message - deprecated: true - properties: - role: - type: string - enum: ["function"] - description: The role of the messages author, in this case `function`. - content: - nullable: true - type: string - description: The contents of the function message. - name: - type: string - description: The name of the function to call. - required: - - role - - content - - name - - FunctionParameters: - type: object - description: "The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation about the format. \n\nOmitting `parameters` defines a function with an empty parameter list." - additionalProperties: true - - ChatCompletionFunctions: - type: object - deprecated: true - properties: - description: - type: string - description: A description of what the function does, used by the model to choose when and how to call the function. - name: - type: string - description: The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64. - parameters: - $ref: "#/components/schemas/FunctionParameters" - required: - - name - - ChatCompletionFunctionCallOption: - type: object - description: > - Specifying a particular function via `{"name": "my_function"}` forces the model to call that function. - properties: - name: - type: string - description: The name of the function to call. - required: - - name - - ChatCompletionTool: - type: object - properties: - type: - type: string - enum: ["function"] - description: The type of the tool. Currently, only `function` is supported. - function: - $ref: "#/components/schemas/FunctionObject" - required: - - type - - function - - FunctionObject: - type: object - properties: - description: - type: string - description: A description of what the function does, used by the model to choose when and how to call the function. - name: - type: string - description: The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64. - parameters: - $ref: "#/components/schemas/FunctionParameters" - required: - - name - - ChatCompletionToolChoiceOption: - description: | - Controls which (if any) tool is called by the model. - `none` means the model will not call any tool and instead generates a message. - `auto` means the model can pick between generating a message or calling one or more tools. - `required` means the model must call one or more tools. - Specifying a particular tool via `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that tool. - - `none` is the default when no tools are present. `auto` is the default if tools are present. - oneOf: - - type: string - description: > - `none` means the model will not call any tool and instead generates a message. - `auto` means the model can pick between generating a message or calling one or more tools. - `required` means the model must call one or more tools. - enum: [none, auto, required] - - $ref: "#/components/schemas/ChatCompletionNamedToolChoice" - x-oaiExpandable: true - - ChatCompletionNamedToolChoice: - type: object - description: Specifies a tool the model should use. Use to force the model to call a specific function. - properties: - type: - type: string - enum: ["function"] - description: The type of the tool. Currently, only `function` is supported. - function: - type: object - properties: - name: - type: string - description: The name of the function to call. - required: - - name - required: - - type - - function - - ParallelToolCalls: - description: Whether to enable [parallel function calling](/docs/guides/function-calling/parallel-function-calling) during tool use. - type: boolean - default: true + **Note:** Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop` + nullable: true + default: 1 + x-ballerina-name: bestOf + stop: + description: | + Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence + nullable: true + oneOf: + - type: string + nullable: true + example: |2+ - ChatCompletionMessageToolCalls: + default: <|endoftext|> + - maxItems: 4 + minItems: 1 type: array - description: The tool calls generated by the model, such as function calls. items: - $ref: "#/components/schemas/ChatCompletionMessageToolCall" - - ChatCompletionMessageToolCall: - type: object - properties: - # TODO: index included when streaming - id: - type: string - description: The ID of the tool call. - type: - type: string - enum: ["function"] - description: The type of the tool. Currently, only `function` is supported. - function: - type: object - description: The function that the model called. - properties: - name: - type: string - description: The name of the function to call. - arguments: - type: string - description: The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function. - required: - - name - - arguments - required: - - id - - type - - function - - ChatCompletionMessageToolCallChunk: - type: object - properties: - index: - type: integer - id: - type: string - description: The ID of the tool call. - type: - type: string - enum: ["function"] - description: The type of the tool. Currently, only `function` is supported. - function: - type: object - properties: - name: - type: string - description: The name of the function to call. - arguments: - type: string - description: The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function. - required: - - index + type: string + example: "[\"\\n\"]" + stream: + type: boolean + description: | + Whether to stream back partial progress. If set, tokens will be sent as data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) as they become available, with the stream terminated by a `data: [DONE]` message. [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions) + nullable: true + default: false + temperature: + maximum: 2 + minimum: 0 + type: number + description: | + What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. - # Note, this isn't referenced anywhere, but is kept as a convenience to record all possible roles in one place. - ChatCompletionRole: - type: string - description: The role of the author of a message + We generally recommend altering this or `top_p` but not both + nullable: true + example: 1 + default: 1 + model: + description: | + ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](/docs/models/overview) for descriptions of them + anyOf: + - type: string + - type: string enum: - - system - - user - - assistant - - tool - - function - - ChatCompletionStreamOptions: - description: | - Options for streaming response. Only set this when you set `stream: true`. - type: object - nullable: true - # default: null - properties: - include_usage: - type: boolean - description: | - If set, an additional chunk will be streamed before the `data: [DONE]` message. The `usage` field on this chunk shows the token usage statistics for the entire request, and the `choices` field will always be an empty array. All other chunks will also include a `usage` field, but with a null value. - - ChatCompletionResponseMessage: - type: object - description: A chat completion message generated by the model. - properties: - content: - type: string - description: The contents of the message. - nullable: true - tool_calls: - $ref: "#/components/schemas/ChatCompletionMessageToolCalls" - role: - type: string - enum: ["assistant"] - description: The role of the author of this message. - function_call: - type: object - deprecated: true - description: "Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model." - properties: - arguments: - type: string - description: The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function. - name: - type: string - description: The name of the function to call. - required: - - name - - arguments - required: - - role - - content - - ChatCompletionStreamResponseDelta: - type: object - description: A chat completion delta generated by streamed model responses. - properties: - content: - type: string - description: The contents of the chunk message. - nullable: true - function_call: - deprecated: true - type: object - description: "Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model." - properties: - arguments: - type: string - description: The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function. - name: - type: string - description: The name of the function to call. - tool_calls: - type: array - items: - $ref: "#/components/schemas/ChatCompletionMessageToolCallChunk" - role: - type: string - enum: ["system", "user", "assistant", "tool"] - description: The role of the author of this message. - - CreateChatCompletionRequest: - type: object - properties: - messages: - description: A list of messages comprising the conversation so far. [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models). - type: array - minItems: 1 - items: - $ref: "#/components/schemas/ChatCompletionRequestMessage" - model: - description: ID of the model to use. See the [model endpoint compatibility](/docs/models/model-endpoint-compatibility) table for details on which models work with the Chat API. - example: "gpt-4-turbo" - anyOf: - - type: string - - type: string - enum: - [ - "gpt-4o", - "gpt-4o-2024-05-13", - "gpt-4o-mini", - "gpt-4o-mini-2024-07-18", - "gpt-4-turbo", - "gpt-4-turbo-2024-04-09", - "gpt-4-0125-preview", - "gpt-4-turbo-preview", - "gpt-4-1106-preview", - "gpt-4-vision-preview", - "gpt-4", - "gpt-4-0314", - "gpt-4-0613", - "gpt-4-32k", - "gpt-4-32k-0314", - "gpt-4-32k-0613", - "gpt-3.5-turbo", - "gpt-3.5-turbo-16k", - "gpt-3.5-turbo-0301", - "gpt-3.5-turbo-0613", - "gpt-3.5-turbo-1106", - "gpt-3.5-turbo-0125", - "gpt-3.5-turbo-16k-0613", - ] - x-oaiTypeLabel: string - frequency_penalty: - type: number - default: 0 - minimum: -2 - maximum: 2 - nullable: true - description: *completions_frequency_penalty_description - logit_bias: - type: object - x-oaiTypeLabel: map - # default: null - nullable: true - additionalProperties: - type: integer - description: | - Modify the likelihood of specified tokens appearing in the completion. - - Accepts a JSON object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token. - logprobs: - description: Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the `content` of `message`. - type: boolean - default: false - nullable: true - top_logprobs: - description: An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. `logprobs` must be set to `true` if this parameter is used. - type: integer - minimum: 0 - maximum: 20 - nullable: true - max_tokens: - description: | - The maximum number of [tokens](/tokenizer) that can be generated in the chat completion. - - The total length of input tokens and generated tokens is limited by the model's context length. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens. - type: integer - nullable: true - n: - type: integer - minimum: 1 - maximum: 128 - default: 1 - example: 1 - nullable: true - description: How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep `n` as `1` to minimize costs. - presence_penalty: - type: number - default: 0 - minimum: -2 - maximum: 2 - nullable: true - description: *completions_presence_penalty_description - response_format: - type: object - description: | - An object specifying the format that the model must output. Compatible with [GPT-4 Turbo](/docs/models/gpt-4-and-gpt-4-turbo) and all GPT-3.5 Turbo models newer than `gpt-3.5-turbo-1106`. - - Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is valid JSON. - - **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length. - properties: - type: - type: string - enum: ["text", "json_object"] - example: "json_object" - default: "text" - description: Must be one of `text` or `json_object`. - seed: - type: integer - minimum: -9223372036854775808 - maximum: 9223372036854775807 - nullable: true - description: | - This feature is in Beta. - If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result. - Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend. - x-oaiMeta: - beta: true - service_tier: - description: | - Specifies the latency tier to use for processing the request. This parameter is relevant for customers subscribed to the scale tier service: - - If set to 'auto', the system will utilize scale tier credits until they are exhausted. - - If set to 'default', the request will be processed using the default service tier with a lower uptime SLA and no latency guarentee. - - When not set, the default behavior is 'auto'. - - When this parameter is set, the response body will include the `service_tier` utilized. - type: string - enum: ["auto", "default"] - nullable: true - # default: null - stop: - description: | - Up to 4 sequences where the API will stop generating further tokens. - # default: null - oneOf: - - type: string - nullable: true - - type: array - minItems: 1 - maxItems: 4 - items: - type: string - stream: - description: > - If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) - as they become available, with the stream terminated by a `data: [DONE]` message. [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions). - type: boolean - nullable: true - default: false - stream_options: - $ref: "#/components/schemas/ChatCompletionStreamOptions" - temperature: - type: number - minimum: 0 - maximum: 2 - default: 1 - example: 1 - nullable: true - description: *completions_temperature_description - top_p: - type: number - minimum: 0 - maximum: 1 - default: 1 - example: 1 - nullable: true - description: *completions_top_p_description - tools: - type: array - description: > - A list of tools the model may call. Currently, only functions are supported as a tool. - Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported. - items: - $ref: "#/components/schemas/ChatCompletionTool" - tool_choice: - $ref: "#/components/schemas/ChatCompletionToolChoiceOption" - parallel_tool_calls: - $ref: "#/components/schemas/ParallelToolCalls" - user: *end_user_param_configuration - function_call: - deprecated: true - description: | - Deprecated in favor of `tool_choice`. - - Controls which (if any) function is called by the model. - `none` means the model will not call a function and instead generates a message. - `auto` means the model can pick between generating a message or calling a function. - Specifying a particular function via `{"name": "my_function"}` forces the model to call that function. - - `none` is the default when no functions are present. `auto` is the default if functions are present. - oneOf: - - type: string - description: > - `none` means the model will not call a function and instead generates a message. - `auto` means the model can pick between generating a message or calling a function. - enum: [none, auto] - - $ref: "#/components/schemas/ChatCompletionFunctionCallOption" - x-oaiExpandable: true - functions: - deprecated: true - description: | - Deprecated in favor of `tools`. - - A list of functions the model may generate JSON inputs for. - type: array - minItems: 1 - maxItems: 128 - items: - $ref: "#/components/schemas/ChatCompletionFunctions" - - required: - - model - - messages - - CreateChatCompletionResponse: - type: object - description: Represents a chat completion response returned by model, based on the provided input. - properties: - id: - type: string - description: A unique identifier for the chat completion. - choices: - type: array - description: A list of chat completion choices. Can be more than one if `n` is greater than 1. - items: - type: object - required: - - finish_reason - - index - - message - - logprobs - properties: - finish_reason: - type: string - description: &chat_completion_finish_reason_description | - The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence, - `length` if the maximum number of tokens specified in the request was reached, - `content_filter` if content was omitted due to a flag from our content filters, - `tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function. - enum: - [ - "stop", - "length", - "tool_calls", - "content_filter", - "function_call", - ] - index: - type: integer - description: The index of the choice in the list of choices. - message: - $ref: "#/components/schemas/ChatCompletionResponseMessage" - logprobs: &chat_completion_response_logprobs - description: Log probability information for the choice. - type: object - nullable: true - properties: - content: - description: A list of message content tokens with log probability information. - type: array - items: - $ref: "#/components/schemas/ChatCompletionTokenLogprob" - nullable: true - required: - - content - created: - type: integer - description: The Unix timestamp (in seconds) of when the chat completion was created. - model: - type: string - description: The model used for the chat completion. - service_tier: - description: The service tier used for processing the request. This field is only included if the `service_tier` parameter is specified in the request. - type: string - enum: ["scale", "default"] - example: "scale" - nullable: true - system_fingerprint: - type: string - description: | - This fingerprint represents the backend configuration that the model runs with. - - Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism. - object: - type: string - description: The object type, which is always `chat.completion`. - enum: [chat.completion] - usage: - $ref: "#/components/schemas/CompletionUsage" - required: - - choices - - created - - id - - model - - object - x-oaiMeta: - name: The chat completion object - group: chat - example: *chat_completion_example - - CreateChatCompletionFunctionResponse: - type: object - description: Represents a chat completion response returned by model, based on the provided input. - properties: - id: - type: string - description: A unique identifier for the chat completion. - choices: - type: array - description: A list of chat completion choices. Can be more than one if `n` is greater than 1. - items: - type: object - required: - - finish_reason - - index - - message - - logprobs - properties: - finish_reason: - type: string - description: - &chat_completion_function_finish_reason_description | - The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence, `length` if the maximum number of tokens specified in the request was reached, `content_filter` if content was omitted due to a flag from our content filters, or `function_call` if the model called a function. - enum: - ["stop", "length", "function_call", "content_filter"] - index: - type: integer - description: The index of the choice in the list of choices. - message: - $ref: "#/components/schemas/ChatCompletionResponseMessage" - created: - type: integer - description: The Unix timestamp (in seconds) of when the chat completion was created. - model: - type: string - description: The model used for the chat completion. - system_fingerprint: - type: string - description: | - This fingerprint represents the backend configuration that the model runs with. - - Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism. - object: - type: string - description: The object type, which is always `chat.completion`. - enum: [chat.completion] - usage: - $ref: "#/components/schemas/CompletionUsage" - required: - - choices - - created - - id - - model - - object - x-oaiMeta: - name: The chat completion object - group: chat - example: *chat_completion_function_example - - ChatCompletionTokenLogprob: - type: object - properties: - token: &chat_completion_response_logprobs_token - description: The token. - type: string - logprob: &chat_completion_response_logprobs_token_logprob - description: The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value `-9999.0` is used to signify that the token is very unlikely. - type: number - bytes: &chat_completion_response_logprobs_bytes - description: A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be `null` if there is no bytes representation for the token. - type: array - items: - type: integer - nullable: true - top_logprobs: - description: List of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested `top_logprobs` returned. - type: array - items: - type: object - properties: - token: *chat_completion_response_logprobs_token - logprob: *chat_completion_response_logprobs_token_logprob - bytes: *chat_completion_response_logprobs_bytes - required: - - token - - logprob - - bytes - required: - - token - - logprob - - bytes - - top_logprobs - - ListPaginatedFineTuningJobsResponse: - type: object - properties: - data: - type: array - items: - $ref: "#/components/schemas/FineTuningJob" - has_more: - type: boolean - object: - type: string - enum: [list] - required: - - object - - data - - has_more - - CreateChatCompletionStreamResponse: - type: object - description: Represents a streamed chunk of a chat completion response returned by model, based on the provided input. - properties: - id: - type: string - description: A unique identifier for the chat completion. Each chunk has the same ID. - choices: - type: array - description: | - A list of chat completion choices. Can contain more than one elements if `n` is greater than 1. Can also be empty for the - last chunk if you set `stream_options: {"include_usage": true}`. - items: - type: object - required: - - delta - - finish_reason - - index - properties: - delta: - $ref: "#/components/schemas/ChatCompletionStreamResponseDelta" - logprobs: *chat_completion_response_logprobs - finish_reason: - type: string - description: *chat_completion_finish_reason_description - enum: - [ - "stop", - "length", - "tool_calls", - "content_filter", - "function_call", - ] - nullable: true - index: - type: integer - description: The index of the choice in the list of choices. - created: - type: integer - description: The Unix timestamp (in seconds) of when the chat completion was created. Each chunk has the same timestamp. - model: - type: string - description: The model to generate the completion. - service_tier: - description: The service tier used for processing the request. This field is only included if the `service_tier` parameter is specified in the request. - type: string - enum: ["scale", "default"] - example: "scale" - nullable: true - system_fingerprint: - type: string - description: | - This fingerprint represents the backend configuration that the model runs with. - Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism. - object: - type: string - description: The object type, which is always `chat.completion.chunk`. - enum: [chat.completion.chunk] - usage: - type: object - description: | - An optional field that will only be present when you set `stream_options: {"include_usage": true}` in your request. - When present, it contains a null value except for the last chunk which contains the token usage statistics for the entire request. - properties: - completion_tokens: - type: integer - description: Number of tokens in the generated completion. - prompt_tokens: - type: integer - description: Number of tokens in the prompt. - total_tokens: - type: integer - description: Total number of tokens used in the request (prompt + completion). - required: - - prompt_tokens - - completion_tokens - - total_tokens - required: - - choices - - created - - id - - model - - object - x-oaiMeta: - name: The chat completion chunk object - group: chat - example: *chat_completion_chunk_example - - CreateChatCompletionImageResponse: - type: object - description: Represents a streamed chunk of a chat completion response returned by model, based on the provided input. - x-oaiMeta: - name: The chat completion chunk object - group: chat - example: *chat_completion_image_example - - CreateImageRequest: - type: object - properties: - prompt: - description: A text description of the desired image(s). The maximum length is 1000 characters for `dall-e-2` and 4000 characters for `dall-e-3`. - type: string - example: "A cute baby sea otter" - model: - anyOf: - - type: string - - type: string - enum: ["dall-e-2", "dall-e-3"] - x-oaiTypeLabel: string - default: "dall-e-2" - example: "dall-e-3" - nullable: true - description: The model to use for image generation. - n: &images_n - type: integer - minimum: 1 - maximum: 10 - default: 1 - example: 1 - nullable: true - description: The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only `n=1` is supported. - quality: - type: string - enum: ["standard", "hd"] - default: "standard" - example: "standard" - description: The quality of the image that will be generated. `hd` creates images with finer details and greater consistency across the image. This param is only supported for `dall-e-3`. - response_format: &images_response_format - type: string - enum: ["url", "b64_json"] - default: "url" - example: "url" - nullable: true - description: The format in which the generated images are returned. Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes after the image has been generated. - size: &images_size - type: string - enum: ["256x256", "512x512", "1024x1024", "1792x1024", "1024x1792"] - default: "1024x1024" - example: "1024x1024" - nullable: true - description: The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`. Must be one of `1024x1024`, `1792x1024`, or `1024x1792` for `dall-e-3` models. - style: - type: string - enum: ["vivid", "natural"] - default: "vivid" - example: "vivid" - nullable: true - description: The style of the generated images. Must be one of `vivid` or `natural`. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images. This param is only supported for `dall-e-3`. - user: *end_user_param_configuration - required: - - prompt - - ImagesResponse: - properties: - created: - type: integer - data: - type: array - items: - $ref: "#/components/schemas/Image" - required: - - created - - data - - Image: - type: object - description: Represents the url or the content of an image generated by the OpenAI API. - properties: - b64_json: - type: string - description: The base64-encoded JSON of the generated image, if `response_format` is `b64_json`. - url: - type: string - description: The URL of the generated image, if `response_format` is `url` (default). - revised_prompt: - type: string - description: The prompt that was used to generate the image, if there was any revision to the prompt. - x-oaiMeta: - name: The image object - example: | - { - "url": "...", - "revised_prompt": "..." - } - - CreateImageEditRequest: - type: object - properties: - image: - description: The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask. - type: string - format: binary - prompt: - description: A text description of the desired image(s). The maximum length is 1000 characters. - type: string - example: "A cute baby sea otter wearing a beret" - mask: - description: An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where `image` should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as `image`. - type: string - format: binary - model: - anyOf: - - type: string - - type: string - enum: ["dall-e-2"] - x-oaiTypeLabel: string - default: "dall-e-2" - example: "dall-e-2" - nullable: true - description: The model to use for image generation. Only `dall-e-2` is supported at this time. - n: - type: integer - minimum: 1 - maximum: 10 - default: 1 - example: 1 - nullable: true - description: The number of images to generate. Must be between 1 and 10. - size: &dalle2_images_size - type: string - enum: ["256x256", "512x512", "1024x1024"] - default: "1024x1024" - example: "1024x1024" - nullable: true - description: The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. - response_format: *images_response_format - user: *end_user_param_configuration - required: - - prompt - - image - - CreateImageVariationRequest: - type: object - properties: - image: - description: The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square. - type: string - format: binary - model: - anyOf: - - type: string - - type: string - enum: ["dall-e-2"] - x-oaiTypeLabel: string - default: "dall-e-2" - example: "dall-e-2" - nullable: true - description: The model to use for image generation. Only `dall-e-2` is supported at this time. - n: *images_n - response_format: *images_response_format - size: *dalle2_images_size - user: *end_user_param_configuration - required: - - image - - CreateModerationRequest: - type: object - properties: - input: - description: The input text to classify - oneOf: - - type: string - default: "" - example: "I want to kill them." - - type: array - items: - type: string - default: "" - example: "I want to kill them." - model: - description: | - Two content moderations models are available: `text-moderation-stable` and `text-moderation-latest`. - - The default is `text-moderation-latest` which will be automatically upgraded over time. This ensures you are always using our most accurate model. If you use `text-moderation-stable`, we will provide advanced notice before updating the model. Accuracy of `text-moderation-stable` may be slightly lower than for `text-moderation-latest`. - nullable: false - default: "text-moderation-latest" - example: "text-moderation-stable" - anyOf: - - type: string - - type: string - enum: ["text-moderation-latest", "text-moderation-stable"] - x-oaiTypeLabel: string - required: - - input - - CreateModerationResponse: - type: object - description: Represents if a given text input is potentially harmful. - properties: - id: - type: string - description: The unique identifier for the moderation request. - model: - type: string - description: The model used to generate the moderation results. - results: - type: array - description: A list of moderation objects. - items: - type: object - properties: - flagged: - type: boolean - description: Whether any of the below categories are flagged. - categories: - type: object - description: A list of the categories, and whether they are flagged or not. - properties: - hate: - type: boolean - description: Content that expresses, incites, or promotes hate based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste. Hateful content aimed at non-protected groups (e.g., chess players) is harassment. - hate/threatening: - type: boolean - description: Hateful content that also includes violence or serious harm towards the targeted group based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste. - harassment: - type: boolean - description: Content that expresses, incites, or promotes harassing language towards any target. - harassment/threatening: - type: boolean - description: Harassment content that also includes violence or serious harm towards any target. - self-harm: - type: boolean - description: Content that promotes, encourages, or depicts acts of self-harm, such as suicide, cutting, and eating disorders. - self-harm/intent: - type: boolean - description: Content where the speaker expresses that they are engaging or intend to engage in acts of self-harm, such as suicide, cutting, and eating disorders. - self-harm/instructions: - type: boolean - description: Content that encourages performing acts of self-harm, such as suicide, cutting, and eating disorders, or that gives instructions or advice on how to commit such acts. - sexual: - type: boolean - description: Content meant to arouse sexual excitement, such as the description of sexual activity, or that promotes sexual services (excluding sex education and wellness). - sexual/minors: - type: boolean - description: Sexual content that includes an individual who is under 18 years old. - violence: - type: boolean - description: Content that depicts death, violence, or physical injury. - violence/graphic: - type: boolean - description: Content that depicts death, violence, or physical injury in graphic detail. - required: - - hate - - hate/threatening - - harassment - - harassment/threatening - - self-harm - - self-harm/intent - - self-harm/instructions - - sexual - - sexual/minors - - violence - - violence/graphic - category_scores: - type: object - description: A list of the categories along with their scores as predicted by model. - properties: - hate: - type: number - description: The score for the category 'hate'. - hate/threatening: - type: number - description: The score for the category 'hate/threatening'. - harassment: - type: number - description: The score for the category 'harassment'. - harassment/threatening: - type: number - description: The score for the category 'harassment/threatening'. - self-harm: - type: number - description: The score for the category 'self-harm'. - self-harm/intent: - type: number - description: The score for the category 'self-harm/intent'. - self-harm/instructions: - type: number - description: The score for the category 'self-harm/instructions'. - sexual: - type: number - description: The score for the category 'sexual'. - sexual/minors: - type: number - description: The score for the category 'sexual/minors'. - violence: - type: number - description: The score for the category 'violence'. - violence/graphic: - type: number - description: The score for the category 'violence/graphic'. - required: - - hate - - hate/threatening - - harassment - - harassment/threatening - - self-harm - - self-harm/intent - - self-harm/instructions - - sexual - - sexual/minors - - violence - - violence/graphic - required: - - flagged - - categories - - category_scores - required: - - id - - model - - results - x-oaiMeta: - name: The moderation object - example: *moderation_example - - ListFilesResponse: - type: object - properties: - data: - type: array - items: - $ref: "#/components/schemas/OpenAIFile" - object: - type: string - enum: [list] - required: - - object - - data - - CreateFileRequest: - type: object - additionalProperties: false - properties: - file: - description: | - The File object (not file name) to be uploaded. - type: string - format: binary - purpose: - description: | - The intended purpose of the uploaded file. - - Use "assistants" for [Assistants](/docs/api-reference/assistants) and [Message](/docs/api-reference/messages) files, "vision" for Assistants image file inputs, "batch" for [Batch API](/docs/guides/batch), and "fine-tune" for [Fine-tuning](/docs/api-reference/fine-tuning). - type: string - enum: ["assistants", "batch", "fine-tune", "vision"] - required: - - file - - purpose - - DeleteFileResponse: - type: object - properties: - id: - type: string - object: - type: string - enum: [file] - deleted: - type: boolean - required: - - id - - object - - deleted - - CreateUploadRequest: - type: object - additionalProperties: false - properties: - filename: - description: | - The name of the file to upload. - type: string - purpose: - description: | - The intended purpose of the uploaded file. - - See the [documentation on File purposes](/docs/api-reference/files/create#files-create-purpose). - type: string - enum: ["assistants", "batch", "fine-tune", "vision"] - bytes: - description: | - The number of bytes in the file you are uploading. - type: integer - mime_type: - description: | - The MIME type of the file. - - This must fall within the supported MIME types for your file purpose. See the supported MIME types for assistants and vision. - type: string - required: - - filename - - purpose - - bytes - - mime_type - - AddUploadPartRequest: - type: object - additionalProperties: false - properties: - data: - description: | - The chunk of bytes for this Part. - type: string - format: binary - required: - - data - - CompleteUploadRequest: - type: object - additionalProperties: false - properties: - part_ids: - type: array - description: | - The ordered list of Part IDs. - items: - type: string - md5: - description: | - The optional md5 checksum for the file contents to verify if the bytes uploaded matches what you expect. - type: string - required: - - part_ids - - CancelUploadRequest: - type: object - additionalProperties: false - - CreateFineTuningJobRequest: - type: object - properties: - model: - description: | - The name of the model to fine-tune. You can select one of the - [supported models](/docs/guides/fine-tuning/what-models-can-be-fine-tuned). - example: "gpt-3.5-turbo" - anyOf: - - type: string - - type: string - enum: ["babbage-002", "davinci-002", "gpt-3.5-turbo"] - x-oaiTypeLabel: string - training_file: - description: | - The ID of an uploaded file that contains training data. - - See [upload file](/docs/api-reference/files/create) for how to upload a file. - - Your dataset must be formatted as a JSONL file. Additionally, you must upload your file with the purpose `fine-tune`. - - The contents of the file should differ depending on if the model uses the [chat](/docs/api-reference/fine-tuning/chat-input) or [completions](/docs/api-reference/fine-tuning/completions-input) format. - - See the [fine-tuning guide](/docs/guides/fine-tuning) for more details. - type: string - example: "file-abc123" - hyperparameters: - type: object - description: The hyperparameters used for the fine-tuning job. - properties: - batch_size: - description: | - Number of examples in each batch. A larger batch size means that model parameters - are updated less frequently, but with lower variance. - oneOf: - - type: string - enum: [auto] - - type: integer - minimum: 1 - maximum: 256 - default: auto - learning_rate_multiplier: - description: | - Scaling factor for the learning rate. A smaller learning rate may be useful to avoid - overfitting. - oneOf: - - type: string - enum: [auto] - - type: number - minimum: 0 - exclusiveMinimum: true - default: auto - n_epochs: - description: | - The number of epochs to train the model for. An epoch refers to one full cycle - through the training dataset. - oneOf: - - type: string - enum: [auto] - - type: integer - minimum: 1 - maximum: 50 - default: auto - suffix: - description: | - A string of up to 18 characters that will be added to your fine-tuned model name. - - For example, a `suffix` of "custom-model-name" would produce a model name like `ft:gpt-3.5-turbo:openai:custom-model-name:7p4lURel`. - type: string - minLength: 1 - maxLength: 40 - # default: null - nullable: true - validation_file: - description: | - The ID of an uploaded file that contains validation data. - - If you provide this file, the data is used to generate validation - metrics periodically during fine-tuning. These metrics can be viewed in - the fine-tuning results file. - The same data should not be present in both train and validation files. - - Your dataset must be formatted as a JSONL file. You must upload your file with the purpose `fine-tune`. - - See the [fine-tuning guide](/docs/guides/fine-tuning) for more details. - type: string - nullable: true - example: "file-abc123" - integrations: - type: array - description: A list of integrations to enable for your fine-tuning job. - nullable: true - items: - type: object - required: - - type - - wandb - properties: - type: - description: | - The type of integration to enable. Currently, only "wandb" (Weights and Biases) is supported. - oneOf: - - type: string - enum: [wandb] - wandb: - type: object - description: | - The settings for your integration with Weights and Biases. This payload specifies the project that - metrics will be sent to. Optionally, you can set an explicit display name for your run, add tags - to your run, and set a default entity (team, username, etc) to be associated with your run. - required: - - project - properties: - project: - description: | - The name of the project that the new run will be created under. - type: string - example: "my-wandb-project" - name: - description: | - A display name to set for the run. If not set, we will use the Job ID as the name. - nullable: true - type: string - entity: - description: | - The entity to use for the run. This allows you to set the team or username of the WandB user that you would - like associated with the run. If not set, the default entity for the registered WandB API key is used. - nullable: true - type: string - tags: - description: | - A list of tags to be attached to the newly created run. These tags are passed through directly to WandB. Some - default tags are generated by OpenAI: "openai/finetune", "openai/{base-model}", "openai/{ftjob-abcdef}". - type: array - items: - type: string - example: "custom-tag" - - seed: - description: | - The seed controls the reproducibility of the job. Passing in the same seed and job parameters should produce the same results, but may differ in rare cases. - If a seed is not specified, one will be generated for you. - type: integer - nullable: true - minimum: 0 - maximum: 2147483647 - example: 42 - required: - - model - - training_file - - ListFineTuningJobEventsResponse: - type: object - properties: - data: - type: array - items: - $ref: "#/components/schemas/FineTuningJobEvent" - object: - type: string - enum: [list] - required: - - object - - data - - ListFineTuningJobCheckpointsResponse: - type: object - properties: - data: - type: array - items: - $ref: "#/components/schemas/FineTuningJobCheckpoint" - object: - type: string - enum: [list] - first_id: - type: string - nullable: true - last_id: - type: string - nullable: true - has_more: - type: boolean - required: - - object - - data - - has_more - - CreateEmbeddingRequest: - type: object - additionalProperties: false - properties: - input: - description: | - Input text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays. The input must not exceed the max input tokens for the model (8192 tokens for `text-embedding-ada-002`), cannot be an empty string, and any array must be 2048 dimensions or less. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens. - example: "The quick brown fox jumped over the lazy dog" - oneOf: - - type: string - title: string - description: The string that will be turned into an embedding. - default: "" - example: "This is a test." - - type: array - title: array - description: The array of strings that will be turned into an embedding. - minItems: 1 - maxItems: 2048 - items: - type: string - default: "" - example: "['This is a test.']" - - type: array - title: array - description: The array of integers that will be turned into an embedding. - minItems: 1 - maxItems: 2048 - items: - type: integer - example: "[1212, 318, 257, 1332, 13]" - - type: array - title: array - description: The array of arrays containing integers that will be turned into an embedding. - minItems: 1 - maxItems: 2048 - items: - type: array - minItems: 1 - items: - type: integer - example: "[[1212, 318, 257, 1332, 13]]" - x-oaiExpandable: true - model: - description: *model_description - example: "text-embedding-3-small" - anyOf: - - type: string - - type: string - enum: - [ - "text-embedding-ada-002", - "text-embedding-3-small", - "text-embedding-3-large", - ] - x-oaiTypeLabel: string - encoding_format: - description: "The format to return the embeddings in. Can be either `float` or [`base64`](https://pypi.org/project/pybase64/)." - example: "float" - default: "float" - type: string - enum: ["float", "base64"] - dimensions: - description: | - The number of dimensions the resulting output embeddings should have. Only supported in `text-embedding-3` and later models. - type: integer - minimum: 1 - user: *end_user_param_configuration - required: - - model - - input - - CreateEmbeddingResponse: - type: object - properties: - data: - type: array - description: The list of embeddings generated by the model. - items: - $ref: "#/components/schemas/Embedding" - model: - type: string - description: The name of the model used to generate the embedding. - object: - type: string - description: The object type, which is always "list". - enum: [list] - usage: - type: object - description: The usage information for the request. - properties: - prompt_tokens: - type: integer - description: The number of tokens used by the prompt. - total_tokens: - type: integer - description: The total number of tokens used by the request. - required: - - prompt_tokens - - total_tokens - required: - - object - - model - - data - - usage - - CreateTranscriptionRequest: - type: object - additionalProperties: false - properties: - file: - description: | - The audio file object (not file name) to transcribe, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm. - type: string - x-oaiTypeLabel: file - format: binary - model: - description: | - ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2 model) is currently available. - example: whisper-1 - anyOf: - - type: string - - type: string - enum: ["whisper-1"] - x-oaiTypeLabel: string - language: - description: | - The language of the input audio. Supplying the input language in [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) format will improve accuracy and latency. - type: string - prompt: - description: | - An optional text to guide the model's style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text/prompting) should match the audio language. - type: string - response_format: - description: | - The format of the transcript output, in one of these options: `json`, `text`, `srt`, `verbose_json`, or `vtt`. - type: string - enum: - - json - - text - - srt - - verbose_json - - vtt - default: json - temperature: - description: | - The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. - type: number - default: 0 - timestamp_granularities[]: - description: | - The timestamp granularities to populate for this transcription. `response_format` must be set `verbose_json` to use timestamp granularities. Either or both of these options are supported: `word`, or `segment`. Note: There is no additional latency for segment timestamps, but generating word timestamps incurs additional latency. - type: array - items: - type: string - enum: - - word - - segment - default: [segment] - required: - - file - - model - - # Note: This does not currently support the non-default response format types. - CreateTranscriptionResponseJson: - type: object - description: Represents a transcription response returned by model, based on the provided input. - properties: - text: - type: string - description: The transcribed text. - required: - - text - x-oaiMeta: - name: The transcription object (JSON) - group: audio - example: *basic_transcription_response_example - - TranscriptionSegment: - type: object - properties: - id: - type: integer - description: Unique identifier of the segment. - seek: - type: integer - description: Seek offset of the segment. - start: - type: number - format: float - description: Start time of the segment in seconds. - end: - type: number - format: float - description: End time of the segment in seconds. - text: - type: string - description: Text content of the segment. - tokens: - type: array - items: - type: integer - description: Array of token IDs for the text content. - temperature: - type: number - format: float - description: Temperature parameter used for generating the segment. - avg_logprob: - type: number - format: float - description: Average logprob of the segment. If the value is lower than -1, consider the logprobs failed. - compression_ratio: - type: number - format: float - description: Compression ratio of the segment. If the value is greater than 2.4, consider the compression failed. - no_speech_prob: - type: number - format: float - description: Probability of no speech in the segment. If the value is higher than 1.0 and the `avg_logprob` is below -1, consider this segment silent. - required: - - id - - seek - - start - - end - - text - - tokens - - temperature - - avg_logprob - - compression_ratio - - no_speech_prob - - TranscriptionWord: - type: object - properties: - word: - type: string - description: The text content of the word. - start: - type: number - format: float - description: Start time of the word in seconds. - end: - type: number - format: float - description: End time of the word in seconds. - required: [word, start, end] - - CreateTranscriptionResponseVerboseJson: - type: object - description: Represents a verbose json transcription response returned by model, based on the provided input. - properties: - language: - type: string - description: The language of the input audio. - duration: - type: string - description: The duration of the input audio. - text: - type: string - description: The transcribed text. - words: - type: array - description: Extracted words and their corresponding timestamps. - items: - $ref: "#/components/schemas/TranscriptionWord" - segments: - type: array - description: Segments of the transcribed text and their corresponding details. - items: - $ref: "#/components/schemas/TranscriptionSegment" - required: [language, duration, text] - x-oaiMeta: - name: The transcription object (Verbose JSON) - group: audio - example: *verbose_transcription_response_example - - CreateTranslationRequest: - type: object - additionalProperties: false - properties: - file: - description: | - The audio file object (not file name) translate, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm. - type: string - x-oaiTypeLabel: file - format: binary - model: - description: | - ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2 model) is currently available. - example: whisper-1 - anyOf: - - type: string - - type: string - enum: ["whisper-1"] - x-oaiTypeLabel: string - prompt: - description: | - An optional text to guide the model's style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text/prompting) should be in English. - type: string - response_format: - description: | - The format of the transcript output, in one of these options: `json`, `text`, `srt`, `verbose_json`, or `vtt`. - type: string - default: json - temperature: - description: | - The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. - type: number - default: 0 - required: - - file - - model - - # Note: This does not currently support the non-default response format types. - CreateTranslationResponseJson: - type: object - properties: - text: - type: string - required: - - text - - CreateTranslationResponseVerboseJson: - type: object - properties: - language: - type: string - description: The language of the output translation (always `english`). - duration: - type: string - description: The duration of the input audio. - text: - type: string - description: The translated text. - segments: - type: array - description: Segments of the translated text and their corresponding details. - items: - $ref: "#/components/schemas/TranscriptionSegment" - required: [language, duration, text] - - CreateSpeechRequest: - type: object - additionalProperties: false - properties: - model: - description: | - One of the available [TTS models](/docs/models/tts): `tts-1` or `tts-1-hd` - anyOf: - - type: string - - type: string - enum: ["tts-1", "tts-1-hd"] - x-oaiTypeLabel: string - input: - type: string - description: The text to generate audio for. The maximum length is 4096 characters. - maxLength: 4096 - voice: - description: The voice to use when generating the audio. Supported voices are `alloy`, `echo`, `fable`, `onyx`, `nova`, and `shimmer`. Previews of the voices are available in the [Text to speech guide](/docs/guides/text-to-speech/voice-options). - type: string - enum: ["alloy", "echo", "fable", "onyx", "nova", "shimmer"] - response_format: - description: "The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`, `wav`, and `pcm`." - default: "mp3" - type: string - enum: ["mp3", "opus", "aac", "flac", "wav", "pcm"] - speed: - description: "The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is the default." - type: number - default: 1.0 - minimum: 0.25 - maximum: 4.0 - required: - - model - - input - - voice - - Model: - title: Model - description: Describes an OpenAI model offering that can be used with the API. - properties: - id: - type: string - description: The model identifier, which can be referenced in the API endpoints. - created: - type: integer - description: The Unix timestamp (in seconds) when the model was created. - object: - type: string - description: The object type, which is always "model". - enum: [model] - owned_by: - type: string - description: The organization that owns the model. - required: - - id - - object - - created - - owned_by - x-oaiMeta: - name: The model object - example: *retrieve_model_response - - OpenAIFile: - title: OpenAIFile - description: The `File` object represents a document that has been uploaded to OpenAI. - properties: - id: - type: string - description: The file identifier, which can be referenced in the API endpoints. - bytes: - type: integer - description: The size of the file, in bytes. - created_at: - type: integer - description: The Unix timestamp (in seconds) for when the file was created. - filename: - type: string - description: The name of the file. - object: - type: string - description: The object type, which is always `file`. - enum: ["file"] - purpose: - type: string - description: The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results` and `vision`. - enum: - [ - "assistants", - "assistants_output", - "batch", - "batch_output", - "fine-tune", - "fine-tune-results", - "vision", - ] - status: - type: string - deprecated: true - description: Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`. - enum: ["uploaded", "processed", "error"] - status_details: - type: string - nullable: true - description: Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`. - required: - - id - - object - - bytes - - created_at - - filename - - purpose - - status - x-oaiMeta: - name: The file object - example: | - { - "id": "file-abc123", - "object": "file", - "bytes": 120000, - "created_at": 1677610602, - "filename": "salesOverview.pdf", - "purpose": "assistants", - } - Upload: - type: object - title: Upload - description: | - The Upload object can accept byte chunks in the form of Parts. - properties: - id: - type: string - description: The Upload unique identifier, which can be referenced in API endpoints. - created_at: - type: integer - description: The Unix timestamp (in seconds) for when the Upload was created. - filename: - type: string - description: The name of the file to be uploaded. - bytes: - type: integer - description: The intended number of bytes to be uploaded. - purpose: - type: string - description: The intended purpose of the file. [Please refer here](/docs/api-reference/files/object#files/object-purpose) for acceptable values. - status: - type: string - description: The status of the Upload. - enum: ["pending", "completed", "cancelled", "expired"] - expires_at: - type: integer - description: The Unix timestamp (in seconds) for when the Upload was created. - object: - type: string - description: The object type, which is always "upload". - enum: [upload] - file: - $ref: "#/components/schemas/OpenAIFile" - nullable: true - description: The ready File object after the Upload is completed. - required: - - bytes - - created_at - - expires_at - - filename - - id - - purpose - - status - - step_number - x-oaiMeta: - name: The upload object - example: | - { - "id": "upload_abc123", - "object": "upload", - "bytes": 2147483648, - "created_at": 1719184911, - "filename": "training_examples.jsonl", - "purpose": "fine-tune", - "status": "completed", - "expires_at": 1719127296, - "file": { - "id": "file-xyz321", - "object": "file", - "bytes": 2147483648, - "created_at": 1719186911, - "filename": "training_examples.jsonl", - "purpose": "fine-tune", - } - } - UploadPart: - type: object - title: UploadPart - description: | - The upload Part represents a chunk of bytes we can add to an Upload object. - properties: - id: - type: string - description: The upload Part unique identifier, which can be referenced in API endpoints. - created_at: - type: integer - description: The Unix timestamp (in seconds) for when the Part was created. - upload_id: - type: string - description: The ID of the Upload object that this Part was added to. - object: - type: string - description: The object type, which is always `upload.part`. - enum: ['upload.part'] - required: - - created_at - - id - - object - - upload_id - x-oaiMeta: - name: The upload part object - example: | - { - "id": "part_def456", - "object": "upload.part", - "created_at": 1719186911, - "upload_id": "upload_abc123" - } - Embedding: - type: object - description: | - Represents an embedding vector returned by embedding endpoint. - properties: - index: - type: integer - description: The index of the embedding in the list of embeddings. - embedding: - type: array - description: | - The embedding vector, which is a list of floats. The length of vector depends on the model as listed in the [embedding guide](/docs/guides/embeddings). - items: - type: number - object: - type: string - description: The object type, which is always "embedding". - enum: [embedding] - required: - - index - - object - - embedding - x-oaiMeta: - name: The embedding object - example: | - { - "object": "embedding", - "embedding": [ - 0.0023064255, - -0.009327292, - .... (1536 floats total for ada-002) - -0.0028842222, - ], - "index": 0 - } - - FineTuningJob: - type: object - title: FineTuningJob - description: | - The `fine_tuning.job` object represents a fine-tuning job that has been created through the API. - properties: - id: - type: string - description: The object identifier, which can be referenced in the API endpoints. - created_at: - type: integer - description: The Unix timestamp (in seconds) for when the fine-tuning job was created. - error: - type: object - nullable: true - description: For fine-tuning jobs that have `failed`, this will contain more information on the cause of the failure. - properties: - code: - type: string - description: A machine-readable error code. - message: - type: string - description: A human-readable error message. - param: - type: string - description: The parameter that was invalid, usually `training_file` or `validation_file`. This field will be null if the failure was not parameter-specific. - nullable: true - fine_tuned_model: - type: string - nullable: true - description: The name of the fine-tuned model that is being created. The value will be null if the fine-tuning job is still running. - finished_at: - type: integer - nullable: true - description: The Unix timestamp (in seconds) for when the fine-tuning job was finished. The value will be null if the fine-tuning job is still running. - hyperparameters: - type: object - description: The hyperparameters used for the fine-tuning job. See the [fine-tuning guide](/docs/guides/fine-tuning) for more details. - properties: - n_epochs: - oneOf: - - type: string - enum: [auto] - - type: integer - minimum: 1 - maximum: 50 - default: auto - description: - The number of epochs to train the model for. An epoch refers to one full cycle through the training dataset. - - "auto" decides the optimal number of epochs based on the size of the dataset. If setting the number manually, we support any number between 1 and 50 epochs. - required: - - n_epochs - model: - type: string - description: The base model that is being fine-tuned. - object: - type: string - description: The object type, which is always "fine_tuning.job". - enum: [fine_tuning.job] - organization_id: - type: string - description: The organization that owns the fine-tuning job. - result_files: - type: array - description: The compiled results file ID(s) for the fine-tuning job. You can retrieve the results with the [Files API](/docs/api-reference/files/retrieve-contents). - items: - type: string - example: file-abc123 - status: - type: string - description: The current status of the fine-tuning job, which can be either `validating_files`, `queued`, `running`, `succeeded`, `failed`, or `cancelled`. - enum: - [ - "validating_files", - "queued", - "running", - "succeeded", - "failed", - "cancelled", - ] - trained_tokens: - type: integer - nullable: true - description: The total number of billable tokens processed by this fine-tuning job. The value will be null if the fine-tuning job is still running. - training_file: - type: string - description: The file ID used for training. You can retrieve the training data with the [Files API](/docs/api-reference/files/retrieve-contents). - validation_file: - type: string - nullable: true - description: The file ID used for validation. You can retrieve the validation results with the [Files API](/docs/api-reference/files/retrieve-contents). - integrations: - type: array - nullable: true - description: A list of integrations to enable for this fine-tuning job. - maxItems: 5 - items: - oneOf: - - $ref: "#/components/schemas/FineTuningIntegration" - x-oaiExpandable: true - seed: - type: integer - description: The seed used for the fine-tuning job. - estimated_finish: - type: integer - nullable: true - description: The Unix timestamp (in seconds) for when the fine-tuning job is estimated to finish. The value will be null if the fine-tuning job is not running. - required: - - created_at - - error - - finished_at - - fine_tuned_model - - hyperparameters - - id - - model - - object - - organization_id - - result_files - - status - - trained_tokens - - training_file - - validation_file - - seed - x-oaiMeta: - name: The fine-tuning job object - example: *fine_tuning_example - - FineTuningIntegration: - type: object - title: Fine-Tuning Job Integration - required: - - type - - wandb - properties: - type: - type: string - description: "The type of the integration being enabled for the fine-tuning job" - enum: ["wandb"] - wandb: - type: object - description: | - The settings for your integration with Weights and Biases. This payload specifies the project that - metrics will be sent to. Optionally, you can set an explicit display name for your run, add tags - to your run, and set a default entity (team, username, etc) to be associated with your run. - required: - - project - properties: - project: - description: | - The name of the project that the new run will be created under. - type: string - example: "my-wandb-project" - name: - description: | - A display name to set for the run. If not set, we will use the Job ID as the name. - nullable: true - type: string - entity: - description: | - The entity to use for the run. This allows you to set the team or username of the WandB user that you would - like associated with the run. If not set, the default entity for the registered WandB API key is used. - nullable: true - type: string - tags: - description: | - A list of tags to be attached to the newly created run. These tags are passed through directly to WandB. Some - default tags are generated by OpenAI: "openai/finetune", "openai/{base-model}", "openai/{ftjob-abcdef}". - type: array - items: - type: string - example: "custom-tag" - - FineTuningJobEvent: - type: object - description: Fine-tuning job event object - properties: - id: - type: string - created_at: - type: integer - level: - type: string - enum: ["info", "warn", "error"] - message: - type: string - object: - type: string - enum: [fine_tuning.job.event] - required: - - id - - object - - created_at - - level - - message - x-oaiMeta: - name: The fine-tuning job event object - example: | - { - "object": "fine_tuning.job.event", - "id": "ftevent-abc123" - "created_at": 1677610602, - "level": "info", - "message": "Created fine-tuning job" - } - - FineTuningJobCheckpoint: - type: object - title: FineTuningJobCheckpoint - description: | - The `fine_tuning.job.checkpoint` object represents a model checkpoint for a fine-tuning job that is ready to use. - properties: - id: - type: string - description: The checkpoint identifier, which can be referenced in the API endpoints. - created_at: - type: integer - description: The Unix timestamp (in seconds) for when the checkpoint was created. - fine_tuned_model_checkpoint: - type: string - description: The name of the fine-tuned checkpoint model that is created. - step_number: - type: integer - description: The step number that the checkpoint was created at. - metrics: - type: object - description: Metrics at the step number during the fine-tuning job. - properties: - step: - type: number - train_loss: - type: number - train_mean_token_accuracy: - type: number - valid_loss: - type: number - valid_mean_token_accuracy: - type: number - full_valid_loss: - type: number - full_valid_mean_token_accuracy: - type: number - fine_tuning_job_id: - type: string - description: The name of the fine-tuning job that this checkpoint was created from. - object: - type: string - description: The object type, which is always "fine_tuning.job.checkpoint". - enum: [fine_tuning.job.checkpoint] - required: - - created_at - - fine_tuning_job_id - - fine_tuned_model_checkpoint - - id - - metrics - - object - - step_number - x-oaiMeta: - name: The fine-tuning job checkpoint object - example: | - { - "object": "fine_tuning.job.checkpoint", - "id": "ftckpt_qtZ5Gyk4BLq1SfLFWp3RtO3P", - "created_at": 1712211699, - "fine_tuned_model_checkpoint": "ft:gpt-3.5-turbo-0125:my-org:custom_suffix:9ABel2dg:ckpt-step-88", - "fine_tuning_job_id": "ftjob-fpbNQ3H1GrMehXRf8cO97xTN", - "metrics": { - "step": 88, - "train_loss": 0.478, - "train_mean_token_accuracy": 0.924, - "valid_loss": 10.112, - "valid_mean_token_accuracy": 0.145, - "full_valid_loss": 0.567, - "full_valid_mean_token_accuracy": 0.944 - }, - "step_number": 88 - } - - FinetuneChatRequestInput: - type: object - description: The per-line training example of a fine-tuning input file for chat models - properties: - messages: - type: array - minItems: 1 - items: - oneOf: - - $ref: "#/components/schemas/ChatCompletionRequestSystemMessage" - - $ref: "#/components/schemas/ChatCompletionRequestUserMessage" - - $ref: "#/components/schemas/FineTuneChatCompletionRequestAssistantMessage" - - $ref: "#/components/schemas/ChatCompletionRequestToolMessage" - - $ref: "#/components/schemas/ChatCompletionRequestFunctionMessage" - x-oaiExpandable: true - tools: - type: array - description: A list of tools the model may generate JSON inputs for. - items: - $ref: "#/components/schemas/ChatCompletionTool" - parallel_tool_calls: - $ref: "#/components/schemas/ParallelToolCalls" - functions: - deprecated: true - description: - A list of functions the model may generate JSON inputs for. - type: array - minItems: 1 - maxItems: 128 - items: - $ref: "#/components/schemas/ChatCompletionFunctions" - x-oaiMeta: - name: Training format for chat models - example: | - { - "messages": [ - { "role": "user", "content": "What is the weather in San Francisco?" }, - { - "role": "assistant", - "tool_calls": [ - { - "id": "call_id", - "type": "function", - "function": { - "name": "get_current_weather", - "arguments": "{\"location\": \"San Francisco, USA\", \"format\": \"celsius\"}" - } - } - ] - } - ], - "parallel_tool_calls": false, - "tools": [ - { - "type": "function", - "function": { - "name": "get_current_weather", - "description": "Get the current weather", - "parameters": { - "type": "object", - "properties": { - "location": { - "type": "string", - "description": "The city and country, eg. San Francisco, USA" - }, - "format": { "type": "string", "enum": ["celsius", "fahrenheit"] } - }, - "required": ["location", "format"] - } - } - } - ] - } - - FinetuneCompletionRequestInput: - type: object - description: The per-line training example of a fine-tuning input file for completions models - properties: - prompt: - type: string - description: The input prompt for this training example. - completion: - type: string - description: The desired completion for this training example. - x-oaiMeta: - name: Training format for completions models - example: | - { - "prompt": "What is the answer to 2+2", - "completion": "4" - } - - CompletionUsage: - type: object - description: Usage statistics for the completion request. - properties: - completion_tokens: - type: integer - description: Number of tokens in the generated completion. - prompt_tokens: - type: integer - description: Number of tokens in the prompt. - total_tokens: - type: integer - description: Total number of tokens used in the request (prompt + completion). - required: - - prompt_tokens - - completion_tokens - - total_tokens - - RunCompletionUsage: - type: object - description: Usage statistics related to the run. This value will be `null` if the run is not in a terminal state (i.e. `in_progress`, `queued`, etc.). - properties: - completion_tokens: - type: integer - description: Number of completion tokens used over the course of the run. - prompt_tokens: - type: integer - description: Number of prompt tokens used over the course of the run. - total_tokens: - type: integer - description: Total number of tokens used (prompt + completion). - required: - - prompt_tokens - - completion_tokens - - total_tokens - nullable: true - - RunStepCompletionUsage: - type: object - description: Usage statistics related to the run step. This value will be `null` while the run step's status is `in_progress`. - properties: - completion_tokens: - type: integer - description: Number of completion tokens used over the course of the run step. - prompt_tokens: - type: integer - description: Number of prompt tokens used over the course of the run step. - total_tokens: - type: integer - description: Total number of tokens used (prompt + completion). - required: - - prompt_tokens - - completion_tokens - - total_tokens - nullable: true - - AssistantsApiResponseFormatOption: - description: | - Specifies the format that the model must output. Compatible with [GPT-4o](/docs/models/gpt-4o), [GPT-4 Turbo](/docs/models/gpt-4-turbo-and-gpt-4), and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`. - - Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is valid JSON. - - **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length. - oneOf: - - type: string - description: > - `auto` is the default value - enum: [none, auto] - - $ref: "#/components/schemas/AssistantsApiResponseFormat" - x-oaiExpandable: true - - AssistantsApiResponseFormat: - type: object - description: | - An object describing the expected output of the model. If `json_object` only `function` type `tools` are allowed to be passed to the Run. If `text` the model can return text or any value needed. - properties: - type: - type: string - enum: ["text", "json_object"] - example: "json_object" - default: "text" - description: Must be one of `text` or `json_object`. - - AssistantObject: - type: object - title: Assistant - description: Represents an `assistant` that can call the model and use tools. - properties: - id: - description: The identifier, which can be referenced in API endpoints. - type: string - object: - description: The object type, which is always `assistant`. - type: string - enum: [assistant] - created_at: - description: The Unix timestamp (in seconds) for when the assistant was created. - type: integer - name: - description: &assistant_name_param_description | - The name of the assistant. The maximum length is 256 characters. - type: string - maxLength: 256 - nullable: true - description: - description: &assistant_description_param_description | - The description of the assistant. The maximum length is 512 characters. - type: string - maxLength: 512 - nullable: true - model: - description: *model_description - type: string - instructions: - description: &assistant_instructions_param_description | - The system instructions that the assistant uses. The maximum length is 256,000 characters. - type: string - maxLength: 256000 - nullable: true - tools: - description: &assistant_tools_param_description | - A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`. - default: [] - type: array - maxItems: 128 - items: - oneOf: - - $ref: "#/components/schemas/AssistantToolsCode" - - $ref: "#/components/schemas/AssistantToolsFileSearch" - - $ref: "#/components/schemas/AssistantToolsFunction" - x-oaiExpandable: true - tool_resources: - type: object - description: | - A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs. - properties: - code_interpreter: - type: object - properties: - file_ids: - type: array - description: | - A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter`` tool. There can be a maximum of 20 files associated with the tool. - default: [] - maxItems: 20 - items: - type: string - file_search: - type: object - properties: - vector_store_ids: - type: array - description: | - The ID of the [vector store](/docs/api-reference/vector-stores/object) attached to this assistant. There can be a maximum of 1 vector store attached to the assistant. - maxItems: 1 - items: - type: string - nullable: true - metadata: - description: &metadata_description | - Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. - type: object - x-oaiTypeLabel: map - nullable: true - temperature: - description: &run_temperature_description | - What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. - type: number - minimum: 0 - maximum: 2 - default: 1 - example: 1 - nullable: true - top_p: - type: number - minimum: 0 - maximum: 1 - default: 1 - example: 1 - nullable: true - description: &run_top_p_description | - An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. - - We generally recommend altering this or temperature but not both. - response_format: - $ref: "#/components/schemas/AssistantsApiResponseFormatOption" - nullable: true - required: - - id - - object - - created_at - - name - - description - - model - - instructions - - tools - - metadata - x-oaiMeta: - name: The assistant object - beta: true - example: *create_assistants_example - - CreateAssistantRequest: - type: object - additionalProperties: false - properties: - model: - description: *model_description - example: "gpt-4-turbo" - anyOf: - - type: string - - type: string - enum: - [ - "gpt-4o", - "gpt-4o-2024-05-13", - "gpt-4o-mini", - "gpt-4o-mini-2024-07-18", - "gpt-4-turbo", - "gpt-4-turbo-2024-04-09", - "gpt-4-0125-preview", - "gpt-4-turbo-preview", - "gpt-4-1106-preview", - "gpt-4-vision-preview", - "gpt-4", - "gpt-4-0314", - "gpt-4-0613", - "gpt-4-32k", - "gpt-4-32k-0314", - "gpt-4-32k-0613", - "gpt-3.5-turbo", - "gpt-3.5-turbo-16k", - "gpt-3.5-turbo-0613", - "gpt-3.5-turbo-1106", - "gpt-3.5-turbo-0125", - "gpt-3.5-turbo-16k-0613", - ] - x-oaiTypeLabel: string - name: - description: *assistant_name_param_description - type: string - nullable: true - maxLength: 256 - description: - description: *assistant_description_param_description - type: string - nullable: true - maxLength: 512 - instructions: - description: *assistant_instructions_param_description - type: string - nullable: true - maxLength: 256000 - tools: - description: *assistant_tools_param_description - default: [] - type: array - maxItems: 128 - items: - oneOf: - - $ref: "#/components/schemas/AssistantToolsCode" - - $ref: "#/components/schemas/AssistantToolsFileSearch" - - $ref: "#/components/schemas/AssistantToolsFunction" - x-oaiExpandable: true - tool_resources: - type: object - description: | - A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs. - properties: - code_interpreter: - type: object - properties: - file_ids: - type: array - description: | - A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool. - default: [] - maxItems: 20 - items: - type: string - file_search: - type: object - properties: - vector_store_ids: - type: array - description: | - The [vector store](/docs/api-reference/vector-stores/object) attached to this assistant. There can be a maximum of 1 vector store attached to the assistant. - maxItems: 1 - items: - type: string - vector_stores: - type: array - description: | - A helper to create a [vector store](/docs/api-reference/vector-stores/object) with file_ids and attach it to this assistant. There can be a maximum of 1 vector store attached to the assistant. - maxItems: 1 - items: - type: object - properties: - file_ids: - type: array - description: | - A list of [file](/docs/api-reference/files) IDs to add to the vector store. There can be a maximum of 10000 files in a vector store. - maxItems: 10000 - items: - type: string - chunking_strategy: - # Ideally we'd reuse the chunking strategy schema here, but it doesn't expand properly - type: object - description: The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy. - oneOf: - - type: object - title: Auto Chunking Strategy - description: The default strategy. This strategy currently uses a `max_chunk_size_tokens` of `800` and `chunk_overlap_tokens` of `400`. - additionalProperties: false - properties: - type: - type: string - description: Always `auto`. - enum: ["auto"] - required: - - type - - type: object - title: Static Chunking Strategy - additionalProperties: false - properties: - type: - type: string - description: Always `static`. - enum: ["static"] - static: - type: object - additionalProperties: false - properties: - max_chunk_size_tokens: - type: integer - minimum: 100 - maximum: 4096 - description: The maximum number of tokens in each chunk. The default value is `800`. The minimum value is `100` and the maximum value is `4096`. - chunk_overlap_tokens: - type: integer - description: | - The number of tokens that overlap between chunks. The default value is `400`. - - Note that the overlap must not exceed half of `max_chunk_size_tokens`. - required: - - max_chunk_size_tokens - - chunk_overlap_tokens - required: - - type - - static - x-oaiExpandable: true - metadata: - type: object - description: | - Set of 16 key-value pairs that can be attached to a vector store. This can be useful for storing additional information about the vector store in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. - x-oaiTypeLabel: map - oneOf: - - required: [vector_store_ids] - - required: [vector_stores] - nullable: true - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - temperature: - description: &run_temperature_description | - What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. - type: number - minimum: 0 - maximum: 2 - default: 1 - example: 1 - nullable: true - top_p: - type: number - minimum: 0 - maximum: 1 - default: 1 - example: 1 - nullable: true - description: &run_top_p_description | - An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. - - We generally recommend altering this or temperature but not both. - response_format: - $ref: "#/components/schemas/AssistantsApiResponseFormatOption" - nullable: true - required: - - model - - ModifyAssistantRequest: - type: object - additionalProperties: false - properties: - model: - description: *model_description - anyOf: - - type: string - name: - description: *assistant_name_param_description - type: string - nullable: true - maxLength: 256 - description: - description: *assistant_description_param_description - type: string - nullable: true - maxLength: 512 - instructions: - description: *assistant_instructions_param_description - type: string - nullable: true - maxLength: 256000 - tools: - description: *assistant_tools_param_description - default: [] - type: array - maxItems: 128 - items: - oneOf: - - $ref: "#/components/schemas/AssistantToolsCode" - - $ref: "#/components/schemas/AssistantToolsFileSearch" - - $ref: "#/components/schemas/AssistantToolsFunction" - x-oaiExpandable: true - tool_resources: - type: object - description: | - A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs. - properties: - code_interpreter: - type: object - properties: - file_ids: - type: array - description: | - Overrides the list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool. - default: [] - maxItems: 20 - items: - type: string - file_search: - type: object - properties: - vector_store_ids: - type: array - description: | - Overrides the [vector store](/docs/api-reference/vector-stores/object) attached to this assistant. There can be a maximum of 1 vector store attached to the assistant. - maxItems: 1 - items: - type: string - nullable: true - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - temperature: - description: *run_temperature_description - type: number - minimum: 0 - maximum: 2 - default: 1 - example: 1 - nullable: true - top_p: - type: number - minimum: 0 - maximum: 1 - default: 1 - example: 1 - nullable: true - description: &run_top_p_description | - An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. - - We generally recommend altering this or temperature but not both. - response_format: - $ref: "#/components/schemas/AssistantsApiResponseFormatOption" - nullable: true - - DeleteAssistantResponse: - type: object - properties: - id: - type: string - deleted: - type: boolean - object: - type: string - enum: [assistant.deleted] - required: - - id - - object - - deleted - - ListAssistantsResponse: - type: object - properties: - object: - type: string - example: "list" - data: - type: array - items: - $ref: "#/components/schemas/AssistantObject" - first_id: - type: string - example: "asst_abc123" - last_id: - type: string - example: "asst_abc456" - has_more: - type: boolean - example: false - required: - - object - - data - - first_id - - last_id - - has_more - x-oaiMeta: - name: List assistants response object - group: chat - example: *list_assistants_example - - AssistantToolsCode: - type: object - title: Code interpreter tool - properties: - type: - type: string - description: "The type of tool being defined: `code_interpreter`" - enum: ["code_interpreter"] - required: - - type - - AssistantToolsFileSearch: - type: object - title: FileSearch tool - properties: - type: - type: string - description: "The type of tool being defined: `file_search`" - enum: ["file_search"] - file_search: - type: object - description: Overrides for the file search tool. - properties: - max_num_results: - type: integer - minimum: 1 - maximum: 50 - description: | - The maximum number of results the file search tool should output. The default is 20 for gpt-4* models and 5 for gpt-3.5-turbo. This number should be between 1 and 50 inclusive. - - Note that the file search tool may output fewer than `max_num_results` results. See the [file search tool documentation](/docs/assistants/tools/file-search/number-of-chunks-returned) for more information. - required: - - type - - AssistantToolsFileSearchTypeOnly: - type: object - title: FileSearch tool - properties: - type: - type: string - description: "The type of tool being defined: `file_search`" - enum: ["file_search"] - required: - - type - - AssistantToolsFunction: - type: object - title: Function tool - properties: - type: - type: string - description: "The type of tool being defined: `function`" - enum: ["function"] - function: - $ref: "#/components/schemas/FunctionObject" - required: - - type - - function - - TruncationObject: - type: object - title: Thread Truncation Controls - description: Controls for how a thread will be truncated prior to the run. Use this to control the intial context window of the run. - properties: - type: - type: string - description: The truncation strategy to use for the thread. The default is `auto`. If set to `last_messages`, the thread will be truncated to the n most recent messages in the thread. When set to `auto`, messages in the middle of the thread will be dropped to fit the context length of the model, `max_prompt_tokens`. - enum: ["auto", "last_messages"] - last_messages: - type: integer - description: The number of most recent messages from the thread when constructing the context for the run. - minimum: 1 - nullable: true - required: - - type - - AssistantsApiToolChoiceOption: - description: | - Controls which (if any) tool is called by the model. - `none` means the model will not call any tools and instead generates a message. - `auto` is the default value and means the model can pick between generating a message or calling one or more tools. - `required` means the model must call one or more tools before responding to the user. - Specifying a particular tool like `{"type": "file_search"}` or `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that tool. - - oneOf: - - type: string - description: > - `none` means the model will not call any tools and instead generates a message. - `auto` means the model can pick between generating a message or calling one or more tools. - `required` means the model must call one or more tools before responding to the user. - enum: [none, auto, required] - - $ref: "#/components/schemas/AssistantsNamedToolChoice" - x-oaiExpandable: true - - AssistantsNamedToolChoice: - type: object - description: Specifies a tool the model should use. Use to force the model to call a specific tool. - properties: - type: - type: string - enum: ["function", "code_interpreter", "file_search"] - description: The type of the tool. If type is `function`, the function name must be set - function: - type: object - properties: - name: - type: string - description: The name of the function to call. - required: - - name - required: - - type - - RunObject: - type: object - title: A run on a thread - description: Represents an execution run on a [thread](/docs/api-reference/threads). - properties: - id: - description: The identifier, which can be referenced in API endpoints. - type: string - object: - description: The object type, which is always `thread.run`. - type: string - enum: ["thread.run"] - created_at: - description: The Unix timestamp (in seconds) for when the run was created. - type: integer - thread_id: - description: The ID of the [thread](/docs/api-reference/threads) that was executed on as a part of this run. - type: string - assistant_id: - description: The ID of the [assistant](/docs/api-reference/assistants) used for execution of this run. - type: string - status: - description: The status of the run, which can be either `queued`, `in_progress`, `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`, `incomplete`, or `expired`. - type: string - enum: - [ - "queued", - "in_progress", - "requires_action", - "cancelling", - "cancelled", - "failed", - "completed", - "incomplete", - "expired", - ] - required_action: - type: object - description: Details on the action required to continue the run. Will be `null` if no action is required. - nullable: true - properties: - type: - description: For now, this is always `submit_tool_outputs`. - type: string - enum: ["submit_tool_outputs"] - submit_tool_outputs: - type: object - description: Details on the tool outputs needed for this run to continue. - properties: - tool_calls: - type: array - description: A list of the relevant tool calls. - items: - $ref: "#/components/schemas/RunToolCallObject" - required: - - tool_calls - required: - - type - - submit_tool_outputs - last_error: - type: object - description: The last error associated with this run. Will be `null` if there are no errors. - nullable: true - properties: - code: - type: string - description: One of `server_error`, `rate_limit_exceeded`, or `invalid_prompt`. - enum: - ["server_error", "rate_limit_exceeded", "invalid_prompt"] - message: - type: string - description: A human-readable description of the error. - required: - - code - - message - expires_at: - description: The Unix timestamp (in seconds) for when the run will expire. - type: integer - nullable: true - started_at: - description: The Unix timestamp (in seconds) for when the run was started. - type: integer - nullable: true - cancelled_at: - description: The Unix timestamp (in seconds) for when the run was cancelled. - type: integer - nullable: true - failed_at: - description: The Unix timestamp (in seconds) for when the run failed. - type: integer - nullable: true - completed_at: - description: The Unix timestamp (in seconds) for when the run was completed. - type: integer - nullable: true - incomplete_details: - description: Details on why the run is incomplete. Will be `null` if the run is not incomplete. - type: object - nullable: true - properties: - reason: - description: The reason why the run is incomplete. This will point to which specific token limit was reached over the course of the run. - type: string - enum: ["max_completion_tokens", "max_prompt_tokens"] - model: - description: The model that the [assistant](/docs/api-reference/assistants) used for this run. - type: string - instructions: - description: The instructions that the [assistant](/docs/api-reference/assistants) used for this run. - type: string - tools: - description: The list of tools that the [assistant](/docs/api-reference/assistants) used for this run. - default: [] - type: array - maxItems: 20 - items: - oneOf: - - $ref: "#/components/schemas/AssistantToolsCode" - - $ref: "#/components/schemas/AssistantToolsFileSearch" - - $ref: "#/components/schemas/AssistantToolsFunction" - x-oaiExpandable: true - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - usage: - $ref: "#/components/schemas/RunCompletionUsage" - temperature: - description: The sampling temperature used for this run. If not set, defaults to 1. - type: number - nullable: true - top_p: - description: The nucleus sampling value used for this run. If not set, defaults to 1. - type: number - nullable: true - max_prompt_tokens: - type: integer - nullable: true - description: | - The maximum number of prompt tokens specified to have been used over the course of the run. - minimum: 256 - max_completion_tokens: - type: integer - nullable: true - description: | - The maximum number of completion tokens specified to have been used over the course of the run. - minimum: 256 - truncation_strategy: - $ref: "#/components/schemas/TruncationObject" - nullable: true - tool_choice: - $ref: "#/components/schemas/AssistantsApiToolChoiceOption" - nullable: true - parallel_tool_calls: - $ref: "#/components/schemas/ParallelToolCalls" - response_format: - $ref: "#/components/schemas/AssistantsApiResponseFormatOption" - nullable: true - required: - - id - - object - - created_at - - thread_id - - assistant_id - - status - - required_action - - last_error - - expires_at - - started_at - - cancelled_at - - failed_at - - completed_at - - model - - instructions - - tools - - metadata - - usage - - incomplete_details - - max_prompt_tokens - - max_completion_tokens - - truncation_strategy - - tool_choice - - parallel_tool_calls - - response_format - x-oaiMeta: - name: The run object - beta: true - example: | - { - "id": "run_abc123", - "object": "thread.run", - "created_at": 1698107661, - "assistant_id": "asst_abc123", - "thread_id": "thread_abc123", - "status": "completed", - "started_at": 1699073476, - "expires_at": null, - "cancelled_at": null, - "failed_at": null, - "completed_at": 1699073498, - "last_error": null, - "model": "gpt-4-turbo", - "instructions": null, - "tools": [{"type": "file_search"}, {"type": "code_interpreter"}], - "metadata": {}, - "incomplete_details": null, - "usage": { - "prompt_tokens": 123, - "completion_tokens": 456, - "total_tokens": 579 - }, - "temperature": 1.0, - "top_p": 1.0, - "max_prompt_tokens": 1000, - "max_completion_tokens": 1000, - "truncation_strategy": { - "type": "auto", - "last_messages": null - }, - "response_format": "auto", - "tool_choice": "auto", - "parallel_tool_calls": true - } - CreateRunRequest: - type: object - additionalProperties: false - properties: - assistant_id: - description: The ID of the [assistant](/docs/api-reference/assistants) to use to execute this run. - type: string - model: - description: The ID of the [Model](/docs/api-reference/models) to be used to execute this run. If a value is provided here, it will override the model associated with the assistant. If not, the model associated with the assistant will be used. - example: "gpt-4-turbo" - anyOf: - - type: string - - type: string - enum: - [ - "gpt-4o", - "gpt-4o-2024-05-13", - "gpt-4o-mini", - "gpt-4o-mini-2024-07-18", - "gpt-4-turbo", - "gpt-4-turbo-2024-04-09", - "gpt-4-0125-preview", - "gpt-4-turbo-preview", - "gpt-4-1106-preview", - "gpt-4-vision-preview", - "gpt-4", - "gpt-4-0314", - "gpt-4-0613", - "gpt-4-32k", - "gpt-4-32k-0314", - "gpt-4-32k-0613", - "gpt-3.5-turbo", - "gpt-3.5-turbo-16k", - "gpt-3.5-turbo-0613", - "gpt-3.5-turbo-1106", - "gpt-3.5-turbo-0125", - "gpt-3.5-turbo-16k-0613", - ] - x-oaiTypeLabel: string - nullable: true - instructions: - description: Overrides the [instructions](/docs/api-reference/assistants/createAssistant) of the assistant. This is useful for modifying the behavior on a per-run basis. - type: string - nullable: true - additional_instructions: - description: Appends additional instructions at the end of the instructions for the run. This is useful for modifying the behavior on a per-run basis without overriding other instructions. - type: string - nullable: true - additional_messages: - description: Adds additional messages to the thread before creating the run. - type: array - items: - $ref: "#/components/schemas/CreateMessageRequest" - nullable: true - tools: - description: Override the tools the assistant can use for this run. This is useful for modifying the behavior on a per-run basis. - nullable: true - type: array - maxItems: 20 - items: - oneOf: - - $ref: "#/components/schemas/AssistantToolsCode" - - $ref: "#/components/schemas/AssistantToolsFileSearch" - - $ref: "#/components/schemas/AssistantToolsFunction" - x-oaiExpandable: true - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - temperature: - type: number - minimum: 0 - maximum: 2 - default: 1 - example: 1 - nullable: true - description: *run_temperature_description - top_p: - type: number - minimum: 0 - maximum: 1 - default: 1 - example: 1 - nullable: true - description: &run_top_p_description | - An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. - - We generally recommend altering this or temperature but not both. - stream: - type: boolean - nullable: true - description: | - If `true`, returns a stream of events that happen during the Run as server-sent events, terminating when the Run enters a terminal state with a `data: [DONE]` message. - max_prompt_tokens: - type: integer - nullable: true - description: | - The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info. - minimum: 256 - max_completion_tokens: - type: integer - nullable: true - description: | - The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort to use only the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of completion tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info. - minimum: 256 - truncation_strategy: - $ref: "#/components/schemas/TruncationObject" - nullable: true - tool_choice: - $ref: "#/components/schemas/AssistantsApiToolChoiceOption" - nullable: true - parallel_tool_calls: - $ref: "#/components/schemas/ParallelToolCalls" - response_format: - $ref: "#/components/schemas/AssistantsApiResponseFormatOption" - nullable: true - required: - - thread_id - - assistant_id - ListRunsResponse: - type: object - properties: - object: - type: string - example: "list" - data: - type: array - items: - $ref: "#/components/schemas/RunObject" - first_id: - type: string - example: "run_abc123" - last_id: - type: string - example: "run_abc456" - has_more: - type: boolean - example: false - required: - - object - - data - - first_id - - last_id - - has_more - ModifyRunRequest: - type: object - additionalProperties: false - properties: - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - SubmitToolOutputsRunRequest: - type: object - additionalProperties: false - properties: - tool_outputs: - description: A list of tools for which the outputs are being submitted. - type: array - items: - type: object - properties: - tool_call_id: - type: string - description: The ID of the tool call in the `required_action` object within the run object the output is being submitted for. - output: - type: string - description: The output of the tool call to be submitted to continue the run. - stream: - type: boolean - nullable: true - description: | - If `true`, returns a stream of events that happen during the Run as server-sent events, terminating when the Run enters a terminal state with a `data: [DONE]` message. - required: - - tool_outputs - - RunToolCallObject: - type: object - description: Tool call objects - properties: - id: - type: string - description: The ID of the tool call. This ID must be referenced when you submit the tool outputs in using the [Submit tool outputs to run](/docs/api-reference/runs/submitToolOutputs) endpoint. - type: - type: string - description: The type of tool call the output is required for. For now, this is always `function`. - enum: ["function"] - function: - type: object - description: The function definition. - properties: - name: - type: string - description: The name of the function. - arguments: - type: string - description: The arguments that the model expects you to pass to the function. - required: - - name - - arguments - required: - - id - - type - - function - - CreateThreadAndRunRequest: - type: object - additionalProperties: false - properties: - assistant_id: - description: The ID of the [assistant](/docs/api-reference/assistants) to use to execute this run. - type: string - thread: - $ref: "#/components/schemas/CreateThreadRequest" - description: If no thread is provided, an empty thread will be created. - model: - description: The ID of the [Model](/docs/api-reference/models) to be used to execute this run. If a value is provided here, it will override the model associated with the assistant. If not, the model associated with the assistant will be used. - example: "gpt-4-turbo" - anyOf: - - type: string - - type: string - enum: - [ - "gpt-4o", - "gpt-4o-2024-05-13", - "gpt-4o-mini", - "gpt-4o-mini-2024-07-18", - "gpt-4-turbo", - "gpt-4-turbo-2024-04-09", - "gpt-4-0125-preview", - "gpt-4-turbo-preview", - "gpt-4-1106-preview", - "gpt-4-vision-preview", - "gpt-4", - "gpt-4-0314", - "gpt-4-0613", - "gpt-4-32k", - "gpt-4-32k-0314", - "gpt-4-32k-0613", - "gpt-3.5-turbo", - "gpt-3.5-turbo-16k", - "gpt-3.5-turbo-0613", - "gpt-3.5-turbo-1106", - "gpt-3.5-turbo-0125", - "gpt-3.5-turbo-16k-0613", - ] - x-oaiTypeLabel: string - nullable: true - instructions: - description: Override the default system message of the assistant. This is useful for modifying the behavior on a per-run basis. - type: string - nullable: true - tools: - description: Override the tools the assistant can use for this run. This is useful for modifying the behavior on a per-run basis. - nullable: true - type: array - maxItems: 20 - items: - oneOf: - - $ref: "#/components/schemas/AssistantToolsCode" - - $ref: "#/components/schemas/AssistantToolsFileSearch" - - $ref: "#/components/schemas/AssistantToolsFunction" - tool_resources: - type: object - description: | - A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs. - properties: - code_interpreter: - type: object - properties: - file_ids: - type: array - description: | - A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool. - default: [] - maxItems: 20 - items: - type: string - file_search: - type: object - properties: - vector_store_ids: - type: array - description: | - The ID of the [vector store](/docs/api-reference/vector-stores/object) attached to this assistant. There can be a maximum of 1 vector store attached to the assistant. - maxItems: 1 - items: - type: string - nullable: true - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - temperature: - type: number - minimum: 0 - maximum: 2 - default: 1 - example: 1 - nullable: true - description: *run_temperature_description - top_p: - type: number - minimum: 0 - maximum: 1 - default: 1 - example: 1 - nullable: true - description: *run_top_p_description - stream: - type: boolean - nullable: true - description: | - If `true`, returns a stream of events that happen during the Run as server-sent events, terminating when the Run enters a terminal state with a `data: [DONE]` message. - max_prompt_tokens: - type: integer - nullable: true - description: | - The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info. - minimum: 256 - max_completion_tokens: - type: integer - nullable: true - description: | - The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort to use only the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of completion tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info. - minimum: 256 - truncation_strategy: - $ref: "#/components/schemas/TruncationObject" - nullable: true - tool_choice: - $ref: "#/components/schemas/AssistantsApiToolChoiceOption" - nullable: true - parallel_tool_calls: - $ref: "#/components/schemas/ParallelToolCalls" - response_format: - $ref: "#/components/schemas/AssistantsApiResponseFormatOption" - nullable: true - required: - - thread_id - - assistant_id - - ThreadObject: - type: object - title: Thread - description: Represents a thread that contains [messages](/docs/api-reference/messages). - properties: - id: - description: The identifier, which can be referenced in API endpoints. - type: string - object: - description: The object type, which is always `thread`. - type: string - enum: ["thread"] - created_at: - description: The Unix timestamp (in seconds) for when the thread was created. - type: integer - tool_resources: - type: object - description: | - A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs. - properties: - code_interpreter: - type: object - properties: - file_ids: - type: array - description: | - A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool. - default: [] - maxItems: 20 - items: - type: string - file_search: - type: object - properties: - vector_store_ids: - type: array - description: | - The [vector store](/docs/api-reference/vector-stores/object) attached to this thread. There can be a maximum of 1 vector store attached to the thread. - maxItems: 1 - items: - type: string - nullable: true - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - required: - - id - - object - - created_at - - tool_resources - - metadata - x-oaiMeta: - name: The thread object - beta: true - example: | - { - "id": "thread_abc123", - "object": "thread", - "created_at": 1698107661, - "metadata": {} - } - - CreateThreadRequest: - type: object - additionalProperties: false - properties: - messages: - description: A list of [messages](/docs/api-reference/messages) to start the thread with. - type: array - items: - $ref: "#/components/schemas/CreateMessageRequest" - tool_resources: - type: object - description: | - A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs. - properties: - code_interpreter: - type: object - properties: - file_ids: - type: array - description: | - A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool. - default: [] - maxItems: 20 - items: - type: string - file_search: - type: object - properties: - vector_store_ids: - type: array - description: | - The [vector store](/docs/api-reference/vector-stores/object) attached to this thread. There can be a maximum of 1 vector store attached to the thread. - maxItems: 1 - items: - type: string - vector_stores: - type: array - description: | - A helper to create a [vector store](/docs/api-reference/vector-stores/object) with file_ids and attach it to this thread. There can be a maximum of 1 vector store attached to the thread. - maxItems: 1 - items: - type: object - properties: - file_ids: - type: array - description: | - A list of [file](/docs/api-reference/files) IDs to add to the vector store. There can be a maximum of 10000 files in a vector store. - maxItems: 10000 - items: - type: string - chunking_strategy: - # Ideally we'd reuse the chunking strategy schema here, but it doesn't expand properly - type: object - description: The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy. - oneOf: - - type: object - title: Auto Chunking Strategy - description: The default strategy. This strategy currently uses a `max_chunk_size_tokens` of `800` and `chunk_overlap_tokens` of `400`. - additionalProperties: false - properties: - type: - type: string - description: Always `auto`. - enum: ["auto"] - required: - - type - - type: object - title: Static Chunking Strategy - additionalProperties: false - properties: - type: - type: string - description: Always `static`. - enum: ["static"] - static: - type: object - additionalProperties: false - properties: - max_chunk_size_tokens: - type: integer - minimum: 100 - maximum: 4096 - description: The maximum number of tokens in each chunk. The default value is `800`. The minimum value is `100` and the maximum value is `4096`. - chunk_overlap_tokens: - type: integer - description: | - The number of tokens that overlap between chunks. The default value is `400`. - - Note that the overlap must not exceed half of `max_chunk_size_tokens`. - required: - - max_chunk_size_tokens - - chunk_overlap_tokens - required: - - type - - static - x-oaiExpandable: true - metadata: - type: object - description: | - Set of 16 key-value pairs that can be attached to a vector store. This can be useful for storing additional information about the vector store in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. - x-oaiTypeLabel: map - x-oaiExpandable: true - oneOf: - - required: [vector_store_ids] - - required: [vector_stores] - nullable: true - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - - ModifyThreadRequest: - type: object - additionalProperties: false - properties: - tool_resources: - type: object - description: | - A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs. - properties: - code_interpreter: - type: object - properties: - file_ids: - type: array - description: | - A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool. - default: [] - maxItems: 20 - items: - type: string - file_search: - type: object - properties: - vector_store_ids: - type: array - description: | - The [vector store](/docs/api-reference/vector-stores/object) attached to this thread. There can be a maximum of 1 vector store attached to the thread. - maxItems: 1 - items: - type: string - nullable: true - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - - DeleteThreadResponse: - type: object - properties: - id: - type: string - deleted: - type: boolean - object: - type: string - enum: [thread.deleted] - required: - - id - - object - - deleted - - ListThreadsResponse: - properties: - object: - type: string - example: "list" - data: - type: array - items: - $ref: "#/components/schemas/ThreadObject" - first_id: - type: string - example: "asst_abc123" - last_id: - type: string - example: "asst_abc456" - has_more: - type: boolean - example: false - required: - - object - - data - - first_id - - last_id - - has_more - - MessageObject: - type: object - title: The message object - description: Represents a message within a [thread](/docs/api-reference/threads). - properties: - id: - description: The identifier, which can be referenced in API endpoints. - type: string - object: - description: The object type, which is always `thread.message`. - type: string - enum: ["thread.message"] - created_at: - description: The Unix timestamp (in seconds) for when the message was created. - type: integer - thread_id: - description: The [thread](/docs/api-reference/threads) ID that this message belongs to. - type: string - status: - description: The status of the message, which can be either `in_progress`, `incomplete`, or `completed`. - type: string - enum: ["in_progress", "incomplete", "completed"] - incomplete_details: - description: On an incomplete message, details about why the message is incomplete. - type: object - properties: - reason: - type: string - description: The reason the message is incomplete. - enum: - [ - "content_filter", - "max_tokens", - "run_cancelled", - "run_expired", - "run_failed", - ] - nullable: true - required: - - reason - completed_at: - description: The Unix timestamp (in seconds) for when the message was completed. - type: integer - nullable: true - incomplete_at: - description: The Unix timestamp (in seconds) for when the message was marked as incomplete. - type: integer - nullable: true - role: - description: The entity that produced the message. One of `user` or `assistant`. - type: string - enum: ["user", "assistant"] - content: - description: The content of the message in array of text and/or images. - type: array - items: - oneOf: - - $ref: "#/components/schemas/MessageContentImageFileObject" - - $ref: "#/components/schemas/MessageContentImageUrlObject" - - $ref: "#/components/schemas/MessageContentTextObject" - x-oaiExpandable: true - assistant_id: - description: If applicable, the ID of the [assistant](/docs/api-reference/assistants) that authored this message. - type: string - nullable: true - run_id: - description: The ID of the [run](/docs/api-reference/runs) associated with the creation of this message. Value is `null` when messages are created manually using the create message or create thread endpoints. - type: string - nullable: true - attachments: - type: array - items: - type: object - properties: - file_id: - type: string - description: The ID of the file to attach to the message. - tools: - description: The tools to add this file to. - type: array - items: - oneOf: - - $ref: "#/components/schemas/AssistantToolsCode" - - $ref: "#/components/schemas/AssistantToolsFileSearchTypeOnly" - x-oaiExpandable: true - description: A list of files attached to the message, and the tools they were added to. - nullable: true - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - required: - - id - - object - - created_at - - thread_id - - status - - incomplete_details - - completed_at - - incomplete_at - - role - - content - - assistant_id - - run_id - - attachments - - metadata - x-oaiMeta: - name: The message object - beta: true - example: | - { - "id": "msg_abc123", - "object": "thread.message", - "created_at": 1698983503, - "thread_id": "thread_abc123", - "role": "assistant", - "content": [ - { - "type": "text", - "text": { - "value": "Hi! How can I help you today?", - "annotations": [] - } - } - ], - "assistant_id": "asst_abc123", - "run_id": "run_abc123", - "attachments": [], - "metadata": {} - } - - MessageDeltaObject: - type: object - title: Message delta object - description: | - Represents a message delta i.e. any changed fields on a message during streaming. - properties: - id: - description: The identifier of the message, which can be referenced in API endpoints. - type: string - object: - description: The object type, which is always `thread.message.delta`. - type: string - enum: ["thread.message.delta"] - delta: - description: The delta containing the fields that have changed on the Message. - type: object - properties: - role: - description: The entity that produced the message. One of `user` or `assistant`. - type: string - enum: ["user", "assistant"] - content: - description: The content of the message in array of text and/or images. - type: array - items: - oneOf: - - $ref: "#/components/schemas/MessageDeltaContentImageFileObject" - - $ref: "#/components/schemas/MessageDeltaContentTextObject" - - $ref: "#/components/schemas/MessageDeltaContentImageUrlObject" - x-oaiExpandable: true - required: - - id - - object - - delta - x-oaiMeta: - name: The message delta object - beta: true - example: | - { - "id": "msg_123", - "object": "thread.message.delta", - "delta": { - "content": [ - { - "index": 0, - "type": "text", - "text": { "value": "Hello", "annotations": [] } - } - ] - } - } - - CreateMessageRequest: - type: object - additionalProperties: false - required: - - role - - content - properties: - role: - type: string - enum: ["user", "assistant"] - description: | - The role of the entity that is creating the message. Allowed values include: - - `user`: Indicates the message is sent by an actual user and should be used in most cases to represent user-generated messages. - - `assistant`: Indicates the message is generated by the assistant. Use this value to insert messages from the assistant into the conversation. - content: - oneOf: - - type: string - description: The text contents of the message. - title: Text content - - type: array - description: An array of content parts with a defined type, each can be of type `text` or images can be passed with `image_url` or `image_file`. Image types are only supported on [Vision-compatible models](/docs/models/overview). - title: Array of content parts - items: - oneOf: - - $ref: "#/components/schemas/MessageContentImageFileObject" - - $ref: "#/components/schemas/MessageContentImageUrlObject" - - $ref: "#/components/schemas/MessageRequestContentTextObject" - x-oaiExpandable: true - minItems: 1 - x-oaiExpandable: true - attachments: - type: array - items: - type: object - properties: - file_id: - type: string - description: The ID of the file to attach to the message. - tools: - description: The tools to add this file to. - type: array - items: - oneOf: - - $ref: "#/components/schemas/AssistantToolsCode" - - $ref: "#/components/schemas/AssistantToolsFileSearchTypeOnly" - x-oaiExpandable: true - description: A list of files attached to the message, and the tools they should be added to. - required: - - file_id - - tools - nullable: true - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - - ModifyMessageRequest: - type: object - additionalProperties: false - properties: - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - - DeleteMessageResponse: - type: object - properties: - id: - type: string - deleted: - type: boolean - object: - type: string - enum: [thread.message.deleted] - required: - - id - - object - - deleted - - ListMessagesResponse: - properties: - object: - type: string - example: "list" - data: - type: array - items: - $ref: "#/components/schemas/MessageObject" - first_id: - type: string - example: "msg_abc123" - last_id: - type: string - example: "msg_abc123" - has_more: - type: boolean - example: false - required: - - object - - data - - first_id - - last_id - - has_more - - MessageContentImageFileObject: - title: Image file - type: object - description: References an image [File](/docs/api-reference/files) in the content of a message. - properties: - type: - description: Always `image_file`. - type: string - enum: ["image_file"] - image_file: - type: object - properties: - file_id: - description: The [File](/docs/api-reference/files) ID of the image in the message content. Set `purpose="vision"` when uploading the File if you need to later display the file content. - type: string - detail: - type: string - description: Specifies the detail level of the image if specified by the user. `low` uses fewer tokens, you can opt in to high resolution using `high`. - enum: ["auto", "low", "high"] - default: "auto" - required: - - file_id - required: - - type - - image_file - - MessageDeltaContentImageFileObject: - title: Image file - type: object - description: References an image [File](/docs/api-reference/files) in the content of a message. - properties: - index: - type: integer - description: The index of the content part in the message. - type: - description: Always `image_file`. - type: string - enum: ["image_file"] - image_file: - type: object - properties: - file_id: - description: The [File](/docs/api-reference/files) ID of the image in the message content. Set `purpose="vision"` when uploading the File if you need to later display the file content. - type: string - detail: - type: string - description: Specifies the detail level of the image if specified by the user. `low` uses fewer tokens, you can opt in to high resolution using `high`. - enum: ["auto", "low", "high"] - default: "auto" - required: - - index - - type - - MessageContentImageUrlObject: - title: Image URL - type: object - description: References an image URL in the content of a message. - properties: - type: - type: string - enum: ["image_url"] - description: The type of the content part. - image_url: - type: object - properties: - url: - type: string - description: "The external URL of the image, must be a supported image types: jpeg, jpg, png, gif, webp." - format: uri - detail: - type: string - description: Specifies the detail level of the image. `low` uses fewer tokens, you can opt in to high resolution using `high`. Default value is `auto` - enum: ["auto", "low", "high"] - default: "auto" - required: - - url - required: - - type - - image_url - - MessageDeltaContentImageUrlObject: - title: Image URL - type: object - description: References an image URL in the content of a message. - properties: - index: - type: integer - description: The index of the content part in the message. - type: - description: Always `image_url`. - type: string - enum: ["image_url"] - image_url: - type: object - properties: - url: - description: "The URL of the image, must be a supported image types: jpeg, jpg, png, gif, webp." - type: string - detail: - type: string - description: Specifies the detail level of the image. `low` uses fewer tokens, you can opt in to high resolution using `high`. - enum: ["auto", "low", "high"] - default: "auto" - required: - - index - - type - - MessageContentTextObject: - title: Text - type: object - description: The text content that is part of a message. - properties: - type: - description: Always `text`. - type: string - enum: ["text"] - text: - type: object - properties: - value: - description: The data that makes up the text. - type: string - annotations: - type: array - items: - oneOf: - - $ref: "#/components/schemas/MessageContentTextAnnotationsFileCitationObject" - - $ref: "#/components/schemas/MessageContentTextAnnotationsFilePathObject" - x-oaiExpandable: true - required: - - value - - annotations - required: - - type - - text - - MessageRequestContentTextObject: - title: Text - type: object - description: The text content that is part of a message. - properties: - type: - description: Always `text`. - type: string - enum: ["text"] - text: - type: string - description: Text content to be sent to the model - required: - - type - - text - - MessageContentTextAnnotationsFileCitationObject: - title: File citation - type: object - description: A citation within the message that points to a specific quote from a specific File associated with the assistant or the message. Generated when the assistant uses the "file_search" tool to search files. - properties: - type: - description: Always `file_citation`. - type: string - enum: ["file_citation"] - text: - description: The text in the message content that needs to be replaced. - type: string - file_citation: - type: object - properties: - file_id: - description: The ID of the specific File the citation is from. - type: string - required: - - file_id - start_index: - type: integer - minimum: 0 - end_index: - type: integer - minimum: 0 - required: - - type - - text - - file_citation - - start_index - - end_index - - MessageContentTextAnnotationsFilePathObject: - title: File path - type: object - description: A URL for the file that's generated when the assistant used the `code_interpreter` tool to generate a file. - properties: - type: - description: Always `file_path`. - type: string - enum: ["file_path"] - text: - description: The text in the message content that needs to be replaced. - type: string - file_path: - type: object - properties: - file_id: - description: The ID of the file that was generated. - type: string - required: - - file_id - start_index: - type: integer - minimum: 0 - end_index: - type: integer - minimum: 0 - required: - - type - - text - - file_path - - start_index - - end_index - - MessageDeltaContentTextObject: - title: Text - type: object - description: The text content that is part of a message. - properties: - index: - type: integer - description: The index of the content part in the message. - type: - description: Always `text`. - type: string - enum: ["text"] - text: - type: object - properties: - value: - description: The data that makes up the text. - type: string - annotations: - type: array - items: - oneOf: - - $ref: "#/components/schemas/MessageDeltaContentTextAnnotationsFileCitationObject" - - $ref: "#/components/schemas/MessageDeltaContentTextAnnotationsFilePathObject" - x-oaiExpandable: true - required: - - index - - type - - MessageDeltaContentTextAnnotationsFileCitationObject: - title: File citation - type: object - description: A citation within the message that points to a specific quote from a specific File associated with the assistant or the message. Generated when the assistant uses the "file_search" tool to search files. - properties: - index: - type: integer - description: The index of the annotation in the text content part. - type: - description: Always `file_citation`. - type: string - enum: ["file_citation"] - text: - description: The text in the message content that needs to be replaced. - type: string - file_citation: - type: object - properties: - file_id: - description: The ID of the specific File the citation is from. - type: string - quote: - description: The specific quote in the file. - type: string - start_index: - type: integer - minimum: 0 - end_index: - type: integer - minimum: 0 - required: - - index - - type - - MessageDeltaContentTextAnnotationsFilePathObject: - title: File path - type: object - description: A URL for the file that's generated when the assistant used the `code_interpreter` tool to generate a file. - properties: - index: - type: integer - description: The index of the annotation in the text content part. - type: - description: Always `file_path`. - type: string - enum: ["file_path"] - text: - description: The text in the message content that needs to be replaced. - type: string - file_path: - type: object - properties: - file_id: - description: The ID of the file that was generated. - type: string - start_index: - type: integer - minimum: 0 - end_index: - type: integer - minimum: 0 - required: - - index - - type - - RunStepObject: - type: object - title: Run steps - description: | - Represents a step in execution of a run. - properties: - id: - description: The identifier of the run step, which can be referenced in API endpoints. - type: string - object: - description: The object type, which is always `thread.run.step`. - type: string - enum: ["thread.run.step"] - created_at: - description: The Unix timestamp (in seconds) for when the run step was created. - type: integer - assistant_id: - description: The ID of the [assistant](/docs/api-reference/assistants) associated with the run step. - type: string - thread_id: - description: The ID of the [thread](/docs/api-reference/threads) that was run. - type: string - run_id: - description: The ID of the [run](/docs/api-reference/runs) that this run step is a part of. - type: string - type: - description: The type of run step, which can be either `message_creation` or `tool_calls`. - type: string - enum: ["message_creation", "tool_calls"] - status: - description: The status of the run step, which can be either `in_progress`, `cancelled`, `failed`, `completed`, or `expired`. - type: string - enum: ["in_progress", "cancelled", "failed", "completed", "expired"] - step_details: - type: object - description: The details of the run step. - oneOf: - - $ref: "#/components/schemas/RunStepDetailsMessageCreationObject" - - $ref: "#/components/schemas/RunStepDetailsToolCallsObject" - x-oaiExpandable: true - last_error: - type: object - description: The last error associated with this run step. Will be `null` if there are no errors. - nullable: true - properties: - code: - type: string - description: One of `server_error` or `rate_limit_exceeded`. - enum: ["server_error", "rate_limit_exceeded"] - message: - type: string - description: A human-readable description of the error. - required: - - code - - message - expired_at: - description: The Unix timestamp (in seconds) for when the run step expired. A step is considered expired if the parent run is expired. - type: integer - nullable: true - cancelled_at: - description: The Unix timestamp (in seconds) for when the run step was cancelled. - type: integer - nullable: true - failed_at: - description: The Unix timestamp (in seconds) for when the run step failed. - type: integer - nullable: true - completed_at: - description: The Unix timestamp (in seconds) for when the run step completed. - type: integer - nullable: true - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - usage: - $ref: "#/components/schemas/RunStepCompletionUsage" - required: - - id - - object - - created_at - - assistant_id - - thread_id - - run_id - - type - - status - - step_details - - last_error - - expired_at - - cancelled_at - - failed_at - - completed_at - - metadata - - usage - x-oaiMeta: - name: The run step object - beta: true - example: *run_step_object_example - - RunStepDeltaObject: - type: object - title: Run step delta object - description: | - Represents a run step delta i.e. any changed fields on a run step during streaming. - properties: - id: - description: The identifier of the run step, which can be referenced in API endpoints. - type: string - object: - description: The object type, which is always `thread.run.step.delta`. - type: string - enum: ["thread.run.step.delta"] - delta: - description: The delta containing the fields that have changed on the run step. - type: object - properties: - step_details: - type: object - description: The details of the run step. - oneOf: - - $ref: "#/components/schemas/RunStepDeltaStepDetailsMessageCreationObject" - - $ref: "#/components/schemas/RunStepDeltaStepDetailsToolCallsObject" - x-oaiExpandable: true - required: - - id - - object - - delta - x-oaiMeta: - name: The run step delta object - beta: true - example: | - { - "id": "step_123", - "object": "thread.run.step.delta", - "delta": { - "step_details": { - "type": "tool_calls", - "tool_calls": [ - { - "index": 0, - "id": "call_123", - "type": "code_interpreter", - "code_interpreter": { "input": "", "outputs": [] } - } - ] - } - } - } - - ListRunStepsResponse: - properties: - object: - type: string - example: "list" - data: - type: array - items: - $ref: "#/components/schemas/RunStepObject" - first_id: - type: string - example: "step_abc123" - last_id: - type: string - example: "step_abc456" - has_more: - type: boolean - example: false - required: - - object - - data - - first_id - - last_id - - has_more - - RunStepDetailsMessageCreationObject: - title: Message creation - type: object - description: Details of the message creation by the run step. - properties: - type: - description: Always `message_creation`. - type: string - enum: ["message_creation"] - message_creation: - type: object - properties: - message_id: - type: string - description: The ID of the message that was created by this run step. - required: - - message_id - required: - - type - - message_creation - - RunStepDeltaStepDetailsMessageCreationObject: - title: Message creation - type: object - description: Details of the message creation by the run step. - properties: - type: - description: Always `message_creation`. - type: string - enum: ["message_creation"] - message_creation: - type: object - properties: - message_id: - type: string - description: The ID of the message that was created by this run step. - required: - - type - - RunStepDetailsToolCallsObject: - title: Tool calls - type: object - description: Details of the tool call. - properties: - type: - description: Always `tool_calls`. - type: string - enum: ["tool_calls"] - tool_calls: - type: array - description: | - An array of tool calls the run step was involved in. These can be associated with one of three types of tools: `code_interpreter`, `file_search`, or `function`. - items: - oneOf: - - $ref: "#/components/schemas/RunStepDetailsToolCallsCodeObject" - - $ref: "#/components/schemas/RunStepDetailsToolCallsFileSearchObject" - - $ref: "#/components/schemas/RunStepDetailsToolCallsFunctionObject" - x-oaiExpandable: true - required: - - type - - tool_calls - - RunStepDeltaStepDetailsToolCallsObject: - title: Tool calls - type: object - description: Details of the tool call. - properties: - type: - description: Always `tool_calls`. - type: string - enum: ["tool_calls"] - tool_calls: - type: array - description: | - An array of tool calls the run step was involved in. These can be associated with one of three types of tools: `code_interpreter`, `file_search`, or `function`. - items: - oneOf: - - $ref: "#/components/schemas/RunStepDeltaStepDetailsToolCallsCodeObject" - - $ref: "#/components/schemas/RunStepDeltaStepDetailsToolCallsFileSearchObject" - - $ref: "#/components/schemas/RunStepDeltaStepDetailsToolCallsFunctionObject" - x-oaiExpandable: true - required: - - type - - RunStepDetailsToolCallsCodeObject: - title: Code Interpreter tool call - type: object - description: Details of the Code Interpreter tool call the run step was involved in. - properties: - id: - type: string - description: The ID of the tool call. - type: - type: string - description: The type of tool call. This is always going to be `code_interpreter` for this type of tool call. - enum: ["code_interpreter"] - code_interpreter: - type: object - description: The Code Interpreter tool call definition. - required: - - input - - outputs - properties: - input: - type: string - description: The input to the Code Interpreter tool call. - outputs: - type: array - description: The outputs from the Code Interpreter tool call. Code Interpreter can output one or more items, including text (`logs`) or images (`image`). Each of these are represented by a different object type. - items: - type: object - oneOf: - - $ref: "#/components/schemas/RunStepDetailsToolCallsCodeOutputLogsObject" - - $ref: "#/components/schemas/RunStepDetailsToolCallsCodeOutputImageObject" - x-oaiExpandable: true - required: - - id - - type - - code_interpreter - - RunStepDeltaStepDetailsToolCallsCodeObject: - title: Code interpreter tool call - type: object - description: Details of the Code Interpreter tool call the run step was involved in. - properties: - index: - type: integer - description: The index of the tool call in the tool calls array. - id: - type: string - description: The ID of the tool call. - type: - type: string - description: The type of tool call. This is always going to be `code_interpreter` for this type of tool call. - enum: ["code_interpreter"] - code_interpreter: - type: object - description: The Code Interpreter tool call definition. - properties: - input: - type: string - description: The input to the Code Interpreter tool call. - outputs: - type: array - description: The outputs from the Code Interpreter tool call. Code Interpreter can output one or more items, including text (`logs`) or images (`image`). Each of these are represented by a different object type. - items: - type: object - oneOf: - - $ref: "#/components/schemas/RunStepDeltaStepDetailsToolCallsCodeOutputLogsObject" - - $ref: "#/components/schemas/RunStepDeltaStepDetailsToolCallsCodeOutputImageObject" - x-oaiExpandable: true - required: - - index - - type - - RunStepDetailsToolCallsCodeOutputLogsObject: - title: Code Interpreter log output - type: object - description: Text output from the Code Interpreter tool call as part of a run step. - properties: - type: - description: Always `logs`. - type: string - enum: ["logs"] - logs: - type: string - description: The text output from the Code Interpreter tool call. - required: - - type - - logs - - RunStepDeltaStepDetailsToolCallsCodeOutputLogsObject: - title: Code interpreter log output - type: object - description: Text output from the Code Interpreter tool call as part of a run step. - properties: - index: - type: integer - description: The index of the output in the outputs array. - type: - description: Always `logs`. - type: string - enum: ["logs"] - logs: - type: string - description: The text output from the Code Interpreter tool call. - required: - - index - - type - - RunStepDetailsToolCallsCodeOutputImageObject: - title: Code Interpreter image output - type: object - properties: - type: - description: Always `image`. - type: string - enum: ["image"] - image: - type: object - properties: - file_id: - description: The [file](/docs/api-reference/files) ID of the image. - type: string - required: - - file_id - required: - - type - - image - - RunStepDeltaStepDetailsToolCallsCodeOutputImageObject: - title: Code interpreter image output - type: object - properties: - index: - type: integer - description: The index of the output in the outputs array. - type: - description: Always `image`. - type: string - enum: ["image"] - image: - type: object - properties: - file_id: - description: The [file](/docs/api-reference/files) ID of the image. - type: string - required: - - index - - type - - RunStepDetailsToolCallsFileSearchObject: - title: File search tool call - type: object - properties: - id: - type: string - description: The ID of the tool call object. - type: - type: string - description: The type of tool call. This is always going to be `file_search` for this type of tool call. - enum: ["file_search"] - file_search: - type: object - description: For now, this is always going to be an empty object. - x-oaiTypeLabel: map - required: - - id - - type - - file_search - - RunStepDeltaStepDetailsToolCallsFileSearchObject: - title: File search tool call - type: object - properties: - index: - type: integer - description: The index of the tool call in the tool calls array. - id: - type: string - description: The ID of the tool call object. - type: - type: string - description: The type of tool call. This is always going to be `file_search` for this type of tool call. - enum: ["file_search"] - file_search: - type: object - description: For now, this is always going to be an empty object. - x-oaiTypeLabel: map - required: - - index - - type - - file_search - - RunStepDetailsToolCallsFunctionObject: - type: object - title: Function tool call - properties: - id: - type: string - description: The ID of the tool call object. - type: - type: string - description: The type of tool call. This is always going to be `function` for this type of tool call. - enum: ["function"] - function: - type: object - description: The definition of the function that was called. - properties: - name: - type: string - description: The name of the function. - arguments: - type: string - description: The arguments passed to the function. - output: - type: string - description: The output of the function. This will be `null` if the outputs have not been [submitted](/docs/api-reference/runs/submitToolOutputs) yet. - nullable: true - required: - - name - - arguments - - output - required: - - id - - type - - function - - RunStepDeltaStepDetailsToolCallsFunctionObject: - type: object - title: Function tool call - properties: - index: - type: integer - description: The index of the tool call in the tool calls array. - id: - type: string - description: The ID of the tool call object. - type: - type: string - description: The type of tool call. This is always going to be `function` for this type of tool call. - enum: ["function"] - function: - type: object - description: The definition of the function that was called. - properties: - name: - type: string - description: The name of the function. - arguments: - type: string - description: The arguments passed to the function. - output: - type: string - description: The output of the function. This will be `null` if the outputs have not been [submitted](/docs/api-reference/runs/submitToolOutputs) yet. - nullable: true - required: - - index - - type - - VectorStoreExpirationAfter: - type: object - title: Vector store expiration policy - description: The expiration policy for a vector store. - properties: - anchor: - description: "Anchor timestamp after which the expiration policy applies. Supported anchors: `last_active_at`." - type: string - enum: ["last_active_at"] - days: - description: The number of days after the anchor time that the vector store will expire. - type: integer - minimum: 1 - maximum: 365 - required: - - anchor - - days - - VectorStoreObject: - type: object - title: Vector store - description: A vector store is a collection of processed files can be used by the `file_search` tool. - properties: - id: - description: The identifier, which can be referenced in API endpoints. - type: string - object: - description: The object type, which is always `vector_store`. - type: string - enum: ["vector_store"] - created_at: - description: The Unix timestamp (in seconds) for when the vector store was created. - type: integer - name: - description: The name of the vector store. - type: string - usage_bytes: - description: The total number of bytes used by the files in the vector store. - type: integer - file_counts: - type: object - properties: - in_progress: - description: The number of files that are currently being processed. - type: integer - completed: - description: The number of files that have been successfully processed. - type: integer - failed: - description: The number of files that have failed to process. - type: integer - cancelled: - description: The number of files that were cancelled. - type: integer - total: - description: The total number of files. - type: integer - required: - - in_progress - - completed - - failed - - cancelled - - total - status: - description: The status of the vector store, which can be either `expired`, `in_progress`, or `completed`. A status of `completed` indicates that the vector store is ready for use. - type: string - enum: ["expired", "in_progress", "completed"] - expires_after: - $ref: "#/components/schemas/VectorStoreExpirationAfter" - expires_at: - description: The Unix timestamp (in seconds) for when the vector store will expire. - type: integer - nullable: true - last_active_at: - description: The Unix timestamp (in seconds) for when the vector store was last active. - type: integer - nullable: true - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - required: - - id - - object - - usage_bytes - - created_at - - status - - last_active_at - - name - - file_counts - - metadata - x-oaiMeta: - name: The vector store object - beta: true - example: | - { - "id": "vs_123", - "object": "vector_store", - "created_at": 1698107661, - "usage_bytes": 123456, - "last_active_at": 1698107661, - "name": "my_vector_store", - "status": "completed", - "file_counts": { - "in_progress": 0, - "completed": 100, - "cancelled": 0, - "failed": 0, - "total": 100 - }, - "metadata": {}, - "last_used_at": 1698107661 - } - - CreateVectorStoreRequest: - type: object - additionalProperties: false - properties: - file_ids: - description: A list of [File](/docs/api-reference/files) IDs that the vector store should use. Useful for tools like `file_search` that can access files. - type: array - maxItems: 500 - items: - type: string - name: - description: The name of the vector store. - type: string - expires_after: - $ref: "#/components/schemas/VectorStoreExpirationAfter" - chunking_strategy: - type: object - description: The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy. Only applicable if `file_ids` is non-empty. - oneOf: - - $ref: "#/components/schemas/AutoChunkingStrategyRequestParam" - - $ref: "#/components/schemas/StaticChunkingStrategyRequestParam" - x-oaiExpandable: true - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - - UpdateVectorStoreRequest: - type: object - additionalProperties: false - properties: - name: - description: The name of the vector store. - type: string - nullable: true - expires_after: - $ref: "#/components/schemas/VectorStoreExpirationAfter" - nullable: true - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - - ListVectorStoresResponse: - properties: - object: - type: string - example: "list" - data: - type: array - items: - $ref: "#/components/schemas/VectorStoreObject" - first_id: - type: string - example: "vs_abc123" - last_id: - type: string - example: "vs_abc456" - has_more: - type: boolean - example: false - required: - - object - - data - - first_id - - last_id - - has_more - - DeleteVectorStoreResponse: - type: object - properties: - id: - type: string - deleted: - type: boolean - object: - type: string - enum: [vector_store.deleted] - required: - - id - - object - - deleted - - VectorStoreFileObject: - type: object - title: Vector store files - description: A list of files attached to a vector store. - properties: - id: - description: The identifier, which can be referenced in API endpoints. - type: string - object: - description: The object type, which is always `vector_store.file`. - type: string - enum: ["vector_store.file"] - usage_bytes: - description: The total vector store usage in bytes. Note that this may be different from the original file size. - type: integer - created_at: - description: The Unix timestamp (in seconds) for when the vector store file was created. - type: integer - vector_store_id: - description: The ID of the [vector store](/docs/api-reference/vector-stores/object) that the [File](/docs/api-reference/files) is attached to. - type: string - status: - description: The status of the vector store file, which can be either `in_progress`, `completed`, `cancelled`, or `failed`. The status `completed` indicates that the vector store file is ready for use. - type: string - enum: ["in_progress", "completed", "cancelled", "failed"] - last_error: - type: object - description: The last error associated with this vector store file. Will be `null` if there are no errors. - nullable: true - properties: - code: - type: string - description: One of `server_error` or `rate_limit_exceeded`. - enum: - [ - "internal_error", - "file_not_found", - "parsing_error", - "unhandled_mime_type", - ] - message: - type: string - description: A human-readable description of the error. - required: - - code - - message - chunking_strategy: - type: object - description: The strategy used to chunk the file. - oneOf: - - $ref: "#/components/schemas/StaticChunkingStrategyResponseParam" - - $ref: "#/components/schemas/OtherChunkingStrategyResponseParam" - x-oaiExpandable: true - required: - - id - - object - - usage_bytes - - created_at - - vector_store_id - - status - - last_error - x-oaiMeta: - name: The vector store file object - beta: true - example: | + - gpt-3.5-turbo-instruct + - davinci-002 + - babbage-002 + x-oaiTypeLabel: string + stream_options: + allOf: + - $ref: '#/components/schemas/ChatCompletionStreamOptions' + x-ballerina-name: streamOptions + prompt: + description: | + The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays. + + Note that <|endoftext|> is the document separator that the model sees during training, so if a prompt is not specified the model will generate as if from the beginning of a new document + nullable: true + oneOf: + - type: string + example: This is a test. + default: "" + - type: array + items: + type: string + example: This is a test. + default: "" + - minItems: 1 + type: array + example: "[1212, 318, 257, 1332, 13]" + items: + type: integer + - minItems: 1 + type: array + example: "[[1212, 318, 257, 1332, 13]]" + items: + minItems: 1 + type: array + items: + type: integer + default: <|endoftext|> + user: + type: string + description: | + A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids) + example: user-1234 + CreateCompletionResponse: + required: + - choices + - created + - id + - model + - object + type: object + properties: + created: + type: integer + description: The Unix timestamp (in seconds) of when the completion was + created + usage: + $ref: '#/components/schemas/CompletionUsage' + model: + type: string + description: The model used for completion + id: + type: string + description: A unique identifier for the completion + choices: + type: array + description: The list of completion choices the model generated for the + input prompt + items: + $ref: '#/components/schemas/CreateCompletionResponseChoices' + system_fingerprint: + type: string + description: | + This fingerprint represents the backend configuration that the model runs with. + + Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism + x-ballerina-name: systemFingerprint + object: + type: string + description: "The object type, which is always \"text_completion\"" + enum: + - text_completion + description: | + Represents a completion response from the API. Note: both the streamed and non-streamed response objects share the same shape (unlike the chat endpoint) + x-oaiMeta: + name: The completion object + legacy: true + example: | + { + "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7", + "object": "text_completion", + "created": 1589478378, + "model": "gpt-4-turbo", + "choices": [ + { + "text": "\n\nThis is indeed a test", + "index": 0, + "logprobs": null, + "finish_reason": "length" + } + ], + "usage": { + "prompt_tokens": 5, + "completion_tokens": 7, + "total_tokens": 12 + } + } + AssistantToolsFunction: + title: Function tool + required: + - function + - type + type: object + properties: + function: + $ref: '#/components/schemas/FunctionObject' + type: + type: string + description: "The type of tool being defined: `function`" + enum: + - function + CreateChatCompletionResponseLogprobs: + required: + - content + type: object + properties: + content: + type: array + description: A list of message content tokens with log probability information + nullable: true + items: + $ref: '#/components/schemas/ChatCompletionTokenLogprob' + description: Log probability information for the choice + nullable: true + TruncationObject: + title: Thread Truncation Controls + required: + - type + type: object + properties: + last_messages: + minimum: 1 + type: integer + description: The number of most recent messages from the thread when constructing + the context for the run + nullable: true + x-ballerina-name: lastMessages + type: + type: string + description: "The truncation strategy to use for the thread. The default\ + \ is `auto`. If set to `last_messages`, the thread will be truncated to\ + \ the n most recent messages in the thread. When set to `auto`, messages\ + \ in the middle of the thread will be dropped to fit the context length\ + \ of the model, `max_prompt_tokens`" + enum: + - auto + - last_messages + description: Controls for how a thread will be truncated prior to the run. Use + this to control the intial context window of the run + ListThreadsResponse: + required: + - data + - first_id + - has_more + - last_id + - object + properties: + object: + type: string + example: list + data: + type: array + items: + $ref: '#/components/schemas/ThreadObject' + first_id: + type: string + example: asst_abc123 + last_id: + type: string + example: asst_abc456 + has_more: + type: boolean + example: false + ErrorResponse: + required: + - error + type: object + properties: + error: + $ref: '#/components/schemas/Error' + AssistantsApiResponseFormat: + type: object + properties: + type: + type: string + description: Must be one of `text` or `json_object` + example: json_object + default: text + enum: + - text + - json_object + description: | + An object describing the expected output of the model. If `json_object` only `function` type `tools` are allowed to be passed to the Run. If `text` the model can return text or any value needed + RunStepDetailsToolCallsObjectToolCalls: + oneOf: + - $ref: '#/components/schemas/RunStepDetailsToolCallsCodeObject' + - $ref: '#/components/schemas/RunStepDetailsToolCallsFileSearchObject' + - $ref: '#/components/schemas/RunStepDetailsToolCallsFunctionObject' + x-oaiExpandable: true + VectorStoreObjectFileCounts: + required: + - cancelled + - completed + - failed + - in_progress + - total + type: object + properties: + in_progress: + type: integer + description: The number of files that are currently being processed + x-ballerina-name: inProgress + total: + type: integer + description: The total number of files + cancelled: + type: integer + description: The number of files that were cancelled + completed: + type: integer + description: The number of files that have been successfully processed + failed: + type: integer + description: The number of files that have failed to process + RunStepDeltaStepDetailsMessageCreationObjectMessageCreation: + type: object + properties: + message_id: + type: string + description: The ID of the message that was created by this run step + x-ballerina-name: messageId + ListMessagesResponse: + required: + - data + - first_id + - has_more + - last_id + - object + properties: + object: + type: string + example: list + data: + type: array + items: + $ref: '#/components/schemas/MessageObject' + first_id: + type: string + example: msg_abc123 + last_id: + type: string + example: msg_abc123 + has_more: + type: boolean + example: false + CreateChatCompletionRequestResponseFormat: + type: object + properties: + type: + type: string + description: Must be one of `text` or `json_object` + example: json_object + default: text + enum: + - text + - json_object + description: | + An object specifying the format that the model must output. Compatible with [GPT-4 Turbo](/docs/models/gpt-4-and-gpt-4-turbo) and all GPT-3.5 Turbo models newer than `gpt-3.5-turbo-1106`. + + Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is valid JSON. + + **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length + FineTuningJobHyperparameters: + required: + - n_epochs + type: object + properties: + n_epochs: + description: |- + The number of epochs to train the model for. An epoch refers to one full cycle through the training dataset. + "auto" decides the optimal number of epochs based on the size of the dataset. If setting the number manually, we support any number between 1 and 50 epochs + oneOf: + - type: string + enum: + - auto + - maximum: 50 + minimum: 1 + type: integer + default: auto + x-ballerina-name: nEpochs + description: "The hyperparameters used for the fine-tuning job. See the [fine-tuning\ + \ guide](/docs/guides/fine-tuning) for more details" + ListAssistantsResponse: + required: + - data + - first_id + - has_more + - last_id + - object + type: object + properties: + first_id: + type: string + example: asst_abc123 + x-ballerina-name: firstId + data: + type: array + items: + $ref: '#/components/schemas/AssistantObject' + last_id: + type: string + example: asst_abc456 + x-ballerina-name: lastId + has_more: + type: boolean + example: false + x-ballerina-name: hasMore + object: + type: string + example: list + x-oaiMeta: + name: List assistants response object + group: chat + example: | + { + "object": "list", + "data": [ + { + "id": "asst_abc123", + "object": "assistant", + "created_at": 1698982736, + "name": "Coding Tutor", + "description": null, + "model": "gpt-4-turbo", + "instructions": "You are a helpful assistant designed to make me better at coding!", + "tools": [], + "tool_resources": {}, + "metadata": {}, + "top_p": 1.0, + "temperature": 1.0, + "response_format": "auto" + }, + { + "id": "asst_abc456", + "object": "assistant", + "created_at": 1698982718, + "name": "My Assistant", + "description": null, + "model": "gpt-4-turbo", + "instructions": "You are a helpful assistant designed to make me better at coding!", + "tools": [], + "tool_resources": {}, + "metadata": {}, + "top_p": 1.0, + "temperature": 1.0, + "response_format": "auto" + }, + { + "id": "asst_abc789", + "object": "assistant", + "created_at": 1698982643, + "name": null, + "description": null, + "model": "gpt-4-turbo", + "instructions": null, + "tools": [], + "tool_resources": {}, + "metadata": {}, + "top_p": 1.0, + "temperature": 1.0, + "response_format": "auto" + } + ], + "first_id": "asst_abc123", + "last_id": "asst_abc789", + "has_more": false + } + ChatCompletionNamedToolChoiceFunction: + required: + - name + type: object + properties: + name: + type: string + description: The name of the function to call + CreateChatCompletionStreamResponseUsage: + required: + - completion_tokens + - prompt_tokens + - total_tokens + type: object + properties: + completion_tokens: + type: integer + description: Number of tokens in the generated completion + x-ballerina-name: completionTokens + prompt_tokens: + type: integer + description: Number of tokens in the prompt + x-ballerina-name: promptTokens + total_tokens: + type: integer + description: Total number of tokens used in the request (prompt + completion) + x-ballerina-name: totalTokens + description: | + An optional field that will only be present when you set `stream_options: {"include_usage": true}` in your request. + When present, it contains a null value except for the last chunk which contains the token usage statistics for the entire request + CreateThreadAndRunRequestToolResourcesFileSearch: + type: object + properties: + vector_store_ids: + maxItems: 1 + type: array + description: | + The ID of the [vector store](/docs/api-reference/vector-stores/object) attached to this assistant. There can be a maximum of 1 vector store attached to the assistant + items: + type: string + x-ballerina-name: vectorStoreIds + ThreadObjectToolResources: + type: object + properties: + code_interpreter: + allOf: + - $ref: '#/components/schemas/ThreadObjectToolResourcesCodeInterpreter' + x-ballerina-name: codeInterpreter + file_search: + allOf: + - $ref: '#/components/schemas/ThreadObjectToolResourcesFileSearch' + x-ballerina-name: fileSearch + description: | + A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs + nullable: true + InlineResponse2001: + oneOf: + - $ref: '#/components/schemas/CreateTranslationResponseJson' + - $ref: '#/components/schemas/CreateTranslationResponseVerboseJson' + MessageRequestContentTextObject: + title: Text + required: + - text + - type + type: object + properties: + text: + type: string + description: Text content to be sent to the model + type: + type: string + description: Always `text` + enum: + - text + description: The text content that is part of a message + CreateThreadAndRunRequestTools: + oneOf: + - $ref: '#/components/schemas/AssistantToolsCode' + - $ref: '#/components/schemas/AssistantToolsFileSearch' + - $ref: '#/components/schemas/AssistantToolsFunction' + RunStepDetailsToolCallsCodeObjectCodeInterpreterOutputs: + type: object + oneOf: + - $ref: '#/components/schemas/RunStepDetailsToolCallsCodeOutputLogsObject' + - $ref: '#/components/schemas/RunStepDetailsToolCallsCodeOutputImageObject' + x-oaiExpandable: true + CreateTranscriptionResponseJson: + required: + - text + type: object + properties: + text: + type: string + description: The transcribed text + description: "Represents a transcription response returned by model, based on\ + \ the provided input" + x-oaiMeta: + name: The transcription object (JSON) + group: audio + example: | + { + "text": "Imagine the wildest idea that you've ever had, and you're curious about how it might scale to something that's a 100, a 1,000 times bigger. This is a place where you can get to do that." + } + RunStepCompletionUsage: + required: + - completion_tokens + - prompt_tokens + - total_tokens + type: object + properties: + completion_tokens: + type: integer + description: Number of completion tokens used over the course of the run + step + x-ballerina-name: completionTokens + prompt_tokens: + type: integer + description: Number of prompt tokens used over the course of the run step + x-ballerina-name: promptTokens + total_tokens: + type: integer + description: Total number of tokens used (prompt + completion) + x-ballerina-name: totalTokens + description: Usage statistics related to the run step. This value will be `null` + while the run step's status is `in_progress` + nullable: true + TranscriptionSegment: + required: + - avg_logprob + - compression_ratio + - end + - id + - no_speech_prob + - seek + - start + - temperature + - text + - tokens + type: object + properties: + start: + type: number + description: Start time of the segment in seconds + format: float + temperature: + type: number + description: Temperature parameter used for generating the segment + format: float + avg_logprob: + type: number + description: "Average logprob of the segment. If the value is lower than\ + \ -1, consider the logprobs failed" + format: float + x-ballerina-name: avgLogprob + no_speech_prob: + type: number + description: "Probability of no speech in the segment. If the value is higher\ + \ than 1.0 and the `avg_logprob` is below -1, consider this segment silent" + format: float + x-ballerina-name: noSpeechProb + end: + type: number + description: End time of the segment in seconds + format: float + tokens: + type: array + description: Array of token IDs for the text content + items: + type: integer + id: + type: integer + description: Unique identifier of the segment + text: + type: string + description: Text content of the segment + seek: + type: integer + description: Seek offset of the segment + compression_ratio: + type: number + description: "Compression ratio of the segment. If the value is greater\ + \ than 2.4, consider the compression failed" + format: float + x-ballerina-name: compressionRatio + DeleteVectorStoreFileResponse: + required: + - deleted + - id + - object + type: object + properties: + deleted: + type: boolean + id: + type: string + object: + type: string + enum: + - vector_store.file.deleted + CreateImageRequest: + required: + - prompt + type: object + properties: + response_format: + type: string + description: The format in which the generated images are returned. Must + be one of `url` or `b64_json`. URLs are only valid for 60 minutes after + the image has been generated + nullable: true + example: url + default: url + enum: + - url + - b64_json + x-ballerina-name: responseFormat + size: + type: string + description: "The size of the generated images. Must be one of `256x256`,\ + \ `512x512`, or `1024x1024` for `dall-e-2`. Must be one of `1024x1024`,\ + \ `1792x1024`, or `1024x1792` for `dall-e-3` models" + nullable: true + example: 1024x1024 + default: 1024x1024 + enum: + - 256x256 + - 512x512 + - 1024x1024 + - 1792x1024 + - 1024x1792 + model: + description: The model to use for image generation + nullable: true + example: dall-e-3 + anyOf: + - type: string + - type: string + enum: + - dall-e-2 + - dall-e-3 + default: dall-e-2 + x-oaiTypeLabel: string + style: + type: string + description: "The style of the generated images. Must be one of `vivid`\ + \ or `natural`. Vivid causes the model to lean towards generating hyper-real\ + \ and dramatic images. Natural causes the model to produce more natural,\ + \ less hyper-real looking images. This param is only supported for `dall-e-3`" + nullable: true + example: vivid + default: vivid + enum: + - vivid + - natural + prompt: + type: string + description: A text description of the desired image(s). The maximum length + is 1000 characters for `dall-e-2` and 4000 characters for `dall-e-3` + example: A cute baby sea otter + user: + type: string + description: | + A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids) + example: user-1234 + "n": + maximum: 10 + minimum: 1 + type: integer + description: "The number of images to generate. Must be between 1 and 10.\ + \ For `dall-e-3`, only `n=1` is supported" + nullable: true + example: 1 + default: 1 + quality: + type: string + description: The quality of the image that will be generated. `hd` creates + images with finer details and greater consistency across the image. This + param is only supported for `dall-e-3` + example: standard + default: standard + enum: + - standard + - hd + BatchErrors: + type: object + properties: + data: + type: array + items: + $ref: '#/components/schemas/BatchErrorsData' + object: + type: string + description: "The object type, which is always `list`" + CancelUploadRequest: + type: object + additionalProperties: false + ChatCompletionToolChoiceOptionOneOf1: + type: string + description: | + `none` means the model will not call any tool and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `required` means the model must call one or more tools + enum: + - none + - auto + - required + RunObjectRequiredActionSubmitToolOutputs: + required: + - tool_calls + type: object + properties: + tool_calls: + type: array + description: A list of the relevant tool calls + items: + $ref: '#/components/schemas/RunToolCallObject' + x-ballerina-name: toolCalls + description: Details on the tool outputs needed for this run to continue + ModifyThreadRequestToolResourcesFileSearch: + type: object + properties: + vector_store_ids: + maxItems: 1 + type: array + description: | + The [vector store](/docs/api-reference/vector-stores/object) attached to this thread. There can be a maximum of 1 vector store attached to the thread + items: + type: string + x-ballerina-name: vectorStoreIds + MessageStreamEventMessageStreamEventOneOf12: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/MessageObject' + event: + type: string + enum: + - thread.message.in_progress + description: "Occurs when a [message](/docs/api-reference/messages/object) moves\ + \ to an `in_progress` state" + x-oaiMeta: + dataDescription: "`data` is a [message](/docs/api-reference/messages/object)" + CreateTranscriptionRequest: + required: + - file + - model + type: object + properties: + timestamp_granularities[]: + type: array + description: | + The timestamp granularities to populate for this transcription. `response_format` must be set `verbose_json` to use timestamp granularities. Either or both of these options are supported: `word`, or `segment`. Note: There is no additional latency for segment timestamps, but generating word timestamps incurs additional latency + items: + type: string + enum: + - word + - segment + default: + - segment + x-ballerina-name: timestampGranularities + file: + type: string + description: | + The audio file object (not file name) to transcribe, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm + format: binary + x-oaiTypeLabel: file + response_format: + type: string + description: | + The format of the transcript output, in one of these options: `json`, `text`, `srt`, `verbose_json`, or `vtt` + default: json + enum: + - json + - text + - srt + - verbose_json + - vtt + x-ballerina-name: responseFormat + temperature: + type: number + description: | + The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit + default: 0 + model: + description: | + ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2 model) is currently available + example: whisper-1 + anyOf: + - type: string + - type: string + enum: + - whisper-1 + x-oaiTypeLabel: string + language: + type: string + description: | + The language of the input audio. Supplying the input language in [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) format will improve accuracy and latency + prompt: + type: string + description: | + An optional text to guide the model's style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text/prompting) should match the audio language + additionalProperties: false + RunObjectIncompleteDetails: + type: object + properties: + reason: + type: string + description: The reason why the run is incomplete. This will point to which + specific token limit was reached over the course of the run + enum: + - max_completion_tokens + - max_prompt_tokens + description: Details on why the run is incomplete. Will be `null` if the run + is not incomplete + nullable: true + RunStepStreamEventOneOf1: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunStepObject' + event: + type: string + enum: + - thread.run.step.created + description: "Occurs when a [run step](/docs/api-reference/runs/step-object)\ + \ is created" + x-oaiMeta: + dataDescription: "`data` is a [run step](/docs/api-reference/runs/step-object)" + MessageContentTextAnnotationsFileCitationObjectFileCitation: + required: + - file_id + type: object + properties: + file_id: + type: string + description: The ID of the specific File the citation is from + x-ballerina-name: fileId + SubmitToolOutputsRunRequestToolOutputs: + type: object + properties: + output: + type: string + description: The output of the tool call to be submitted to continue the + run + tool_call_id: + type: string + description: The ID of the tool call in the `required_action` object within + the run object the output is being submitted for + x-ballerina-name: toolCallId + ListBatchesResponse: + required: + - data + - has_more + - object + type: object + properties: + first_id: + type: string + example: batch_abc123 + x-ballerina-name: firstId + data: + type: array + items: + $ref: '#/components/schemas/Batch' + last_id: + type: string + example: batch_abc456 + x-ballerina-name: lastId + has_more: + type: boolean + x-ballerina-name: hasMore + object: + type: string + enum: + - list + CreateEmbeddingResponse: + required: + - data + - model + - object + - usage + type: object + properties: + data: + type: array + description: The list of embeddings generated by the model + items: + $ref: '#/components/schemas/Embedding' + usage: + $ref: '#/components/schemas/CreateEmbeddingResponseUsage' + model: + type: string + description: The name of the model used to generate the embedding + object: + type: string + description: "The object type, which is always \"list\"" + enum: + - list + BatchErrorsData: + type: object + properties: + code: + type: string + description: An error code identifying the error type + param: + type: string + description: "The name of the parameter that caused the error, if applicable" + nullable: true + line: + type: integer + description: "The line number of the input file where the error occurred,\ + \ if applicable" + nullable: true + message: + type: string + description: A human-readable message providing more details about the error + RunStepDeltaStepDetailsToolCallsCodeOutputLogsObject: + title: Code interpreter log output + required: + - index + - type + type: object + properties: + index: + type: integer + description: The index of the output in the outputs array + type: + type: string + description: Always `logs` + enum: + - logs + logs: + type: string + description: The text output from the Code Interpreter tool call + description: Text output from the Code Interpreter tool call as part of a run + step + CreateThreadRequestToolResources: + type: object + properties: + code_interpreter: + allOf: + - $ref: '#/components/schemas/CreateThreadRequestToolResourcesCodeInterpreter' + x-ballerina-name: codeInterpreter + file_search: + allOf: + - $ref: '#/components/schemas/CreateThreadRequestToolResourcesFileSearch' + x-ballerina-name: fileSearch + description: | + A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs + nullable: true + BatchRequestOutputError: + type: object + properties: + code: + type: string + description: A machine-readable error code + message: + type: string + description: A human-readable error message + description: "For requests that failed with a non-HTTP error, this will contain\ + \ more information on the cause of the failure" + nullable: true + CreateChatCompletionFunctionResponse: + required: + - choices + - created + - id + - model + - object + type: object + properties: + created: + type: integer + description: The Unix timestamp (in seconds) of when the chat completion + was created + usage: + $ref: '#/components/schemas/CompletionUsage' + model: + type: string + description: The model used for the chat completion + id: + type: string + description: A unique identifier for the chat completion + choices: + type: array + description: A list of chat completion choices. Can be more than one if + `n` is greater than 1 + items: + $ref: '#/components/schemas/CreateChatCompletionFunctionResponseChoices' + system_fingerprint: + type: string + description: | + This fingerprint represents the backend configuration that the model runs with. + + Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism + x-ballerina-name: systemFingerprint + object: + type: string + description: "The object type, which is always `chat.completion`" + enum: + - chat.completion + description: "Represents a chat completion response returned by model, based\ + \ on the provided input" + x-oaiMeta: + name: The chat completion object + group: chat + example: | + { + "id": "chatcmpl-abc123", + "object": "chat.completion", + "created": 1699896916, + "model": "gpt-4o-mini", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": null, + "tool_calls": [ { - "id": "file-abc123", - "object": "vector_store.file", - "usage_bytes": 1234, - "created_at": 1698107661, - "vector_store_id": "vs_abc123", - "status": "completed", - "last_error": null, - "chunking_strategy": { - "type": "static", - "static": { - "max_chunk_size_tokens": 800, - "chunk_overlap_tokens": 400 - } + "id": "call_abc123", + "type": "function", + "function": { + "name": "get_current_weather", + "arguments": "{\n\"location\": \"Boston, MA\"\n}" } } - - OtherChunkingStrategyResponseParam: - type: object - title: Other Chunking Strategy - description: This is returned when the chunking strategy is unknown. Typically, this is because the file was indexed before the `chunking_strategy` concept was introduced in the API. + ] + }, + "logprobs": null, + "finish_reason": "tool_calls" + } + ], + "usage": { + "prompt_tokens": 82, + "completion_tokens": 17, + "total_tokens": 99 + } + } + RunObject: + title: A run on a thread + required: + - assistant_id + - cancelled_at + - completed_at + - created_at + - expires_at + - failed_at + - id + - incomplete_details + - instructions + - last_error + - max_completion_tokens + - max_prompt_tokens + - metadata + - model + - object + - parallel_tool_calls + - required_action + - response_format + - started_at + - status + - thread_id + - tool_choice + - tools + - truncation_strategy + - usage + type: object + properties: + cancelled_at: + type: integer + description: The Unix timestamp (in seconds) for when the run was cancelled + nullable: true + x-ballerina-name: cancelledAt + instructions: + type: string + description: "The instructions that the [assistant](/docs/api-reference/assistants)\ + \ used for this run" + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + assistant_id: + type: string + description: "The ID of the [assistant](/docs/api-reference/assistants)\ + \ used for execution of this run" + x-ballerina-name: assistantId + required_action: + allOf: + - $ref: '#/components/schemas/RunObjectRequiredAction' + x-ballerina-name: requiredAction + usage: + $ref: '#/components/schemas/RunCompletionUsage' + created_at: + type: integer + description: The Unix timestamp (in seconds) for when the run was created + x-ballerina-name: createdAt + tools: + maxItems: 20 + type: array + description: "The list of tools that the [assistant](/docs/api-reference/assistants)\ + \ used for this run" + items: + $ref: '#/components/schemas/RunObjectTools' + default: [] + top_p: + type: number + description: "The nucleus sampling value used for this run. If not set,\ + \ defaults to 1" + nullable: true + x-ballerina-name: topP + max_completion_tokens: + minimum: 256 + type: integer + description: | + The maximum number of completion tokens specified to have been used over the course of the run + nullable: true + x-ballerina-name: maxCompletionTokens + thread_id: + type: string + description: "The ID of the [thread](/docs/api-reference/threads) that was\ + \ executed on as a part of this run" + x-ballerina-name: threadId + expires_at: + type: integer + description: The Unix timestamp (in seconds) for when the run will expire + nullable: true + x-ballerina-name: expiresAt + response_format: + allOf: + - $ref: '#/components/schemas/AssistantsApiResponseFormatOption' + x-ballerina-name: responseFormat + temperature: + type: number + description: "The sampling temperature used for this run. If not set, defaults\ + \ to 1" + nullable: true + tool_choice: + allOf: + - $ref: '#/components/schemas/AssistantsApiToolChoiceOption' + x-ballerina-name: toolChoice + model: + type: string + description: "The model that the [assistant](/docs/api-reference/assistants)\ + \ used for this run" + id: + type: string + description: "The identifier, which can be referenced in API endpoints" + last_error: + allOf: + - $ref: '#/components/schemas/RunObjectLastError' + x-ballerina-name: lastError + incomplete_details: + allOf: + - $ref: '#/components/schemas/RunObjectIncompleteDetails' + x-ballerina-name: incompleteDetails + truncation_strategy: + allOf: + - $ref: '#/components/schemas/TruncationObject' + x-ballerina-name: truncationStrategy + completed_at: + type: integer + description: The Unix timestamp (in seconds) for when the run was completed + nullable: true + x-ballerina-name: completedAt + parallel_tool_calls: + allOf: + - $ref: '#/components/schemas/ParallelToolCalls' + x-ballerina-name: parallelToolCalls + started_at: + type: integer + description: The Unix timestamp (in seconds) for when the run was started + nullable: true + x-ballerina-name: startedAt + failed_at: + type: integer + description: The Unix timestamp (in seconds) for when the run failed + nullable: true + x-ballerina-name: failedAt + max_prompt_tokens: + minimum: 256 + type: integer + description: | + The maximum number of prompt tokens specified to have been used over the course of the run + nullable: true + x-ballerina-name: maxPromptTokens + object: + type: string + description: "The object type, which is always `thread.run`" + enum: + - thread.run + status: + type: string + description: "The status of the run, which can be either `queued`, `in_progress`,\ + \ `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`,\ + \ `incomplete`, or `expired`" + enum: + - queued + - in_progress + - requires_action + - cancelling + - cancelled + - failed + - completed + - incomplete + - expired + description: "Represents an execution run on a [thread](/docs/api-reference/threads)" + x-oaiMeta: + name: The run object + beta: true + example: | + { + "id": "run_abc123", + "object": "thread.run", + "created_at": 1698107661, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "completed", + "started_at": 1699073476, + "expires_at": null, + "cancelled_at": null, + "failed_at": null, + "completed_at": 1699073498, + "last_error": null, + "model": "gpt-4-turbo", + "instructions": null, + "tools": [{"type": "file_search"}, {"type": "code_interpreter"}], + "metadata": {}, + "incomplete_details": null, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + }, + "temperature": 1.0, + "top_p": 1.0, + "max_prompt_tokens": 1000, + "max_completion_tokens": 1000, + "truncation_strategy": { + "type": "auto", + "last_messages": null + }, + "response_format": "auto", + "tool_choice": "auto", + "parallel_tool_calls": true + } + ChatCompletionRequestUserMessage: + title: User message + required: + - content + - role + type: object + properties: + role: + type: string + description: "The role of the messages author, in this case `user`" + enum: + - user + name: + type: string + description: An optional name for the participant. Provides the model information + to differentiate between participants of the same role + content: + description: | + The contents of the user message + oneOf: + - title: Text content + type: string + description: The text contents of the message. + - title: Array of content parts + minItems: 1 + type: array + description: "An array of content parts with a defined type, each can\ + \ be of type `text` or `image_url` when passing in images. You can pass\ + \ multiple images by adding multiple `image_url` content parts. Image\ + \ input is only supported when using the `gpt-4o` model." + items: + $ref: '#/components/schemas/ChatCompletionRequestMessageContentPart' + x-oaiExpandable: true + MessageDeltaObject: + title: Message delta object + required: + - delta + - id + - object + type: object + properties: + delta: + $ref: '#/components/schemas/MessageDeltaObjectDelta' + id: + type: string + description: "The identifier of the message, which can be referenced in\ + \ API endpoints" + object: + type: string + description: "The object type, which is always `thread.message.delta`" + enum: + - thread.message.delta + description: | + Represents a message delta i.e. any changed fields on a message during streaming + x-oaiMeta: + name: The message delta object + beta: true + example: | + { + "id": "msg_123", + "object": "thread.message.delta", + "delta": { + "content": [ + { + "index": 0, + "type": "text", + "text": { "value": "Hello", "annotations": [] } + } + ] + } + } + AssistantMessage: + title: Assistant message + type: object + properties: + weight: + type: integer + description: Controls whether the assistant message is trained against (0 + or 1) + enum: + - 0 + - 1 + deprecated: false + RunStepDeltaStepDetailsMessageCreationObject: + title: Message creation + required: + - type + type: object + properties: + message_creation: + allOf: + - $ref: '#/components/schemas/RunStepDeltaStepDetailsMessageCreationObjectMessageCreation' + x-ballerina-name: messageCreation + type: + type: string + description: Always `message_creation` + enum: + - message_creation + description: Details of the message creation by the run step + ModifyAssistantRequestToolResourcesCodeInterpreter: + type: object + properties: + file_ids: + maxItems: 20 + type: array + description: | + Overrides the list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool + items: + type: string + default: [] + x-ballerina-name: fileIds + ChatCompletionTool: + required: + - function + - type + type: object + properties: + function: + $ref: '#/components/schemas/FunctionObject' + type: + type: string + description: "The type of the tool. Currently, only `function` is supported" + enum: + - function + VectorStoreExpirationAfter: + title: Vector store expiration policy + required: + - anchor + - days + type: object + properties: + anchor: + type: string + description: "Anchor timestamp after which the expiration policy applies.\ + \ Supported anchors: `last_active_at`" + enum: + - last_active_at + days: + maximum: 365 + minimum: 1 + type: integer + description: The number of days after the anchor time that the vector store + will expire + description: The expiration policy for a vector store + CreateThreadAndRunRequestToolResourcesCodeInterpreter: + type: object + properties: + file_ids: + maxItems: 20 + type: array + description: | + A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool + items: + type: string + default: [] + x-ballerina-name: fileIds + AssistantsApiToolChoiceOption: + description: | + Controls which (if any) tool is called by the model. + `none` means the model will not call any tools and instead generates a message. + `auto` is the default value and means the model can pick between generating a message or calling one or more tools. + `required` means the model must call one or more tools before responding to the user. + Specifying a particular tool like `{"type": "file_search"}` or `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that tool + oneOf: + - $ref: '#/components/schemas/AssistantsApiToolChoiceOptionOneOf1' + - $ref: '#/components/schemas/AssistantsNamedToolChoice' + x-oaiExpandable: true + ModifyMessageRequest: + type: object + properties: + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + additionalProperties: false + RunStepStreamEvent: + oneOf: + - $ref: '#/components/schemas/RunStepStreamEventOneOf1' + - $ref: '#/components/schemas/RunStepStreamEventRunStepStreamEventOneOf12' + - $ref: '#/components/schemas/RunStepStreamEventRunStepStreamEventRunStepStreamEventOneOf123' + - $ref: '#/components/schemas/RunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventOneOf1234' + - $ref: '#/components/schemas/RunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventOneOf12345' + - $ref: '#/components/schemas/RunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventOneOf123456' + - $ref: '#/components/schemas/RunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventOneOf1234567' + ChatCompletionStreamResponseDelta: + type: object + properties: + role: + type: string + description: The role of the author of this message + enum: + - system + - user + - assistant + - tool + function_call: + allOf: + - $ref: '#/components/schemas/ChatCompletionStreamResponseDeltaFunctionCall' + x-ballerina-name: functionCall + tool_calls: + type: array + items: + $ref: '#/components/schemas/ChatCompletionMessageToolCallChunk' + x-ballerina-name: toolCalls + content: + type: string + description: The contents of the chunk message + nullable: true + description: A chat completion delta generated by streamed model responses + RunStepDetailsToolCallsCodeOutputImageObject: + title: Code Interpreter image output + required: + - image + - type + type: object + properties: + image: + $ref: '#/components/schemas/RunStepDetailsToolCallsCodeOutputImageObjectImage' + type: + type: string + description: Always `image` + enum: + - image + RunStepDeltaStepDetailsToolCallsCodeObjectCodeInterpreterOutputs: + type: object + oneOf: + - $ref: '#/components/schemas/RunStepDeltaStepDetailsToolCallsCodeOutputLogsObject' + - $ref: '#/components/schemas/RunStepDeltaStepDetailsToolCallsCodeOutputImageObject' + x-oaiExpandable: true + FunctionParameters: + type: object + additionalProperties: true + description: "The parameters the functions accepts, described as a JSON Schema\ + \ object. See the [guide](/docs/guides/function-calling) for examples, and\ + \ the [JSON Schema reference](https://json-schema.org/understanding-json-schema/)\ + \ for documentation about the format. \n\nOmitting `parameters` defines a\ + \ function with an empty parameter list" + OpenAIFile: + title: OpenAIFile + required: + - bytes + - created_at + - filename + - id + - object + - purpose + - status + properties: + id: + type: string + description: "The file identifier, which can be referenced in the API endpoints." + bytes: + type: integer + description: "The size of the file, in bytes." + created_at: + type: integer + description: The Unix timestamp (in seconds) for when the file was created. + filename: + type: string + description: The name of the file. + object: + type: string + description: "The object type, which is always `file`." + enum: + - file + purpose: + type: string + description: "The intended purpose of the file. Supported values are `assistants`,\ + \ `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results`\ + \ and `vision`." + enum: + - assistants + - assistants_output + - batch + - batch_output + - fine-tune + - fine-tune-results + - vision + status: + type: string + description: "Deprecated. The current status of the file, which can be either\ + \ `uploaded`, `processed`, or `error`." + deprecated: true + enum: + - uploaded + - processed + - error + status_details: + type: string + description: "Deprecated. For details on why a fine-tuning training file\ + \ failed validation, see the `error` field on `fine_tuning.job`." + nullable: true + description: The `File` object represents a document that has been uploaded + to OpenAI + x-oaiMeta: + name: The file object + example: | + { + "id": "file-abc123", + "object": "file", + "bytes": 120000, + "created_at": 1677610602, + "filename": "salesOverview.pdf", + "purpose": "assistants", + } + ModifyAssistantRequestTools: + oneOf: + - $ref: '#/components/schemas/AssistantToolsCode' + - $ref: '#/components/schemas/AssistantToolsFileSearch' + - $ref: '#/components/schemas/AssistantToolsFunction' + x-oaiExpandable: true + ChatCompletionMessageToolCallChunk: + required: + - index + type: object + properties: + function: + $ref: '#/components/schemas/ChatCompletionMessageToolCallChunkFunction' + index: + type: integer + id: + type: string + description: The ID of the tool call + type: + type: string + description: "The type of the tool. Currently, only `function` is supported" + enum: + - function + MessageDeltaContentImageUrlObject: + title: Image URL + required: + - index + - type + type: object + properties: + image_url: + allOf: + - $ref: '#/components/schemas/MessageDeltaContentImageUrlObjectImageUrl' + x-ballerina-name: imageUrl + index: + type: integer + description: The index of the content part in the message + type: + type: string + description: Always `image_url` + enum: + - image_url + description: References an image URL in the content of a message + AssistantStreamEvent: + description: | + Represents an event emitted when streaming a Run. + + Each event in a server-sent events stream has an `event` and `data` property: + + ``` + event: thread.created + data: {"id": "thread_123", "object": "thread", ...} + ``` + + We emit events whenever a new object is created, transitions to a new state, or is being + streamed in parts (deltas). For example, we emit `thread.run.created` when a new run + is created, `thread.run.completed` when a run completes, and so on. When an Assistant chooses + to create a message during a run, we emit a `thread.message.created event`, a + `thread.message.in_progress` event, many `thread.message.delta` events, and finally a + `thread.message.completed` event. + + We may add additional events over time, so we recommend handling unknown events gracefully + in your code. See the [Assistants API quickstart](/docs/assistants/overview) to learn how to + integrate the Assistants API with streaming + oneOf: + - $ref: '#/components/schemas/ThreadStreamEvent' + - $ref: '#/components/schemas/RunStreamEvent' + - $ref: '#/components/schemas/RunStepStreamEvent' + - $ref: '#/components/schemas/MessageStreamEvent' + - $ref: '#/components/schemas/ErrorEvent' + - $ref: '#/components/schemas/DoneEvent' + x-oaiMeta: + name: Assistant stream events + beta: true + RunStepDeltaStepDetailsToolCallsFunctionObject: + title: Function tool call + required: + - index + - type + type: object + properties: + function: + $ref: '#/components/schemas/RunStepDeltaStepDetailsToolCallsFunctionObjectFunction' + index: + type: integer + description: The index of the tool call in the tool calls array + id: + type: string + description: The ID of the tool call object + type: + type: string + description: The type of tool call. This is always going to be `function` + for this type of tool call + enum: + - function + RunStreamEventOneOf1: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunObject' + event: + type: string + enum: + - thread.run.created + description: "Occurs when a new [run](/docs/api-reference/runs/object) is created" + x-oaiMeta: + dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" + CreateAssistantRequestToolResourcesFileSearchVectorStores: + type: object + properties: + chunking_strategy: + type: object + description: "The chunking strategy used to chunk the file(s). If not set,\ + \ will use the `auto` strategy" + oneOf: + - title: Auto Chunking Strategy + required: + - type + type: object + properties: + type: + type: string + description: Always `auto`. + enum: + - auto additionalProperties: false - properties: - type: - type: string - description: Always `other`. - enum: ["other"] + description: The default strategy. This strategy currently uses a `max_chunk_size_tokens` + of `800` and `chunk_overlap_tokens` of `400`. + - title: Static Chunking Strategy required: - - type - - StaticChunkingStrategyResponseParam: + - static + - type type: object - title: Static Chunking Strategy - additionalProperties: false properties: - type: - type: string - description: Always `static`. - enum: ["static"] - static: - $ref: "#/components/schemas/StaticChunkingStrategy" - required: - - type + type: + type: string + description: Always `static`. + enum: - static - - StaticChunkingStrategy: - type: object - additionalProperties: false - properties: - max_chunk_size_tokens: - type: integer - minimum: 100 + static: + required: + - chunk_overlap_tokens + - max_chunk_size_tokens + type: object + properties: + max_chunk_size_tokens: maximum: 4096 - description: The maximum number of tokens in each chunk. The default value is `800`. The minimum value is `100` and the maximum value is `4096`. - chunk_overlap_tokens: + minimum: 100 + type: integer + description: The maximum number of tokens in each chunk. The default + value is `800`. The minimum value is `100` and the maximum value + is `4096`. + chunk_overlap_tokens: type: integer description: | - The number of tokens that overlap between chunks. The default value is `400`. - - Note that the overlap must not exceed half of `max_chunk_size_tokens`. - required: - - max_chunk_size_tokens - - chunk_overlap_tokens - - AutoChunkingStrategyRequestParam: - type: object - title: Auto Chunking Strategy - description: The default strategy. This strategy currently uses a `max_chunk_size_tokens` of `800` and `chunk_overlap_tokens` of `400`. - additionalProperties: false - properties: - type: - type: string - description: Always `auto`. - enum: ["auto"] - required: - - type - - StaticChunkingStrategyRequestParam: - type: object - title: Static Chunking Strategy - additionalProperties: false - properties: - type: - type: string - description: Always `static`. - enum: ["static"] - static: - $ref: "#/components/schemas/StaticChunkingStrategy" - required: - - type - - static - - ChunkingStrategyRequestParam: - type: object - description: The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy. - oneOf: - - $ref: "#/components/schemas/AutoChunkingStrategyRequestParam" - - $ref: "#/components/schemas/StaticChunkingStrategyRequestParam" - x-oaiExpandable: true + The number of tokens that overlap between chunks. The default value is `400`. - CreateVectorStoreFileRequest: - type: object + Note that the overlap must not exceed half of `max_chunk_size_tokens`. + additionalProperties: false additionalProperties: false - properties: - file_id: - description: A [File](/docs/api-reference/files) ID that the vector store should use. Useful for tools like `file_search` that can access files. - type: string - chunking_strategy: - $ref: "#/components/schemas/ChunkingStrategyRequestParam" - required: - - file_id + x-oaiExpandable: true + x-ballerina-name: chunkingStrategy + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to a vector store. This can be useful for storing additional information about the vector store in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + x-oaiTypeLabel: map + file_ids: + maxItems: 10000 + type: array + description: | + A list of [file](/docs/api-reference/files) IDs to add to the vector store. There can be a maximum of 10000 files in a vector store + items: + type: string + x-ballerina-name: fileIds + ListVectorStoreFilesResponse: + required: + - data + - first_id + - has_more + - last_id + - object + properties: + object: + type: string + example: list + data: + type: array + items: + $ref: '#/components/schemas/VectorStoreFileObject' + first_id: + type: string + example: file-abc123 + last_id: + type: string + example: file-abc456 + has_more: + type: boolean + example: false + RunStepDetailsToolCallsCodeOutputImageObjectImage: + required: + - file_id + type: object + properties: + file_id: + type: string + description: "The [file](/docs/api-reference/files) ID of the image" + x-ballerina-name: fileId + ChatCompletionRequestMessageContentPart: + oneOf: + - $ref: '#/components/schemas/ChatCompletionRequestMessageContentPartText' + - $ref: '#/components/schemas/ChatCompletionRequestMessageContentPartImage' + x-oaiExpandable: true + Batch: + required: + - completion_window + - created_at + - endpoint + - id + - input_file_id + - object + - status + type: object + properties: + cancelled_at: + type: integer + description: The Unix timestamp (in seconds) for when the batch was cancelled + x-ballerina-name: cancelledAt + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + request_counts: + allOf: + - $ref: '#/components/schemas/BatchRequestCounts' + x-ballerina-name: requestCounts + input_file_id: + type: string + description: The ID of the input file for the batch + x-ballerina-name: inputFileId + output_file_id: + type: string + description: The ID of the file containing the outputs of successfully executed + requests + x-ballerina-name: outputFileId + error_file_id: + type: string + description: The ID of the file containing the outputs of requests with + errors + x-ballerina-name: errorFileId + created_at: + type: integer + description: The Unix timestamp (in seconds) for when the batch was created + x-ballerina-name: createdAt + in_progress_at: + type: integer + description: The Unix timestamp (in seconds) for when the batch started + processing + x-ballerina-name: inProgressAt + expired_at: + type: integer + description: The Unix timestamp (in seconds) for when the batch expired + x-ballerina-name: expiredAt + finalizing_at: + type: integer + description: The Unix timestamp (in seconds) for when the batch started + finalizing + x-ballerina-name: finalizingAt + completed_at: + type: integer + description: The Unix timestamp (in seconds) for when the batch was completed + x-ballerina-name: completedAt + endpoint: + type: string + description: The OpenAI API endpoint used by the batch + expires_at: + type: integer + description: The Unix timestamp (in seconds) for when the batch will expire + x-ballerina-name: expiresAt + cancelling_at: + type: integer + description: The Unix timestamp (in seconds) for when the batch started + cancelling + x-ballerina-name: cancellingAt + completion_window: + type: string + description: The time frame within which the batch should be processed + x-ballerina-name: completionWindow + id: + type: string + failed_at: + type: integer + description: The Unix timestamp (in seconds) for when the batch failed + x-ballerina-name: failedAt + errors: + $ref: '#/components/schemas/BatchErrors' + object: + type: string + description: "The object type, which is always `batch`" + enum: + - batch + status: + type: string + description: The current status of the batch + enum: + - validating + - failed + - in_progress + - finalizing + - completed + - expired + - cancelling + - cancelled + x-oaiMeta: + name: The batch object + example: | + { + "id": "batch_abc123", + "object": "batch", + "endpoint": "/v1/completions", + "errors": null, + "input_file_id": "file-abc123", + "completion_window": "24h", + "status": "completed", + "output_file_id": "file-cvaTdG", + "error_file_id": "file-HOWS94", + "created_at": 1711471533, + "in_progress_at": 1711471538, + "expires_at": 1711557933, + "finalizing_at": 1711493133, + "completed_at": 1711493163, + "failed_at": null, + "expired_at": null, + "cancelling_at": null, + "cancelled_at": null, + "request_counts": { + "total": 100, + "completed": 95, + "failed": 5 + }, + "metadata": { + "customer_id": "user_123456789", + "batch_description": "Nightly eval job", + } + } + StaticChunkingStrategy: + required: + - chunk_overlap_tokens + - max_chunk_size_tokens + type: object + properties: + max_chunk_size_tokens: + maximum: 4096 + minimum: 100 + type: integer + description: The maximum number of tokens in each chunk. The default value + is `800`. The minimum value is `100` and the maximum value is `4096` + x-ballerina-name: maxChunkSizeTokens + chunk_overlap_tokens: + type: integer + description: | + The number of tokens that overlap between chunks. The default value is `400`. + + Note that the overlap must not exceed half of `max_chunk_size_tokens` + x-ballerina-name: chunkOverlapTokens + additionalProperties: false + ? RunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventOneOf123456789 + : required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunObject' + event: + type: string + enum: + - thread.run.cancelled + description: "Occurs when a [run](/docs/api-reference/runs/object) is cancelled" + x-oaiMeta: + dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" + CompleteUploadRequest: + required: + - part_ids + type: object + properties: + part_ids: + type: array + description: | + The ordered list of Part IDs + items: + type: string + x-ballerina-name: partIds + md5: + type: string + description: | + The optional md5 checksum for the file contents to verify if the bytes uploaded matches what you expect + additionalProperties: false + AssistantObjectToolResourcesCodeInterpreter: + type: object + properties: + file_ids: + maxItems: 20 + type: array + description: | + A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter`` tool. There can be a maximum of 20 files associated with the tool + items: + type: string + default: [] + x-ballerina-name: fileIds + ChatCompletionStreamResponseDeltaFunctionCall: + type: object + properties: + name: + type: string + description: The name of the function to call + arguments: + type: string + description: "The arguments to call the function with, as generated by the\ + \ model in JSON format. Note that the model does not always generate valid\ + \ JSON, and may hallucinate parameters not defined by your function schema.\ + \ Validate the arguments in your code before calling your function" + description: "Deprecated and replaced by `tool_calls`. The name and arguments\ + \ of a function that should be called, as generated by the model" + deprecated: true + MessageContentImageFileObject: + title: Image file + required: + - image_file + - type + type: object + properties: + image_file: + allOf: + - $ref: '#/components/schemas/MessageContentImageFileObjectImageFile' + x-ballerina-name: imageFile + type: + type: string + description: Always `image_file` + enum: + - image_file + description: "References an image [File](/docs/api-reference/files) in the content\ + \ of a message" + ThreadObjectToolResourcesFileSearch: + type: object + properties: + vector_store_ids: + maxItems: 1 + type: array + description: | + The [vector store](/docs/api-reference/vector-stores/object) attached to this thread. There can be a maximum of 1 vector store attached to the thread + items: + type: string + x-ballerina-name: vectorStoreIds + AssistantObject: + title: Assistant + required: + - created_at + - description + - id + - instructions + - metadata + - model + - name + - object + - tools + type: object + properties: + instructions: + maxLength: 256000 + type: string + description: | + The system instructions that the assistant uses. The maximum length is 256,000 characters + nullable: true + tool_resources: + allOf: + - $ref: '#/components/schemas/AssistantObjectToolResources' + x-ballerina-name: toolResources + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + created_at: + type: integer + description: The Unix timestamp (in seconds) for when the assistant was + created + x-ballerina-name: createdAt + description: + maxLength: 512 + type: string + description: | + The description of the assistant. The maximum length is 512 characters + nullable: true + tools: + maxItems: 128 + type: array + description: | + A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `file_search`, or `function` + items: + $ref: '#/components/schemas/AssistantObjectTools' + default: [] + top_p: + maximum: 1 + minimum: 0 + type: number + description: | + An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + + We generally recommend altering this or temperature but not both + nullable: true + example: 1 + default: 1 + x-ballerina-name: topP + response_format: + allOf: + - $ref: '#/components/schemas/AssistantsApiResponseFormatOption' + x-ballerina-name: responseFormat + name: + maxLength: 256 + type: string + description: | + The name of the assistant. The maximum length is 256 characters + nullable: true + temperature: + maximum: 2 + minimum: 0 + type: number + description: | + What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic + nullable: true + example: 1 + default: 1 + model: + type: string + description: | + ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](/docs/models/overview) for descriptions of them + id: + type: string + description: "The identifier, which can be referenced in API endpoints" + object: + type: string + description: "The object type, which is always `assistant`" + enum: + - assistant + description: Represents an `assistant` that can call the model and use tools + x-oaiMeta: + name: The assistant object + beta: true + example: | + { + "id": "asst_abc123", + "object": "assistant", + "created_at": 1698984975, + "name": "Math Tutor", + "description": null, + "model": "gpt-4-turbo", + "instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.", + "tools": [ + { + "type": "code_interpreter" + } + ], + "metadata": {}, + "top_p": 1.0, + "temperature": 1.0, + "response_format": "auto" + } + ChatCompletionRequestFunctionMessage: + title: Function message + required: + - content + - name + - role + type: object + properties: + role: + type: string + description: "The role of the messages author, in this case `function`" + enum: + - function + name: + type: string + description: The name of the function to call + content: + type: string + description: The contents of the function message + nullable: true + deprecated: true + CreateFileRequest: + required: + - file + - purpose + type: object + properties: + file: + type: string + description: | + The File object (not file name) to be uploaded + format: binary + purpose: + type: string + description: | + The intended purpose of the uploaded file. + + Use "assistants" for [Assistants](/docs/api-reference/assistants) and [Message](/docs/api-reference/messages) files, "vision" for Assistants image file inputs, "batch" for [Batch API](/docs/guides/batch), and "fine-tune" for [Fine-tuning](/docs/api-reference/fine-tuning) + enum: + - assistants + - batch + - fine-tune + - vision + additionalProperties: false + ChatCompletionMessageToolCallFunction: + required: + - arguments + - name + type: object + properties: + name: + type: string + description: The name of the function to call + arguments: + type: string + description: "The arguments to call the function with, as generated by the\ + \ model in JSON format. Note that the model does not always generate valid\ + \ JSON, and may hallucinate parameters not defined by your function schema.\ + \ Validate the arguments in your code before calling your function" + description: The function that the model called + MessageDeltaContentTextAnnotationsFilePathObject: + title: File path + required: + - index + - type + type: object + properties: + file_path: + allOf: + - $ref: '#/components/schemas/MessageDeltaContentTextAnnotationsFilePathObjectFilePath' + x-ballerina-name: filePath + start_index: + minimum: 0 + type: integer + x-ballerina-name: startIndex + index: + type: integer + description: The index of the annotation in the text content part + end_index: + minimum: 0 + type: integer + x-ballerina-name: endIndex + text: + type: string + description: The text in the message content that needs to be replaced + type: + type: string + description: Always `file_path` + enum: + - file_path + description: A URL for the file that's generated when the assistant used the + `code_interpreter` tool to generate a file + MessageContentTextAnnotationsFilePathObject: + title: File path + required: + - end_index + - file_path + - start_index + - text + - type + type: object + properties: + file_path: + allOf: + - $ref: '#/components/schemas/MessageContentTextAnnotationsFilePathObjectFilePath' + x-ballerina-name: filePath + start_index: + minimum: 0 + type: integer + x-ballerina-name: startIndex + end_index: + minimum: 0 + type: integer + x-ballerina-name: endIndex + text: + type: string + description: The text in the message content that needs to be replaced + type: + type: string + description: Always `file_path` + enum: + - file_path + description: A URL for the file that's generated when the assistant used the + `code_interpreter` tool to generate a file + CreateThreadAndRunRequest: + required: + - assistant_id + - thread_id + type: object + properties: + instructions: + type: string + description: Override the default system message of the assistant. This + is useful for modifying the behavior on a per-run basis + nullable: true + tool_resources: + allOf: + - $ref: '#/components/schemas/CreateThreadAndRunRequestToolResources' + x-ballerina-name: toolResources + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + assistant_id: + type: string + description: "The ID of the [assistant](/docs/api-reference/assistants)\ + \ to use to execute this run" + x-ballerina-name: assistantId + thread: + $ref: '#/components/schemas/CreateThreadRequest' + tools: + maxItems: 20 + type: array + description: Override the tools the assistant can use for this run. This + is useful for modifying the behavior on a per-run basis + nullable: true + items: + $ref: '#/components/schemas/CreateThreadAndRunRequestTools' + truncation_strategy: + allOf: + - $ref: '#/components/schemas/TruncationObject' + x-ballerina-name: truncationStrategy + top_p: + maximum: 1 + minimum: 0 + type: number + description: | + An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + + We generally recommend altering this or temperature but not both + nullable: true + example: 1 + default: 1 + x-ballerina-name: topP + max_completion_tokens: + minimum: 256 + type: integer + description: | + The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort to use only the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of completion tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info + nullable: true + x-ballerina-name: maxCompletionTokens + response_format: + allOf: + - $ref: '#/components/schemas/AssistantsApiResponseFormatOption' + x-ballerina-name: responseFormat + parallel_tool_calls: + allOf: + - $ref: '#/components/schemas/ParallelToolCalls' + x-ballerina-name: parallelToolCalls + stream: + type: boolean + description: | + If `true`, returns a stream of events that happen during the Run as server-sent events, terminating when the Run enters a terminal state with a `data: [DONE]` message + nullable: true + temperature: + maximum: 2 + minimum: 0 + type: number + description: | + What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic + nullable: true + example: 1 + default: 1 + tool_choice: + allOf: + - $ref: '#/components/schemas/AssistantsApiToolChoiceOption' + x-ballerina-name: toolChoice + model: + description: "The ID of the [Model](/docs/api-reference/models) to be used\ + \ to execute this run. If a value is provided here, it will override the\ + \ model associated with the assistant. If not, the model associated with\ + \ the assistant will be used" + nullable: true + example: gpt-4-turbo + anyOf: + - type: string + - type: string + enum: + - gpt-4o + - gpt-4o-2024-05-13 + - gpt-4o-mini + - gpt-4o-mini-2024-07-18 + - gpt-4-turbo + - gpt-4-turbo-2024-04-09 + - gpt-4-0125-preview + - gpt-4-turbo-preview + - gpt-4-1106-preview + - gpt-4-vision-preview + - gpt-4 + - gpt-4-0314 + - gpt-4-0613 + - gpt-4-32k + - gpt-4-32k-0314 + - gpt-4-32k-0613 + - gpt-3.5-turbo + - gpt-3.5-turbo-16k + - gpt-3.5-turbo-0613 + - gpt-3.5-turbo-1106 + - gpt-3.5-turbo-0125 + - gpt-3.5-turbo-16k-0613 + x-oaiTypeLabel: string + max_prompt_tokens: + minimum: 256 + type: integer + description: | + The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info + nullable: true + x-ballerina-name: maxPromptTokens + additionalProperties: false + RunStepDeltaStepDetailsToolCallsObjectToolCalls: + oneOf: + - $ref: '#/components/schemas/RunStepDeltaStepDetailsToolCallsCodeObject' + - $ref: '#/components/schemas/RunStepDeltaStepDetailsToolCallsFileSearchObject' + - $ref: '#/components/schemas/RunStepDeltaStepDetailsToolCallsFunctionObject' + x-oaiExpandable: true + CreateThreadRequestToolResourcesCodeInterpreter: + type: object + properties: + file_ids: + maxItems: 20 + type: array + description: | + A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool + items: + type: string + default: [] + x-ballerina-name: fileIds + FineTuningJobEvent: + required: + - created_at + - id + - level + - message + - object + type: object + properties: + level: + type: string + enum: + - info + - warn + - error + created_at: + type: integer + x-ballerina-name: createdAt + id: + type: string + message: + type: string + object: + type: string + enum: + - fine_tuning.job.event + description: Fine-tuning job event object + x-oaiMeta: + name: The fine-tuning job event object + example: | + { + "object": "fine_tuning.job.event", + "id": "ftevent-abc123" + "created_at": 1677610602, + "level": "info", + "message": "Created fine-tuning job" + } + FineTuningIntegrationWandb: + required: + - project + type: object + properties: + name: + type: string + description: | + A display name to set for the run. If not set, we will use the Job ID as the name + nullable: true + project: + type: string + description: | + The name of the project that the new run will be created under + example: my-wandb-project + entity: + type: string + description: | + The entity to use for the run. This allows you to set the team or username of the WandB user that you would + like associated with the run. If not set, the default entity for the registered WandB API key is used + nullable: true + tags: + type: array + description: | + A list of tags to be attached to the newly created run. These tags are passed through directly to WandB. Some + default tags are generated by OpenAI: "openai/finetune", "openai/{base-model}", "openai/{ftjob-abcdef}" + items: + type: string + example: custom-tag + description: | + The settings for your integration with Weights and Biases. This payload specifies the project that + metrics will be sent to. Optionally, you can set an explicit display name for your run, add tags + to your run, and set a default entity (team, username, etc) to be associated with your run + AssistantsNamedToolChoice: + required: + - type + type: object + properties: + function: + $ref: '#/components/schemas/AssistantsNamedToolChoiceFunction' + type: + type: string + description: "The type of the tool. If type is `function`, the function\ + \ name must be set" + enum: + - function + - code_interpreter + - file_search + description: Specifies a tool the model should use. Use to force the model to + call a specific tool + ListRunStepsResponse: + required: + - data + - first_id + - has_more + - last_id + - object + properties: + object: + type: string + example: list + data: + type: array + items: + $ref: '#/components/schemas/RunStepObject' + first_id: + type: string + example: step_abc123 + last_id: + type: string + example: step_abc456 + has_more: + type: boolean + example: false + MessageObject: + title: The message object + required: + - assistant_id + - attachments + - completed_at + - content + - created_at + - id + - incomplete_at + - incomplete_details + - metadata + - object + - role + - run_id + - status + - thread_id + type: object + properties: + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + role: + type: string + description: The entity that produced the message. One of `user` or `assistant` + enum: + - user + - assistant + assistant_id: + type: string + description: "If applicable, the ID of the [assistant](/docs/api-reference/assistants)\ + \ that authored this message" + nullable: true + x-ballerina-name: assistantId + run_id: + type: string + description: "The ID of the [run](/docs/api-reference/runs) associated with\ + \ the creation of this message. Value is `null` when messages are created\ + \ manually using the create message or create thread endpoints" + nullable: true + x-ballerina-name: runId + attachments: + type: array + description: "A list of files attached to the message, and the tools they\ + \ were added to" + nullable: true + items: + $ref: '#/components/schemas/MessageObjectAttachments' + created_at: + type: integer + description: The Unix timestamp (in seconds) for when the message was created + x-ballerina-name: createdAt + content: + type: array + description: The content of the message in array of text and/or images + items: + $ref: '#/components/schemas/MessageObjectContent' + completed_at: + type: integer + description: The Unix timestamp (in seconds) for when the message was completed + nullable: true + x-ballerina-name: completedAt + thread_id: + type: string + description: "The [thread](/docs/api-reference/threads) ID that this message\ + \ belongs to" + x-ballerina-name: threadId + id: + type: string + description: "The identifier, which can be referenced in API endpoints" + incomplete_at: + type: integer + description: The Unix timestamp (in seconds) for when the message was marked + as incomplete + nullable: true + x-ballerina-name: incompleteAt + incomplete_details: + allOf: + - $ref: '#/components/schemas/MessageObjectIncompleteDetails' + x-ballerina-name: incompleteDetails + object: + type: string + description: "The object type, which is always `thread.message`" + enum: + - thread.message + status: + type: string + description: "The status of the message, which can be either `in_progress`,\ + \ `incomplete`, or `completed`" + enum: + - in_progress + - incomplete + - completed + description: "Represents a message within a [thread](/docs/api-reference/threads)" + x-oaiMeta: + name: The message object + beta: true + example: | + { + "id": "msg_abc123", + "object": "thread.message", + "created_at": 1698983503, + "thread_id": "thread_abc123", + "role": "assistant", + "content": [ + { + "type": "text", + "text": { + "value": "Hi! How can I help you today?", + "annotations": [] + } + } + ], + "assistant_id": "asst_abc123", + "run_id": "run_abc123", + "attachments": [], + "metadata": {} + } + CreateFineTuningJobRequest: + required: + - model + - training_file + type: object + properties: + training_file: + type: string + description: | + The ID of an uploaded file that contains training data. - ListVectorStoreFilesResponse: - properties: - object: - type: string - example: "list" - data: - type: array - items: - $ref: "#/components/schemas/VectorStoreFileObject" - first_id: - type: string - example: "file-abc123" - last_id: - type: string - example: "file-abc456" - has_more: - type: boolean - example: false - required: - - object - - data - - first_id - - last_id - - has_more + See [upload file](/docs/api-reference/files/create) for how to upload a file. - DeleteVectorStoreFileResponse: - type: object - properties: - id: - type: string - deleted: - type: boolean - object: - type: string - enum: [vector_store.file.deleted] - required: - - id - - object - - deleted + Your dataset must be formatted as a JSONL file. Additionally, you must upload your file with the purpose `fine-tune`. - VectorStoreFileBatchObject: - type: object - title: Vector store file batch - description: A batch of files attached to a vector store. - properties: - id: - description: The identifier, which can be referenced in API endpoints. - type: string - object: - description: The object type, which is always `vector_store.file_batch`. - type: string - enum: ["vector_store.files_batch"] - created_at: - description: The Unix timestamp (in seconds) for when the vector store files batch was created. - type: integer - vector_store_id: - description: The ID of the [vector store](/docs/api-reference/vector-stores/object) that the [File](/docs/api-reference/files) is attached to. - type: string - status: - description: The status of the vector store files batch, which can be either `in_progress`, `completed`, `cancelled` or `failed`. - type: string - enum: ["in_progress", "completed", "cancelled", "failed"] - file_counts: - type: object - properties: - in_progress: - description: The number of files that are currently being processed. - type: integer - completed: - description: The number of files that have been processed. - type: integer - failed: - description: The number of files that have failed to process. - type: integer - cancelled: - description: The number of files that where cancelled. - type: integer - total: - description: The total number of files. - type: integer - required: - - in_progress - - completed - - cancelled - - failed - - total - required: - - id - - object - - created_at - - vector_store_id - - status - - file_counts - x-oaiMeta: - name: The vector store files batch object - beta: true - example: | - { - "id": "vsfb_123", - "object": "vector_store.files_batch", - "created_at": 1698107661, - "vector_store_id": "vs_abc123", - "status": "completed", - "file_counts": { - "in_progress": 0, - "completed": 100, - "failed": 0, - "cancelled": 0, - "total": 100 - } - } + The contents of the file should differ depending on if the model uses the [chat](/docs/api-reference/fine-tuning/chat-input) or [completions](/docs/api-reference/fine-tuning/completions-input) format. - CreateVectorStoreFileBatchRequest: - type: object + See the [fine-tuning guide](/docs/guides/fine-tuning) for more details + example: file-abc123 + x-ballerina-name: trainingFile + seed: + maximum: 2147483647 + minimum: 0 + type: integer + description: | + The seed controls the reproducibility of the job. Passing in the same seed and job parameters should produce the same results, but may differ in rare cases. + If a seed is not specified, one will be generated for you + nullable: true + example: 42 + validation_file: + type: string + description: | + The ID of an uploaded file that contains validation data. + + If you provide this file, the data is used to generate validation + metrics periodically during fine-tuning. These metrics can be viewed in + the fine-tuning results file. + The same data should not be present in both train and validation files. + + Your dataset must be formatted as a JSONL file. You must upload your file with the purpose `fine-tune`. + + See the [fine-tuning guide](/docs/guides/fine-tuning) for more details + nullable: true + example: file-abc123 + x-ballerina-name: validationFile + hyperparameters: + $ref: '#/components/schemas/CreateFineTuningJobRequestHyperparameters' + model: + description: | + The name of the model to fine-tune. You can select one of the + [supported models](/docs/guides/fine-tuning/what-models-can-be-fine-tuned) + example: gpt-3.5-turbo + anyOf: + - type: string + - type: string + enum: + - babbage-002 + - davinci-002 + - gpt-3.5-turbo + x-oaiTypeLabel: string + suffix: + maxLength: 40 + minLength: 1 + type: string + description: | + A string of up to 18 characters that will be added to your fine-tuned model name. + + For example, a `suffix` of "custom-model-name" would produce a model name like `ft:gpt-3.5-turbo:openai:custom-model-name:7p4lURel` + nullable: true + integrations: + type: array + description: A list of integrations to enable for your fine-tuning job + nullable: true + items: + $ref: '#/components/schemas/CreateFineTuningJobRequestIntegrations' + MessageContentImageUrlObjectImageUrl: + required: + - url + type: object + properties: + detail: + type: string + description: "Specifies the detail level of the image. `low` uses fewer\ + \ tokens, you can opt in to high resolution using `high`. Default value\ + \ is `auto`" + default: auto + enum: + - auto + - low + - high + url: + type: string + description: "The external URL of the image, must be a supported image types:\ + \ jpeg, jpg, png, gif, webp" + format: uri + CreateFineTuningJobRequestIntegrations: + required: + - type + - wandb + type: object + properties: + wandb: + $ref: '#/components/schemas/CreateFineTuningJobRequestWandb' + type: + description: | + The type of integration to enable. Currently, only "wandb" (Weights and Biases) is supported + oneOf: + - type: string + enum: + - wandb + BatchRequestInput: + type: object + properties: + method: + type: string + description: The HTTP method to be used for the request. Currently only + `POST` is supported + enum: + - POST + custom_id: + type: string + description: A developer-provided per-request id that will be used to match + outputs to inputs. Must be unique for each request in a batch + x-ballerina-name: customId + url: + type: string + description: "The OpenAI API relative URL to be used for the request. Currently\ + \ `/v1/chat/completions`, `/v1/embeddings`, and `/v1/completions` are\ + \ supported" + description: The per-line object of the batch input file + x-oaiMeta: + name: The request input object + example: | + {"custom_id": "request-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "gpt-3.5-turbo", "messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is 2+2?"}]}} + ChatCompletionTokenLogprob: + required: + - bytes + - logprob + - token + - top_logprobs + type: object + properties: + top_logprobs: + type: array + description: "List of the most likely tokens and their log probability,\ + \ at this token position. In rare cases, there may be fewer than the number\ + \ of requested `top_logprobs` returned" + items: + $ref: '#/components/schemas/ChatCompletionTokenLogprobTopLogprobs' + x-ballerina-name: topLogprobs + logprob: + type: number + description: "The log probability of this token, if it is within the top\ + \ 20 most likely tokens. Otherwise, the value `-9999.0` is used to signify\ + \ that the token is very unlikely" + bytes: + type: array + description: A list of integers representing the UTF-8 bytes representation + of the token. Useful in instances where characters are represented by + multiple tokens and their byte representations must be combined to generate + the correct text representation. Can be `null` if there is no bytes representation + for the token + nullable: true + items: + type: integer + token: + type: string + description: The token + AssistantsApiResponseFormatOptionOneOf1: + type: string + description: | + `auto` is the default value + enum: + - none + - auto + ChatCompletionRequestMessage: + oneOf: + - $ref: '#/components/schemas/ChatCompletionRequestSystemMessage' + - $ref: '#/components/schemas/ChatCompletionRequestUserMessage' + - $ref: '#/components/schemas/ChatCompletionRequestAssistantMessage' + - $ref: '#/components/schemas/ChatCompletionRequestToolMessage' + - $ref: '#/components/schemas/ChatCompletionRequestFunctionMessage' + x-oaiExpandable: true + Image: + type: object + properties: + revised_prompt: + type: string + description: "The prompt that was used to generate the image, if there was\ + \ any revision to the prompt" + x-ballerina-name: revisedPrompt + b64_json: + type: string + description: "The base64-encoded JSON of the generated image, if `response_format`\ + \ is `b64_json`" + x-ballerina-name: b64Json + url: + type: string + description: "The URL of the generated image, if `response_format` is `url`\ + \ (default)" + description: Represents the url or the content of an image generated by the + OpenAI API + x-oaiMeta: + name: The image object + example: | + { + "url": "...", + "revised_prompt": "..." + } + RunStepDeltaStepDetailsToolCallsObject: + title: Tool calls + required: + - type + type: object + properties: + tool_calls: + type: array + description: | + An array of tool calls the run step was involved in. These can be associated with one of three types of tools: `code_interpreter`, `file_search`, or `function` + items: + $ref: '#/components/schemas/RunStepDeltaStepDetailsToolCallsObjectToolCalls' + x-ballerina-name: toolCalls + type: + type: string + description: Always `tool_calls` + enum: + - tool_calls + description: Details of the tool call + RunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventOneOf123456: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunObject' + event: + type: string + enum: + - thread.run.incomplete + description: "Occurs when a [run](/docs/api-reference/runs/object) ends with\ + \ status `incomplete`" + x-oaiMeta: + dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" + CreateFineTuningJobRequestHyperparameters: + type: object + properties: + batch_size: + description: | + Number of examples in each batch. A larger batch size means that model parameters + are updated less frequently, but with lower variance + oneOf: + - type: string + enum: + - auto + - maximum: 256 + minimum: 1 + type: integer + default: auto + x-ballerina-name: batchSize + n_epochs: + description: | + The number of epochs to train the model for. An epoch refers to one full cycle + through the training dataset + oneOf: + - type: string + enum: + - auto + - maximum: 50 + minimum: 1 + type: integer + default: auto + x-ballerina-name: nEpochs + learning_rate_multiplier: + description: | + Scaling factor for the learning rate. A smaller learning rate may be useful to avoid + overfitting + oneOf: + - type: string + enum: + - auto + - minimum: 0 + exclusiveMinimum: true + type: number + default: auto + x-ballerina-name: learningRateMultiplier + description: The hyperparameters used for the fine-tuning job + RunObjectLastError: + required: + - code + - message + type: object + properties: + code: + type: string + description: "One of `server_error`, `rate_limit_exceeded`, or `invalid_prompt`" + enum: + - server_error + - rate_limit_exceeded + - invalid_prompt + message: + type: string + description: A human-readable description of the error + description: The last error associated with this run. Will be `null` if there + are no errors + nullable: true + CreateAssistantRequestTools: + oneOf: + - $ref: '#/components/schemas/AssistantToolsCode' + - $ref: '#/components/schemas/AssistantToolsFileSearch' + - $ref: '#/components/schemas/AssistantToolsFunction' + x-oaiExpandable: true + CreateTranscriptionResponseVerboseJson: + required: + - duration + - language + - text + type: object + properties: + duration: + type: string + description: The duration of the input audio + words: + type: array + description: Extracted words and their corresponding timestamps + items: + $ref: '#/components/schemas/TranscriptionWord' + language: + type: string + description: The language of the input audio + text: + type: string + description: The transcribed text + segments: + type: array + description: Segments of the transcribed text and their corresponding details + items: + $ref: '#/components/schemas/TranscriptionSegment' + description: "Represents a verbose json transcription response returned by model,\ + \ based on the provided input" + x-oaiMeta: + name: The transcription object (Verbose JSON) + group: audio + example: | + { + "task": "transcribe", + "language": "english", + "duration": 8.470000267028809, + "text": "The beach was a popular spot on a hot summer day. People were swimming in the ocean, building sandcastles, and playing beach volleyball.", + "segments": [ + { + "id": 0, + "seek": 0, + "start": 0.0, + "end": 3.319999933242798, + "text": " The beach was a popular spot on a hot summer day.", + "tokens": [ + 50364, 440, 7534, 390, 257, 3743, 4008, 322, 257, 2368, 4266, 786, 13, 50530 + ], + "temperature": 0.0, + "avg_logprob": -0.2860786020755768, + "compression_ratio": 1.2363636493682861, + "no_speech_prob": 0.00985979475080967 + }, + ... + ] + } + CreateRunRequestTools: + oneOf: + - $ref: '#/components/schemas/AssistantToolsCode' + - $ref: '#/components/schemas/AssistantToolsFileSearch' + - $ref: '#/components/schemas/AssistantToolsFunction' + x-oaiExpandable: true + MessageDeltaContentImageUrlObjectImageUrl: + type: object + properties: + detail: + type: string + description: "Specifies the detail level of the image. `low` uses fewer\ + \ tokens, you can opt in to high resolution using `high`" + default: auto + enum: + - auto + - low + - high + url: + type: string + description: "The URL of the image, must be a supported image types: jpeg,\ + \ jpg, png, gif, webp" + CreateTranslationRequest: + required: + - file + - model + type: object + properties: + file: + type: string + description: | + The audio file object (not file name) translate, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm + format: binary + x-oaiTypeLabel: file + response_format: + type: string + description: | + The format of the transcript output, in one of these options: `json`, `text`, `srt`, `verbose_json`, or `vtt` + default: json + x-ballerina-name: responseFormat + temperature: + type: number + description: | + The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit + default: 0 + model: + description: | + ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2 model) is currently available + example: whisper-1 + anyOf: + - type: string + - type: string + enum: + - whisper-1 + x-oaiTypeLabel: string + prompt: + type: string + description: | + An optional text to guide the model's style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text/prompting) should be in English + additionalProperties: false + MessageDeltaContentTextAnnotationsFileCitationObjectFileCitation: + type: object + properties: + quote: + type: string + description: The specific quote in the file + file_id: + type: string + description: The ID of the specific File the citation is from + x-ballerina-name: fileId + FinetuneChatRequestInputMessages: + oneOf: + - $ref: '#/components/schemas/ChatCompletionRequestSystemMessage' + - $ref: '#/components/schemas/ChatCompletionRequestUserMessage' + - $ref: '#/components/schemas/FineTuneChatCompletionRequestAssistantMessage' + - $ref: '#/components/schemas/ChatCompletionRequestToolMessage' + - $ref: '#/components/schemas/ChatCompletionRequestFunctionMessage' + x-oaiExpandable: true + UpdateVectorStoreRequest: + type: object + properties: + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + expires_after: + allOf: + - $ref: '#/components/schemas/VectorStoreExpirationAfter' + x-ballerina-name: expiresAfter + name: + type: string + description: The name of the vector store + nullable: true + additionalProperties: false + CreateFineTuningJobRequestWandb: + required: + - project + type: object + properties: + name: + type: string + description: | + A display name to set for the run. If not set, we will use the Job ID as the name + nullable: true + project: + type: string + description: | + The name of the project that the new run will be created under + example: my-wandb-project + entity: + type: string + description: | + The entity to use for the run. This allows you to set the team or username of the WandB user that you would + like associated with the run. If not set, the default entity for the registered WandB API key is used + nullable: true + tags: + type: array + description: | + A list of tags to be attached to the newly created run. These tags are passed through directly to WandB. Some + default tags are generated by OpenAI: "openai/finetune", "openai/{base-model}", "openai/{ftjob-abcdef}" + items: + type: string + example: custom-tag + description: | + The settings for your integration with Weights and Biases. This payload specifies the project that + metrics will be sent to. Optionally, you can set an explicit display name for your run, add tags + to your run, and set a default entity (team, username, etc) to be associated with your run + ChatCompletionFunctions: + required: + - name + type: object + properties: + name: + type: string + description: "The name of the function to be called. Must be a-z, A-Z, 0-9,\ + \ or contain underscores and dashes, with a maximum length of 64" + description: + type: string + description: "A description of what the function does, used by the model\ + \ to choose when and how to call the function" + parameters: + $ref: '#/components/schemas/FunctionParameters' + deprecated: true + AddUploadPartRequest: + required: + - data + type: object + properties: + data: + type: string + description: | + The chunk of bytes for this Part + format: binary + additionalProperties: false + AssistantToolsCode: + title: Code interpreter tool + required: + - type + type: object + properties: + type: + type: string + description: "The type of tool being defined: `code_interpreter`" + enum: + - code_interpreter + CreateEmbeddingResponseUsage: + required: + - prompt_tokens + - total_tokens + type: object + properties: + prompt_tokens: + type: integer + description: The number of tokens used by the prompt + x-ballerina-name: promptTokens + total_tokens: + type: integer + description: The total number of tokens used by the request + x-ballerina-name: totalTokens + description: The usage information for the request + RunStreamEventRunStreamEventRunStreamEventOneOf123: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunObject' + event: + type: string + enum: + - thread.run.in_progress + description: "Occurs when a [run](/docs/api-reference/runs/object) moves to\ + \ an `in_progress` status" + x-oaiMeta: + dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" + OtherChunkingStrategyResponseParam: + title: Other Chunking Strategy + required: + - type + type: object + properties: + type: + type: string + description: Always `other` + enum: + - other + additionalProperties: false + description: "This is returned when the chunking strategy is unknown. Typically,\ + \ this is because the file was indexed before the `chunking_strategy` concept\ + \ was introduced in the API" + RunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventOneOf12345: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunStepObject' + event: + type: string + enum: + - thread.run.step.failed + description: "Occurs when a [run step](/docs/api-reference/runs/step-object)\ + \ fails" + x-oaiMeta: + dataDescription: "`data` is a [run step](/docs/api-reference/runs/step-object)" + ChatCompletionRequestMessageContentPartImage: + title: Image content part + required: + - image_url + - type + type: object + properties: + image_url: + allOf: + - $ref: '#/components/schemas/ChatCompletionRequestMessageContentPartImageImageUrl' + x-ballerina-name: imageUrl + type: + type: string + description: The type of the content part + enum: + - image_url + BatchesBody: + required: + - completion_window + - endpoint + - input_file_id + type: object + properties: + endpoint: + type: string + description: "The endpoint to be used for all requests in the batch. Currently\ + \ `/v1/chat/completions`, `/v1/embeddings`, and `/v1/completions` are\ + \ supported. Note that `/v1/embeddings` batches are also restricted to\ + \ a maximum of 50,000 embedding inputs across all requests in the batch" + enum: + - /v1/chat/completions + - /v1/embeddings + - /v1/completions + metadata: + type: object + additionalProperties: + type: string + description: Optional custom metadata for the batch + nullable: true + input_file_id: + type: string + description: | + The ID of an uploaded file that contains requests for the new batch. + + See [upload file](/docs/api-reference/files/create) for how to upload a file. + + Your input file must be formatted as a [JSONL file](/docs/api-reference/batch/request-input), and must be uploaded with the purpose `batch`. The file can contain up to 50,000 requests, and can be up to 100 MB in size + x-ballerina-name: inputFileId + completion_window: + type: string + description: The time frame within which the batch should be processed. + Currently only `24h` is supported + enum: + - 24h + x-ballerina-name: completionWindow + AssistantObjectToolResourcesFileSearch: + type: object + properties: + vector_store_ids: + maxItems: 1 + type: array + description: | + The ID of the [vector store](/docs/api-reference/vector-stores/object) attached to this assistant. There can be a maximum of 1 vector store attached to the assistant + items: + type: string + x-ballerina-name: vectorStoreIds + MessageDeltaContentTextObject: + title: Text + required: + - index + - type + type: object + properties: + index: + type: integer + description: The index of the content part in the message + text: + $ref: '#/components/schemas/MessageDeltaContentTextObjectText' + type: + type: string + description: Always `text` + enum: + - text + description: The text content that is part of a message + CreateVectorStoreFileBatchRequest: + required: + - file_ids + type: object + properties: + chunking_strategy: + allOf: + - $ref: '#/components/schemas/ChunkingStrategyRequestParam' + x-ballerina-name: chunkingStrategy + file_ids: + maxItems: 500 + minItems: 1 + type: array + description: "A list of [File](/docs/api-reference/files) IDs that the vector\ + \ store should use. Useful for tools like `file_search` that can access\ + \ files" + items: + type: string + x-ballerina-name: fileIds + additionalProperties: false + ModifyThreadRequestToolResources: + type: object + properties: + code_interpreter: + allOf: + - $ref: '#/components/schemas/ModifyThreadRequestToolResourcesCodeInterpreter' + x-ballerina-name: codeInterpreter + file_search: + allOf: + - $ref: '#/components/schemas/ModifyThreadRequestToolResourcesFileSearch' + x-ballerina-name: fileSearch + description: | + A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs + nullable: true + RunStepDetailsToolCallsCodeObjectCodeInterpreter: + required: + - input + - outputs + type: object + properties: + outputs: + type: array + description: "The outputs from the Code Interpreter tool call. Code Interpreter\ + \ can output one or more items, including text (`logs`) or images (`image`).\ + \ Each of these are represented by a different object type" + items: + $ref: '#/components/schemas/RunStepDetailsToolCallsCodeObjectCodeInterpreterOutputs' + input: + type: string + description: The input to the Code Interpreter tool call + description: The Code Interpreter tool call definition + CreateThreadRequest: + type: object + properties: + tool_resources: + allOf: + - $ref: '#/components/schemas/CreateThreadRequestToolResources' + x-ballerina-name: toolResources + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + messages: + type: array + description: "A list of [messages](/docs/api-reference/messages) to start\ + \ the thread with" + items: + $ref: '#/components/schemas/CreateMessageRequest' + additionalProperties: false + MessageStreamEventMessageStreamEventMessageStreamEventMessageStreamEventOneOf1234: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/MessageObject' + event: + type: string + enum: + - thread.message.completed + description: "Occurs when a [message](/docs/api-reference/messages/object) is\ + \ completed" + x-oaiMeta: + dataDescription: "`data` is a [message](/docs/api-reference/messages/object)" + StaticChunkingStrategyRequestParam: + title: Static Chunking Strategy + required: + - static + - type + type: object + properties: + static: + $ref: '#/components/schemas/StaticChunkingStrategy' + type: + type: string + description: Always `static` + enum: + - static + additionalProperties: false + ModifyAssistantRequestToolResourcesFileSearch: + type: object + properties: + vector_store_ids: + maxItems: 1 + type: array + description: | + Overrides the [vector store](/docs/api-reference/vector-stores/object) attached to this assistant. There can be a maximum of 1 vector store attached to the assistant + items: + type: string + x-ballerina-name: vectorStoreIds + MessageObjectIncompleteDetails: + required: + - reason + type: object + properties: + reason: + type: string + description: The reason the message is incomplete + enum: + - content_filter + - max_tokens + - run_cancelled + - run_expired + - run_failed + description: "On an incomplete message, details about why the message is incomplete" + nullable: true + VectorStoreFileObject: + title: Vector store files + required: + - created_at + - id + - last_error + - object + - status + - usage_bytes + - vector_store_id + type: object + properties: + chunking_strategy: + type: object + description: The strategy used to chunk the file + oneOf: + - $ref: '#/components/schemas/StaticChunkingStrategyResponseParam' + - $ref: '#/components/schemas/OtherChunkingStrategyResponseParam' + x-oaiExpandable: true + x-ballerina-name: chunkingStrategy + usage_bytes: + type: integer + description: The total vector store usage in bytes. Note that this may be + different from the original file size + x-ballerina-name: usageBytes + created_at: + type: integer + description: The Unix timestamp (in seconds) for when the vector store file + was created + x-ballerina-name: createdAt + id: + type: string + description: "The identifier, which can be referenced in API endpoints" + last_error: + allOf: + - $ref: '#/components/schemas/VectorStoreFileObjectLastError' + x-ballerina-name: lastError + object: + type: string + description: "The object type, which is always `vector_store.file`" + enum: + - vector_store.file + vector_store_id: + type: string + description: "The ID of the [vector store](/docs/api-reference/vector-stores/object)\ + \ that the [File](/docs/api-reference/files) is attached to" + x-ballerina-name: vectorStoreId + status: + type: string + description: "The status of the vector store file, which can be either `in_progress`,\ + \ `completed`, `cancelled`, or `failed`. The status `completed` indicates\ + \ that the vector store file is ready for use" + enum: + - in_progress + - completed + - cancelled + - failed + description: A list of files attached to a vector store + x-oaiMeta: + name: The vector store file object + beta: true + example: | + { + "id": "file-abc123", + "object": "vector_store.file", + "usage_bytes": 1234, + "created_at": 1698107661, + "vector_store_id": "vs_abc123", + "status": "completed", + "last_error": null, + "chunking_strategy": { + "type": "static", + "static": { + "max_chunk_size_tokens": 800, + "chunk_overlap_tokens": 400 + } + } + } + CreateThreadRequestToolResourcesFileSearch: + type: object + properties: + vector_store_ids: + maxItems: 1 + type: array + description: | + The [vector store](/docs/api-reference/vector-stores/object) attached to this thread. There can be a maximum of 1 vector store attached to the thread. + items: + type: string + vector_stores: + maxItems: 1 + type: array + description: | + A helper to create a [vector store](/docs/api-reference/vector-stores/object) with file_ids and attach it to this thread. There can be a maximum of 1 vector store attached to the thread. + items: + $ref: '#/components/schemas/CreateThreadRequestToolResourcesFileSearchVectorStores' + oneOf: + - required: + - vector_store_ids + - required: + - vector_stores + Upload: + title: Upload + required: + - bytes + - created_at + - expires_at + - filename + - id + - purpose + - status + - step_number + type: object + properties: + filename: + type: string + description: The name of the file to be uploaded + expires_at: + type: integer + description: The Unix timestamp (in seconds) for when the Upload was created + x-ballerina-name: expiresAt + file: + $ref: '#/components/schemas/OpenAIFile' + purpose: + type: string + description: "The intended purpose of the file. [Please refer here](/docs/api-reference/files/object#files/object-purpose)\ + \ for acceptable values" + bytes: + type: integer + description: The intended number of bytes to be uploaded + created_at: + type: integer + description: The Unix timestamp (in seconds) for when the Upload was created + x-ballerina-name: createdAt + id: + type: string + description: "The Upload unique identifier, which can be referenced in API\ + \ endpoints" + status: + type: string + description: The status of the Upload + enum: + - pending + - completed + - cancelled + - expired + object: + type: string + description: "The object type, which is always \"upload\"" + enum: + - upload + description: | + The Upload object can accept byte chunks in the form of Parts + x-oaiMeta: + name: The upload object + example: | + { + "id": "upload_abc123", + "object": "upload", + "bytes": 2147483648, + "created_at": 1719184911, + "filename": "training_examples.jsonl", + "purpose": "fine-tune", + "status": "completed", + "expires_at": 1719127296, + "file": { + "id": "file-xyz321", + "object": "file", + "bytes": 2147483648, + "created_at": 1719186911, + "filename": "training_examples.jsonl", + "purpose": "fine-tune", + } + } + ThreadStreamEvent: + oneOf: + - $ref: '#/components/schemas/ThreadStreamEventOneOf1' + VectorStoreFileObjectLastError: + required: + - code + - message + type: object + properties: + code: + type: string + description: One of `server_error` or `rate_limit_exceeded` + enum: + - internal_error + - file_not_found + - parsing_error + - unhandled_mime_type + message: + type: string + description: A human-readable description of the error + description: The last error associated with this vector store file. Will be + `null` if there are no errors + nullable: true + FineTuningJobError: + type: object + properties: + code: + type: string + description: A machine-readable error code + param: + type: string + description: "The parameter that was invalid, usually `training_file` or\ + \ `validation_file`. This field will be null if the failure was not parameter-specific" + nullable: true + message: + type: string + description: A human-readable error message + description: "For fine-tuning jobs that have `failed`, this will contain more\ + \ information on the cause of the failure" + nullable: true + ChunkingStrategyRequestParam: + type: object + description: "The chunking strategy used to chunk the file(s). If not set, will\ + \ use the `auto` strategy" + oneOf: + - $ref: '#/components/schemas/AutoChunkingStrategyRequestParam' + - $ref: '#/components/schemas/StaticChunkingStrategyRequestParam' + x-oaiExpandable: true + CreateModerationResponseCategoryScores: + required: + - harassment + - harassment/threatening + - hate + - hate/threatening + - self-harm + - self-harm/instructions + - self-harm/intent + - sexual + - sexual/minors + - violence + - violence/graphic + type: object + properties: + self-harm/intent: + type: number + description: The score for the category 'self-harm/intent' + x-ballerina-name: selfHarmIntent + hate/threatening: + type: number + description: The score for the category 'hate/threatening' + x-ballerina-name: hateThreatening + self-harm/instructions: + type: number + description: The score for the category 'self-harm/instructions' + x-ballerina-name: selfHarmInstructions + sexual/minors: + type: number + description: The score for the category 'sexual/minors' + x-ballerina-name: sexualMinors + harassment/threatening: + type: number + description: The score for the category 'harassment/threatening' + x-ballerina-name: harassmentThreatening + hate: + type: number + description: The score for the category 'hate' + self-harm: + type: number + description: The score for the category 'self-harm' + x-ballerina-name: selfHarm + harassment: + type: number + description: The score for the category 'harassment' + sexual: + type: number + description: The score for the category 'sexual' + violence/graphic: + type: number + description: The score for the category 'violence/graphic' + x-ballerina-name: violenceGraphic + violence: + type: number + description: The score for the category 'violence' + description: A list of the categories along with their scores as predicted by + model + RunStepStreamEventRunStepStreamEventOneOf12: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunStepObject' + event: + type: string + enum: + - thread.run.step.in_progress + description: "Occurs when a [run step](/docs/api-reference/runs/step-object)\ + \ moves to an `in_progress` state" + x-oaiMeta: + dataDescription: "`data` is a [run step](/docs/api-reference/runs/step-object)" + RunCompletionUsage: + required: + - completion_tokens + - prompt_tokens + - total_tokens + type: object + properties: + completion_tokens: + type: integer + description: Number of completion tokens used over the course of the run + x-ballerina-name: completionTokens + prompt_tokens: + type: integer + description: Number of prompt tokens used over the course of the run + x-ballerina-name: promptTokens + total_tokens: + type: integer + description: Total number of tokens used (prompt + completion) + x-ballerina-name: totalTokens + description: "Usage statistics related to the run. This value will be `null`\ + \ if the run is not in a terminal state (i.e. `in_progress`, `queued`, etc.)" + nullable: true + MessageContentImageUrlObject: + title: Image URL + required: + - image_url + - type + type: object + properties: + image_url: + allOf: + - $ref: '#/components/schemas/MessageContentImageUrlObjectImageUrl' + x-ballerina-name: imageUrl + type: + type: string + description: The type of the content part + enum: + - image_url + description: References an image URL in the content of a message + ChatCompletionResponseMessageFunctionCall: + required: + - arguments + - name + type: object + properties: + name: + type: string + description: The name of the function to call + arguments: + type: string + description: "The arguments to call the function with, as generated by the\ + \ model in JSON format. Note that the model does not always generate valid\ + \ JSON, and may hallucinate parameters not defined by your function schema.\ + \ Validate the arguments in your code before calling your function" + description: "Deprecated and replaced by `tool_calls`. The name and arguments\ + \ of a function that should be called, as generated by the model" + deprecated: true + DeleteModelResponse: + required: + - deleted + - id + - object + type: object + properties: + deleted: + type: boolean + id: + type: string + object: + type: string + ImagesResponse: + required: + - created + - data + properties: + created: + type: integer + data: + type: array + items: + $ref: '#/components/schemas/Image' + CreateCompletionResponseChoices: + required: + - finish_reason + - index + - logprobs + - text + type: object + properties: + finish_reason: + type: string + description: | + The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence, + `length` if the maximum number of tokens specified in the request was reached, + or `content_filter` if content was omitted due to a flag from our content filters + enum: + - stop + - length + - content_filter + x-ballerina-name: finishReason + index: + type: integer + text: + type: string + logprobs: + $ref: '#/components/schemas/CreateCompletionResponseLogprobs' + RunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventOneOf1234: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunStepObject' + event: + type: string + enum: + - thread.run.step.completed + description: "Occurs when a [run step](/docs/api-reference/runs/step-object)\ + \ is completed" + x-oaiMeta: + dataDescription: "`data` is a [run step](/docs/api-reference/runs/step-object)" + MessageDeltaContentImageFileObjectImageFile: + type: object + properties: + file_id: + type: string + description: "The [File](/docs/api-reference/files) ID of the image in the\ + \ message content. Set `purpose=\"vision\"` when uploading the File if\ + \ you need to later display the file content" + x-ballerina-name: fileId + detail: + type: string + description: "Specifies the detail level of the image if specified by the\ + \ user. `low` uses fewer tokens, you can opt in to high resolution using\ + \ `high`" + default: auto + enum: + - auto + - low + - high + CreateChatCompletionStreamResponse: + required: + - choices + - created + - id + - model + - object + type: object + properties: + created: + type: integer + description: The Unix timestamp (in seconds) of when the chat completion + was created. Each chunk has the same timestamp + usage: + $ref: '#/components/schemas/CreateChatCompletionStreamResponseUsage' + model: + type: string + description: The model to generate the completion + service_tier: + type: string + description: The service tier used for processing the request. This field + is only included if the `service_tier` parameter is specified in the request + nullable: true + example: scale + enum: + - scale + - default + x-ballerina-name: serviceTier + id: + type: string + description: A unique identifier for the chat completion. Each chunk has + the same ID + choices: + type: array + description: | + A list of chat completion choices. Can contain more than one elements if `n` is greater than 1. Can also be empty for the + last chunk if you set `stream_options: {"include_usage": true}` + items: + $ref: '#/components/schemas/CreateChatCompletionStreamResponseChoices' + system_fingerprint: + type: string + description: | + This fingerprint represents the backend configuration that the model runs with. + Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism + x-ballerina-name: systemFingerprint + object: + type: string + description: "The object type, which is always `chat.completion.chunk`" + enum: + - chat.completion.chunk + description: "Represents a streamed chunk of a chat completion response returned\ + \ by model, based on the provided input" + x-oaiMeta: + name: The chat completion chunk object + group: chat + example: | + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-4o-mini", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]} + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-4o-mini", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"Hello"},"logprobs":null,"finish_reason":null}]} + + .... + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-4o-mini", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}]} + ? RunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventOneOf1234567 + : required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunStepObject' + event: + type: string + enum: + - thread.run.step.expired + description: "Occurs when a [run step](/docs/api-reference/runs/step-object)\ + \ expires" + x-oaiMeta: + dataDescription: "`data` is a [run step](/docs/api-reference/runs/step-object)" + CreateChatCompletionFunctionResponseChoices: + required: + - finish_reason + - index + - logprobs + - message + type: object + properties: + finish_reason: + type: string + description: | + The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence, `length` if the maximum number of tokens specified in the request was reached, `content_filter` if content was omitted due to a flag from our content filters, or `function_call` if the model called a function + enum: + - stop + - length + - function_call + - content_filter + x-ballerina-name: finishReason + index: + type: integer + description: The index of the choice in the list of choices + message: + $ref: '#/components/schemas/ChatCompletionResponseMessage' + ChatCompletionMessageToolCall: + required: + - function + - id + - type + type: object + properties: + function: + $ref: '#/components/schemas/ChatCompletionMessageToolCallFunction' + id: + type: string + description: The ID of the tool call + type: + type: string + description: "The type of the tool. Currently, only `function` is supported" + enum: + - function + RunStepDeltaStepDetailsToolCallsCodeOutputImageObjectImage: + type: object + properties: + file_id: + type: string + description: "The [file](/docs/api-reference/files) ID of the image" + x-ballerina-name: fileId + VectorStoreFileBatchObjectFileCounts: + required: + - cancelled + - completed + - failed + - in_progress + - total + type: object + properties: + in_progress: + type: integer + description: The number of files that are currently being processed + x-ballerina-name: inProgress + total: + type: integer + description: The total number of files + cancelled: + type: integer + description: The number of files that where cancelled + completed: + type: integer + description: The number of files that have been processed + failed: + type: integer + description: The number of files that have failed to process + CreateImageEditRequest: + required: + - image + - prompt + type: object + properties: + image: + type: string + description: "The image to edit. Must be a valid PNG file, less than 4MB,\ + \ and square. If mask is not provided, image must have transparency, which\ + \ will be used as the mask" + format: binary + response_format: + type: string + description: The format in which the generated images are returned. Must + be one of `url` or `b64_json`. URLs are only valid for 60 minutes after + the image has been generated + nullable: true + example: url + default: url + enum: + - url + - b64_json + x-ballerina-name: responseFormat + size: + type: string + description: "The size of the generated images. Must be one of `256x256`,\ + \ `512x512`, or `1024x1024`" + nullable: true + example: 1024x1024 + default: 1024x1024 + enum: + - 256x256 + - 512x512 + - 1024x1024 + model: + description: The model to use for image generation. Only `dall-e-2` is supported + at this time + nullable: true + example: dall-e-2 + anyOf: + - type: string + - type: string + enum: + - dall-e-2 + default: dall-e-2 + x-oaiTypeLabel: string + prompt: + type: string + description: A text description of the desired image(s). The maximum length + is 1000 characters + example: A cute baby sea otter wearing a beret + user: + type: string + description: | + A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids) + example: user-1234 + "n": + maximum: 10 + minimum: 1 + type: integer + description: The number of images to generate. Must be between 1 and 10 + nullable: true + example: 1 + default: 1 + mask: + type: string + description: "An additional image whose fully transparent areas (e.g. where\ + \ alpha is zero) indicate where `image` should be edited. Must be a valid\ + \ PNG file, less than 4MB, and have the same dimensions as `image`" + format: binary + MessageDeltaContentTextAnnotationsFileCitationObject: + title: File citation + required: + - index + - type + type: object + properties: + start_index: + minimum: 0 + type: integer + x-ballerina-name: startIndex + file_citation: + allOf: + - $ref: '#/components/schemas/MessageDeltaContentTextAnnotationsFileCitationObjectFileCitation' + x-ballerina-name: fileCitation + index: + type: integer + description: The index of the annotation in the text content part + end_index: + minimum: 0 + type: integer + x-ballerina-name: endIndex + text: + type: string + description: The text in the message content that needs to be replaced + type: + type: string + description: Always `file_citation` + enum: + - file_citation + description: A citation within the message that points to a specific quote from + a specific File associated with the assistant or the message. Generated when + the assistant uses the "file_search" tool to search files + AssistantToolsFileSearchFileSearch: + type: object + properties: + max_num_results: + maximum: 50 + minimum: 1 + type: integer + description: | + The maximum number of results the file search tool should output. The default is 20 for gpt-4* models and 5 for gpt-3.5-turbo. This number should be between 1 and 50 inclusive. + + Note that the file search tool may output fewer than `max_num_results` results. See the [file search tool documentation](/docs/assistants/tools/file-search/number-of-chunks-returned) for more information + x-ballerina-name: maxNumResults + description: Overrides for the file search tool + ListModelsResponse: + required: + - data + - object + type: object + properties: + data: + type: array + items: + $ref: '#/components/schemas/Model' + object: + type: string + enum: + - list + ChatCompletionRole: + type: string + description: The role of the author of a message + enum: + - system + - user + - assistant + - tool + - function + AssistantObjectTools: + oneOf: + - $ref: '#/components/schemas/AssistantToolsCode' + - $ref: '#/components/schemas/AssistantToolsFileSearch' + - $ref: '#/components/schemas/AssistantToolsFunction' + x-oaiExpandable: true + CreateThreadRequestToolResourcesFileSearchVectorStores: + type: object + properties: + chunking_strategy: + type: object + description: "The chunking strategy used to chunk the file(s). If not set,\ + \ will use the `auto` strategy" + oneOf: + - title: Auto Chunking Strategy + required: + - type + type: object + properties: + type: + type: string + description: Always `auto`. + enum: + - auto additionalProperties: false - properties: - file_ids: - description: A list of [File](/docs/api-reference/files) IDs that the vector store should use. Useful for tools like `file_search` that can access files. - type: array - minItems: 1 - maxItems: 500 - items: - type: string - chunking_strategy: - $ref: "#/components/schemas/ChunkingStrategyRequestParam" - required: - - file_ids - - AssistantStreamEvent: - description: | - Represents an event emitted when streaming a Run. - - Each event in a server-sent events stream has an `event` and `data` property: - - ``` - event: thread.created - data: {"id": "thread_123", "object": "thread", ...} - ``` - - We emit events whenever a new object is created, transitions to a new state, or is being - streamed in parts (deltas). For example, we emit `thread.run.created` when a new run - is created, `thread.run.completed` when a run completes, and so on. When an Assistant chooses - to create a message during a run, we emit a `thread.message.created event`, a - `thread.message.in_progress` event, many `thread.message.delta` events, and finally a - `thread.message.completed` event. - - We may add additional events over time, so we recommend handling unknown events gracefully - in your code. See the [Assistants API quickstart](/docs/assistants/overview) to learn how to - integrate the Assistants API with streaming. - oneOf: - - $ref: "#/components/schemas/ThreadStreamEvent" - - $ref: "#/components/schemas/RunStreamEvent" - - $ref: "#/components/schemas/RunStepStreamEvent" - - $ref: "#/components/schemas/MessageStreamEvent" - - $ref: "#/components/schemas/ErrorEvent" - - $ref: "#/components/schemas/DoneEvent" - x-oaiMeta: - name: Assistant stream events - beta: true - - ThreadStreamEvent: - oneOf: - - type: object - properties: - event: - type: string - enum: ["thread.created"] - data: - $ref: "#/components/schemas/ThreadObject" - required: - - event - - data - description: Occurs when a new [thread](/docs/api-reference/threads/object) is created. - x-oaiMeta: - dataDescription: "`data` is a [thread](/docs/api-reference/threads/object)" - - RunStreamEvent: - oneOf: - - type: object - properties: - event: - type: string - enum: ["thread.run.created"] - data: - $ref: "#/components/schemas/RunObject" - required: - - event - - data - description: Occurs when a new [run](/docs/api-reference/runs/object) is created. - x-oaiMeta: - dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" - - type: object - properties: - event: - type: string - enum: ["thread.run.queued"] - data: - $ref: "#/components/schemas/RunObject" - required: - - event - - data - description: Occurs when a [run](/docs/api-reference/runs/object) moves to a `queued` status. - x-oaiMeta: - dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" - - type: object - properties: - event: - type: string - enum: ["thread.run.in_progress"] - data: - $ref: "#/components/schemas/RunObject" - required: - - event - - data - description: Occurs when a [run](/docs/api-reference/runs/object) moves to an `in_progress` status. - x-oaiMeta: - dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" - - type: object - properties: - event: - type: string - enum: ["thread.run.requires_action"] - data: - $ref: "#/components/schemas/RunObject" - required: - - event - - data - description: Occurs when a [run](/docs/api-reference/runs/object) moves to a `requires_action` status. - x-oaiMeta: - dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" - - type: object - properties: - event: - type: string - enum: ["thread.run.completed"] - data: - $ref: "#/components/schemas/RunObject" - required: - - event - - data - description: Occurs when a [run](/docs/api-reference/runs/object) is completed. - x-oaiMeta: - dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" - - type: object - properties: - event: - type: string - enum: [ "thread.run.incomplete" ] - data: - $ref: "#/components/schemas/RunObject" - required: - - event - - data - description: Occurs when a [run](/docs/api-reference/runs/object) ends with status `incomplete`. - x-oaiMeta: - dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" - - type: object - properties: - event: - type: string - enum: ["thread.run.failed"] - data: - $ref: "#/components/schemas/RunObject" - required: - - event - - data - description: Occurs when a [run](/docs/api-reference/runs/object) fails. - x-oaiMeta: - dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" - - type: object - properties: - event: - type: string - enum: ["thread.run.cancelling"] - data: - $ref: "#/components/schemas/RunObject" - required: - - event - - data - description: Occurs when a [run](/docs/api-reference/runs/object) moves to a `cancelling` status. - x-oaiMeta: - dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" - - type: object - properties: - event: - type: string - enum: ["thread.run.cancelled"] - data: - $ref: "#/components/schemas/RunObject" - required: - - event - - data - description: Occurs when a [run](/docs/api-reference/runs/object) is cancelled. - x-oaiMeta: - dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" - - type: object - properties: - event: - type: string - enum: ["thread.run.expired"] - data: - $ref: "#/components/schemas/RunObject" - required: - - event - - data - description: Occurs when a [run](/docs/api-reference/runs/object) expires. - x-oaiMeta: - dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" - - RunStepStreamEvent: - oneOf: - - type: object - properties: - event: - type: string - enum: ["thread.run.step.created"] - data: - $ref: "#/components/schemas/RunStepObject" - required: - - event - - data - description: Occurs when a [run step](/docs/api-reference/runs/step-object) is created. - x-oaiMeta: - dataDescription: "`data` is a [run step](/docs/api-reference/runs/step-object)" - - type: object - properties: - event: - type: string - enum: ["thread.run.step.in_progress"] - data: - $ref: "#/components/schemas/RunStepObject" - required: - - event - - data - description: Occurs when a [run step](/docs/api-reference/runs/step-object) moves to an `in_progress` state. - x-oaiMeta: - dataDescription: "`data` is a [run step](/docs/api-reference/runs/step-object)" - - type: object - properties: - event: - type: string - enum: ["thread.run.step.delta"] - data: - $ref: "#/components/schemas/RunStepDeltaObject" - required: - - event - - data - description: Occurs when parts of a [run step](/docs/api-reference/runs/step-object) are being streamed. - x-oaiMeta: - dataDescription: "`data` is a [run step delta](/docs/api-reference/assistants-streaming/run-step-delta-object)" - - type: object - properties: - event: - type: string - enum: ["thread.run.step.completed"] - data: - $ref: "#/components/schemas/RunStepObject" - required: - - event - - data - description: Occurs when a [run step](/docs/api-reference/runs/step-object) is completed. - x-oaiMeta: - dataDescription: "`data` is a [run step](/docs/api-reference/runs/step-object)" - - type: object - properties: - event: - type: string - enum: ["thread.run.step.failed"] - data: - $ref: "#/components/schemas/RunStepObject" - required: - - event - - data - description: Occurs when a [run step](/docs/api-reference/runs/step-object) fails. - x-oaiMeta: - dataDescription: "`data` is a [run step](/docs/api-reference/runs/step-object)" - - type: object - properties: - event: - type: string - enum: ["thread.run.step.cancelled"] - data: - $ref: "#/components/schemas/RunStepObject" - required: - - event - - data - description: Occurs when a [run step](/docs/api-reference/runs/step-object) is cancelled. - x-oaiMeta: - dataDescription: "`data` is a [run step](/docs/api-reference/runs/step-object)" - - type: object - properties: - event: - type: string - enum: ["thread.run.step.expired"] - data: - $ref: "#/components/schemas/RunStepObject" - required: - - event - - data - description: Occurs when a [run step](/docs/api-reference/runs/step-object) expires. - x-oaiMeta: - dataDescription: "`data` is a [run step](/docs/api-reference/runs/step-object)" - - MessageStreamEvent: - oneOf: - - type: object - properties: - event: - type: string - enum: ["thread.message.created"] - data: - $ref: "#/components/schemas/MessageObject" - required: - - event - - data - description: Occurs when a [message](/docs/api-reference/messages/object) is created. - x-oaiMeta: - dataDescription: "`data` is a [message](/docs/api-reference/messages/object)" - - type: object - properties: - event: - type: string - enum: ["thread.message.in_progress"] - data: - $ref: "#/components/schemas/MessageObject" - required: - - event - - data - description: Occurs when a [message](/docs/api-reference/messages/object) moves to an `in_progress` state. - x-oaiMeta: - dataDescription: "`data` is a [message](/docs/api-reference/messages/object)" - - type: object - properties: - event: - type: string - enum: ["thread.message.delta"] - data: - $ref: "#/components/schemas/MessageDeltaObject" - required: - - event - - data - description: Occurs when parts of a [Message](/docs/api-reference/messages/object) are being streamed. - x-oaiMeta: - dataDescription: "`data` is a [message delta](/docs/api-reference/assistants-streaming/message-delta-object)" - - type: object - properties: - event: - type: string - enum: ["thread.message.completed"] - data: - $ref: "#/components/schemas/MessageObject" - required: - - event - - data - description: Occurs when a [message](/docs/api-reference/messages/object) is completed. - x-oaiMeta: - dataDescription: "`data` is a [message](/docs/api-reference/messages/object)" - - type: object - properties: - event: - type: string - enum: ["thread.message.incomplete"] - data: - $ref: "#/components/schemas/MessageObject" - required: - - event - - data - description: Occurs when a [message](/docs/api-reference/messages/object) ends before it is completed. - x-oaiMeta: - dataDescription: "`data` is a [message](/docs/api-reference/messages/object)" - - ErrorEvent: - type: object - properties: - event: - type: string - enum: ["error"] - data: - $ref: "#/components/schemas/Error" - required: - - event - - data - description: Occurs when an [error](/docs/guides/error-codes/api-errors) occurs. This can happen due to an internal server error or a timeout. - x-oaiMeta: - dataDescription: "`data` is an [error](/docs/guides/error-codes/api-errors)" - - DoneEvent: - type: object - properties: - event: - type: string - enum: ["done"] - data: - type: string - enum: ["[DONE]"] + description: The default strategy. This strategy currently uses a `max_chunk_size_tokens` + of `800` and `chunk_overlap_tokens` of `400`. + - title: Static Chunking Strategy required: - - event - - data - description: Occurs when a stream ends. - x-oaiMeta: - dataDescription: "`data` is `[DONE]`" - - Batch: + - static + - type type: object properties: - id: - type: string - object: - type: string - enum: [batch] - description: The object type, which is always `batch`. - endpoint: - type: string - description: The OpenAI API endpoint used by the batch. - - errors: - type: object - properties: - object: - type: string - description: The object type, which is always `list`. - data: - type: array - items: - type: object - properties: - code: - type: string - description: An error code identifying the error type. - message: - type: string - description: A human-readable message providing more details about the error. - param: - type: string - description: The name of the parameter that caused the error, if applicable. - nullable: true - line: - type: integer - description: The line number of the input file where the error occurred, if applicable. - nullable: true - input_file_id: - type: string - description: The ID of the input file for the batch. - completion_window: - type: string - description: The time frame within which the batch should be processed. - status: - type: string - description: The current status of the batch. - enum: - - validating - - failed - - in_progress - - finalizing - - completed - - expired - - cancelling - - cancelled - output_file_id: - type: string - description: The ID of the file containing the outputs of successfully executed requests. - error_file_id: - type: string - description: The ID of the file containing the outputs of requests with errors. - created_at: - type: integer - description: The Unix timestamp (in seconds) for when the batch was created. - in_progress_at: - type: integer - description: The Unix timestamp (in seconds) for when the batch started processing. - expires_at: - type: integer - description: The Unix timestamp (in seconds) for when the batch will expire. - finalizing_at: - type: integer - description: The Unix timestamp (in seconds) for when the batch started finalizing. - completed_at: - type: integer - description: The Unix timestamp (in seconds) for when the batch was completed. - failed_at: - type: integer - description: The Unix timestamp (in seconds) for when the batch failed. - expired_at: - type: integer - description: The Unix timestamp (in seconds) for when the batch expired. - cancelling_at: + type: + type: string + description: Always `static`. + enum: + - static + static: + required: + - chunk_overlap_tokens + - max_chunk_size_tokens + type: object + properties: + max_chunk_size_tokens: + maximum: 4096 + minimum: 100 type: integer - description: The Unix timestamp (in seconds) for when the batch started cancelling. - cancelled_at: + description: The maximum number of tokens in each chunk. The default + value is `800`. The minimum value is `100` and the maximum value + is `4096`. + chunk_overlap_tokens: type: integer - description: The Unix timestamp (in seconds) for when the batch was cancelled. - request_counts: - type: object - properties: - total: - type: integer - description: Total number of requests in the batch. - completed: - type: integer - description: Number of requests that have been completed successfully. - failed: - type: integer - description: Number of requests that have failed. - required: - - total - - completed - - failed - description: The request counts for different statuses within the batch. - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - required: - - id - - object - - endpoint - - input_file_id - - completion_window - - status - - created_at - x-oaiMeta: - name: The batch object - example: *batch_object - - BatchRequestInput: - type: object - description: The per-line object of the batch input file - properties: - custom_id: - type: string - description: A developer-provided per-request id that will be used to match outputs to inputs. Must be unique for each request in a batch. - method: - type: string - enum: ["POST"] - description: The HTTP method to be used for the request. Currently only `POST` is supported. - url: - type: string - description: The OpenAI API relative URL to be used for the request. Currently `/v1/chat/completions`, `/v1/embeddings`, and `/v1/completions` are supported. - x-oaiMeta: - name: The request input object - example: | - {"custom_id": "request-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "gpt-3.5-turbo", "messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is 2+2?"}]}} - - BatchRequestOutput: - type: object - description: The per-line object of the batch output and error files - properties: - id: - type: string - custom_id: - type: string - description: A developer-provided per-request id that will be used to match outputs to inputs. - response: - type: object - nullable: true - properties: - status_code: - type: integer - description: The HTTP status code of the response - request_id: - type: string - description: An unique identifier for the OpenAI API request. Please include this request ID when contacting support. - body: - type: object - x-oaiTypeLabel: map - description: The JSON body of the response - error: - type: object - nullable: true - description: For requests that failed with a non-HTTP error, this will contain more information on the cause of the failure. - properties: - code: - type: string - description: A machine-readable error code. - message: - type: string - description: A human-readable error message. - x-oaiMeta: - name: The request output object - example: | - {"id": "batch_req_wnaDys", "custom_id": "request-2", "response": {"status_code": 200, "request_id": "req_c187b3", "body": {"id": "chatcmpl-9758Iw", "object": "chat.completion", "created": 1711475054, "model": "gpt-3.5-turbo", "choices": [{"index": 0, "message": {"role": "assistant", "content": "2 + 2 equals 4."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 24, "completion_tokens": 15, "total_tokens": 39}, "system_fingerprint": null}}, "error": null} - - ListBatchesResponse: - type: object - properties: - data: - type: array - items: - $ref: "#/components/schemas/Batch" - first_id: - type: string - example: "batch_abc123" - last_id: - type: string - example: "batch_abc456" - has_more: - type: boolean - object: - type: string - enum: [list] - required: - - object - - data - - has_more - -security: - - ApiKeyAuth: [] + description: | + The number of tokens that overlap between chunks. The default value is `400`. + Note that the overlap must not exceed half of `max_chunk_size_tokens`. + additionalProperties: false + additionalProperties: false + x-oaiExpandable: true + x-ballerina-name: chunkingStrategy + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to a vector store. This can be useful for storing additional information about the vector store in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + x-oaiTypeLabel: map + file_ids: + maxItems: 10000 + type: array + description: | + A list of [file](/docs/api-reference/files) IDs to add to the vector store. There can be a maximum of 10000 files in a vector store + items: + type: string + x-ballerina-name: fileIds + Model: + title: Model + required: + - created + - id + - object + - owned_by + properties: + id: + type: string + description: "The model identifier, which can be referenced in the API endpoints." + created: + type: integer + description: The Unix timestamp (in seconds) when the model was created. + object: + type: string + description: "The object type, which is always \"model\"." + enum: + - model + owned_by: + type: string + description: The organization that owns the model. + description: Describes an OpenAI model offering that can be used with the API + x-oaiMeta: + name: The model object + example: | + { + "id": "VAR_model_id", + "object": "model", + "created": 1686935002, + "owned_by": "openai" + } + ErrorEvent: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/Error' + event: + type: string + enum: + - error + description: "Occurs when an [error](/docs/guides/error-codes/api-errors) occurs.\ + \ This can happen due to an internal server error or a timeout" + x-oaiMeta: + dataDescription: "`data` is an [error](/docs/guides/error-codes/api-errors)" + ListFilesResponse: + required: + - data + - object + type: object + properties: + data: + type: array + items: + $ref: '#/components/schemas/OpenAIFile' + object: + type: string + enum: + - list + CreateChatCompletionStreamResponseChoices: + required: + - delta + - finish_reason + - index + type: object + properties: + finish_reason: + type: string + description: | + The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence, + `length` if the maximum number of tokens specified in the request was reached, + `content_filter` if content was omitted due to a flag from our content filters, + `tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function + nullable: true + enum: + - stop + - length + - tool_calls + - content_filter + - function_call + x-ballerina-name: finishReason + delta: + $ref: '#/components/schemas/ChatCompletionStreamResponseDelta' + index: + type: integer + description: The index of the choice in the list of choices + logprobs: + $ref: '#/components/schemas/CreateChatCompletionStreamResponseLogprobs' + FineTuneChatCompletionRequestAssistantMessage: + required: + - role + allOf: + - $ref: '#/components/schemas/AssistantMessage' + - $ref: '#/components/schemas/ChatCompletionRequestAssistantMessage' + CreateVectorStoreRequest: + type: object + properties: + chunking_strategy: + type: object + description: "The chunking strategy used to chunk the file(s). If not set,\ + \ will use the `auto` strategy. Only applicable if `file_ids` is non-empty" + oneOf: + - $ref: '#/components/schemas/AutoChunkingStrategyRequestParam' + - $ref: '#/components/schemas/StaticChunkingStrategyRequestParam' + x-oaiExpandable: true + x-ballerina-name: chunkingStrategy + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + expires_after: + allOf: + - $ref: '#/components/schemas/VectorStoreExpirationAfter' + x-ballerina-name: expiresAfter + file_ids: + maxItems: 500 + type: array + description: "A list of [File](/docs/api-reference/files) IDs that the vector\ + \ store should use. Useful for tools like `file_search` that can access\ + \ files" + items: + type: string + x-ballerina-name: fileIds + name: + type: string + description: The name of the vector store + additionalProperties: false + ThreadObject: + title: Thread + required: + - created_at + - id + - metadata + - object + - tool_resources + type: object + properties: + tool_resources: + allOf: + - $ref: '#/components/schemas/ThreadObjectToolResources' + x-ballerina-name: toolResources + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + created_at: + type: integer + description: The Unix timestamp (in seconds) for when the thread was created + x-ballerina-name: createdAt + id: + type: string + description: "The identifier, which can be referenced in API endpoints" + object: + type: string + description: "The object type, which is always `thread`" + enum: + - thread + description: "Represents a thread that contains [messages](/docs/api-reference/messages)" + x-oaiMeta: + name: The thread object + beta: true + example: | + { + "id": "thread_abc123", + "object": "thread", + "created_at": 1698107661, + "metadata": {} + } + CreateChatCompletionResponseChoices: + required: + - finish_reason + - index + - logprobs + - message + type: object + properties: + finish_reason: + type: string + description: | + The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence, + `length` if the maximum number of tokens specified in the request was reached, + `content_filter` if content was omitted due to a flag from our content filters, + `tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function + enum: + - stop + - length + - tool_calls + - content_filter + - function_call + x-ballerina-name: finishReason + index: + type: integer + description: The index of the choice in the list of choices + message: + $ref: '#/components/schemas/ChatCompletionResponseMessage' + logprobs: + $ref: '#/components/schemas/CreateChatCompletionResponseLogprobs' + ChatCompletionStreamOptions: + type: object + properties: + include_usage: + type: boolean + description: | + If set, an additional chunk will be streamed before the `data: [DONE]` message. The `usage` field on this chunk shows the token usage statistics for the entire request, and the `choices` field will always be an empty array. All other chunks will also include a `usage` field, but with a null value + x-ballerina-name: includeUsage + description: | + Options for streaming response. Only set this when you set `stream: true` + nullable: true + MessageContentTextAnnotationsFileCitationObject: + title: File citation + required: + - end_index + - file_citation + - start_index + - text + - type + type: object + properties: + start_index: + minimum: 0 + type: integer + x-ballerina-name: startIndex + file_citation: + allOf: + - $ref: '#/components/schemas/MessageContentTextAnnotationsFileCitationObjectFileCitation' + x-ballerina-name: fileCitation + end_index: + minimum: 0 + type: integer + x-ballerina-name: endIndex + text: + type: string + description: The text in the message content that needs to be replaced + type: + type: string + description: Always `file_citation` + enum: + - file_citation + description: A citation within the message that points to a specific quote from + a specific File associated with the assistant or the message. Generated when + the assistant uses the "file_search" tool to search files + MessageStreamEventMessageStreamEventMessageStreamEventMessageStreamEventMessageStreamEventOneOf12345: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/MessageObject' + event: + type: string + enum: + - thread.message.incomplete + description: "Occurs when a [message](/docs/api-reference/messages/object) ends\ + \ before it is completed" + x-oaiMeta: + dataDescription: "`data` is a [message](/docs/api-reference/messages/object)" + ListPaginatedFineTuningJobsResponse: + required: + - data + - has_more + - object + type: object + properties: + data: + type: array + items: + $ref: '#/components/schemas/FineTuningJob' + has_more: + type: boolean + x-ballerina-name: hasMore + object: + type: string + enum: + - list + ? RunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventOneOf12345678910 + : required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunObject' + event: + type: string + enum: + - thread.run.expired + description: "Occurs when a [run](/docs/api-reference/runs/object) expires" + x-oaiMeta: + dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" + ModifyAssistantRequest: + type: object + properties: + top_p: + maximum: 1 + minimum: 0 + type: number + description: | + An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + + We generally recommend altering this or temperature but not both + nullable: true + example: 1 + default: 1 + x-ballerina-name: topP + instructions: + maxLength: 256000 + type: string + description: | + The system instructions that the assistant uses. The maximum length is 256,000 characters + nullable: true + tool_resources: + allOf: + - $ref: '#/components/schemas/ModifyAssistantRequestToolResources' + x-ballerina-name: toolResources + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + response_format: + allOf: + - $ref: '#/components/schemas/AssistantsApiResponseFormatOption' + x-ballerina-name: responseFormat + name: + maxLength: 256 + type: string + description: | + The name of the assistant. The maximum length is 256 characters + nullable: true + temperature: + maximum: 2 + minimum: 0 + type: number + description: | + What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic + nullable: true + example: 1 + default: 1 + description: + maxLength: 512 + type: string + description: | + The description of the assistant. The maximum length is 512 characters + nullable: true + model: + description: | + ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](/docs/models/overview) for descriptions of them + anyOf: + - type: string + tools: + maxItems: 128 + type: array + description: | + A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `file_search`, or `function` + items: + $ref: '#/components/schemas/ModifyAssistantRequestTools' + default: [] + additionalProperties: false + FineTuningJobCheckpointMetrics: + type: object + properties: + full_valid_mean_token_accuracy: + type: number + x-ballerina-name: fullValidMeanTokenAccuracy + valid_loss: + type: number + x-ballerina-name: validLoss + full_valid_loss: + type: number + x-ballerina-name: fullValidLoss + train_mean_token_accuracy: + type: number + x-ballerina-name: trainMeanTokenAccuracy + valid_mean_token_accuracy: + type: number + x-ballerina-name: validMeanTokenAccuracy + train_loss: + type: number + x-ballerina-name: trainLoss + step: + type: number + description: Metrics at the step number during the fine-tuning job + FinetuneChatRequestInput: + type: object + properties: + parallel_tool_calls: + allOf: + - $ref: '#/components/schemas/ParallelToolCalls' + x-ballerina-name: parallelToolCalls + functions: + maxItems: 128 + minItems: 1 + type: array + description: A list of functions the model may generate JSON inputs for + deprecated: true + items: + $ref: '#/components/schemas/ChatCompletionFunctions' + messages: + minItems: 1 + type: array + items: + $ref: '#/components/schemas/FinetuneChatRequestInputMessages' + tools: + type: array + description: A list of tools the model may generate JSON inputs for + items: + $ref: '#/components/schemas/ChatCompletionTool' + description: The per-line training example of a fine-tuning input file for chat + models + x-oaiMeta: + name: Training format for chat models + example: | + { + "messages": [ + { "role": "user", "content": "What is the weather in San Francisco?" }, + { + "role": "assistant", + "tool_calls": [ + { + "id": "call_id", + "type": "function", + "function": { + "name": "get_current_weather", + "arguments": "{\"location\": \"San Francisco, USA\", \"format\": \"celsius\"}" + } + } + ] + } + ], + "parallel_tool_calls": false, + "tools": [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and country, eg. San Francisco, USA" + }, + "format": { "type": "string", "enum": ["celsius", "fahrenheit"] } + }, + "required": ["location", "format"] + } + } + } + ] + } + MessageContentTextObjectTextAnnotations: + oneOf: + - $ref: '#/components/schemas/MessageContentTextAnnotationsFileCitationObject' + - $ref: '#/components/schemas/MessageContentTextAnnotationsFilePathObject' + x-oaiExpandable: true + RunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventOneOf12345678: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunObject' + event: + type: string + enum: + - thread.run.cancelling + description: "Occurs when a [run](/docs/api-reference/runs/object) moves to\ + \ a `cancelling` status" + x-oaiMeta: + dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" + BatchRequestOutputResponse: + type: object + properties: + status_code: + type: integer + description: The HTTP status code of the response + x-ballerina-name: statusCode + body: + type: object + description: The JSON body of the response + x-oaiTypeLabel: map + request_id: + type: string + description: An unique identifier for the OpenAI API request. Please include + this request ID when contacting support + x-ballerina-name: requestId + nullable: true + ChatCompletionRequestAssistantMessage: + title: Assistant message + required: + - role + type: object + properties: + role: + type: string + description: "The role of the messages author, in this case `assistant`" + enum: + - assistant + function_call: + allOf: + - $ref: '#/components/schemas/ChatCompletionRequestAssistantMessageFunctionCall' + x-ballerina-name: functionCall + name: + type: string + description: An optional name for the participant. Provides the model information + to differentiate between participants of the same role + tool_calls: + allOf: + - $ref: '#/components/schemas/ChatCompletionMessageToolCalls' + x-ballerina-name: toolCalls + content: + type: string + description: | + The contents of the assistant message. Required unless `tool_calls` or `function_call` is specified + nullable: true + RunStepDeltaObject: + title: Run step delta object + required: + - delta + - id + - object + type: object + properties: + delta: + $ref: '#/components/schemas/RunStepDeltaObjectDelta' + id: + type: string + description: "The identifier of the run step, which can be referenced in\ + \ API endpoints" + object: + type: string + description: "The object type, which is always `thread.run.step.delta`" + enum: + - thread.run.step.delta + description: | + Represents a run step delta i.e. any changed fields on a run step during streaming + x-oaiMeta: + name: The run step delta object + beta: true + example: | + { + "id": "step_123", + "object": "thread.run.step.delta", + "delta": { + "step_details": { + "type": "tool_calls", + "tool_calls": [ + { + "index": 0, + "id": "call_123", + "type": "code_interpreter", + "code_interpreter": { "input": "", "outputs": [] } + } + ] + } + } + } + ListVectorStoresResponse: + required: + - data + - first_id + - has_more + - last_id + - object + properties: + object: + type: string + example: list + data: + type: array + items: + $ref: '#/components/schemas/VectorStoreObject' + first_id: + type: string + example: vs_abc123 + last_id: + type: string + example: vs_abc456 + has_more: + type: boolean + example: false + RunStepObjectLastError: + required: + - code + - message + type: object + properties: + code: + type: string + description: One of `server_error` or `rate_limit_exceeded` + enum: + - server_error + - rate_limit_exceeded + message: + type: string + description: A human-readable description of the error + description: The last error associated with this run step. Will be `null` if + there are no errors + nullable: true + RunStepDeltaStepDetailsToolCallsCodeObjectCodeInterpreter: + type: object + properties: + outputs: + type: array + description: "The outputs from the Code Interpreter tool call. Code Interpreter\ + \ can output one or more items, including text (`logs`) or images (`image`).\ + \ Each of these are represented by a different object type" + items: + $ref: '#/components/schemas/RunStepDeltaStepDetailsToolCallsCodeObjectCodeInterpreterOutputs' + input: + type: string + description: The input to the Code Interpreter tool call + description: The Code Interpreter tool call definition + RunStepDetailsToolCallsCodeObject: + title: Code Interpreter tool call + required: + - code_interpreter + - id + - type + type: object + properties: + code_interpreter: + allOf: + - $ref: '#/components/schemas/RunStepDetailsToolCallsCodeObjectCodeInterpreter' + x-ballerina-name: codeInterpreter + id: + type: string + description: The ID of the tool call + type: + type: string + description: The type of tool call. This is always going to be `code_interpreter` + for this type of tool call + enum: + - code_interpreter + description: Details of the Code Interpreter tool call the run step was involved + in + RunObjectTools: + oneOf: + - $ref: '#/components/schemas/AssistantToolsCode' + - $ref: '#/components/schemas/AssistantToolsFileSearch' + - $ref: '#/components/schemas/AssistantToolsFunction' + x-oaiExpandable: true + CreateModerationResponse: + required: + - id + - model + - results + type: object + properties: + model: + type: string + description: The model used to generate the moderation results + id: + type: string + description: The unique identifier for the moderation request + results: + type: array + description: A list of moderation objects + items: + $ref: '#/components/schemas/CreateModerationResponseResults' + description: Represents if a given text input is potentially harmful + x-oaiMeta: + name: The moderation object + example: | + { + "id": "modr-XXXXX", + "model": "text-moderation-005", + "results": [ + { + "flagged": true, + "categories": { + "sexual": false, + "hate": false, + "harassment": false, + "self-harm": false, + "sexual/minors": false, + "hate/threatening": false, + "violence/graphic": false, + "self-harm/intent": false, + "self-harm/instructions": false, + "harassment/threatening": true, + "violence": true, + }, + "category_scores": { + "sexual": 1.2282071e-06, + "hate": 0.010696256, + "harassment": 0.29842457, + "self-harm": 1.5236925e-08, + "sexual/minors": 5.7246268e-08, + "hate/threatening": 0.0060676364, + "violence/graphic": 4.435014e-06, + "self-harm/intent": 8.098441e-10, + "self-harm/instructions": 2.8498655e-11, + "harassment/threatening": 0.63055265, + "violence": 0.99011886, + } + } + ] + } + FineTuningIntegration: + title: Fine-Tuning Job Integration + required: + - type + - wandb + type: object + properties: + wandb: + $ref: '#/components/schemas/FineTuningIntegrationWandb' + type: + type: string + description: The type of the integration being enabled for the fine-tuning + job + enum: + - wandb + SubmitToolOutputsRunRequest: + required: + - tool_outputs + type: object + properties: + stream: + type: boolean + description: | + If `true`, returns a stream of events that happen during the Run as server-sent events, terminating when the Run enters a terminal state with a `data: [DONE]` message + nullable: true + tool_outputs: + type: array + description: A list of tools for which the outputs are being submitted + items: + $ref: '#/components/schemas/SubmitToolOutputsRunRequestToolOutputs' + x-ballerina-name: toolOutputs + additionalProperties: false + VectorStoreFileBatchObject: + title: Vector store file batch + required: + - created_at + - file_counts + - id + - object + - status + - vector_store_id + type: object + properties: + file_counts: + allOf: + - $ref: '#/components/schemas/VectorStoreFileBatchObjectFileCounts' + x-ballerina-name: fileCounts + created_at: + type: integer + description: The Unix timestamp (in seconds) for when the vector store files + batch was created + x-ballerina-name: createdAt + id: + type: string + description: "The identifier, which can be referenced in API endpoints" + object: + type: string + description: "The object type, which is always `vector_store.file_batch`" + enum: + - vector_store.files_batch + vector_store_id: + type: string + description: "The ID of the [vector store](/docs/api-reference/vector-stores/object)\ + \ that the [File](/docs/api-reference/files) is attached to" + x-ballerina-name: vectorStoreId + status: + type: string + description: "The status of the vector store files batch, which can be either\ + \ `in_progress`, `completed`, `cancelled` or `failed`" + enum: + - in_progress + - completed + - cancelled + - failed + description: A batch of files attached to a vector store + x-oaiMeta: + name: The vector store files batch object + beta: true + example: | + { + "id": "vsfb_123", + "object": "vector_store.files_batch", + "created_at": 1698107661, + "vector_store_id": "vs_abc123", + "status": "completed", + "file_counts": { + "in_progress": 0, + "completed": 100, + "failed": 0, + "cancelled": 0, + "total": 100 + } + } + MessageContentTextAnnotationsFilePathObjectFilePath: + required: + - file_id + type: object + properties: + file_id: + type: string + description: The ID of the file that was generated + x-ballerina-name: fileId + ModifyRunRequest: + type: object + properties: + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + additionalProperties: false + CreateThreadAndRunRequestToolResources: + type: object + properties: + code_interpreter: + allOf: + - $ref: '#/components/schemas/CreateThreadAndRunRequestToolResourcesCodeInterpreter' + x-ballerina-name: codeInterpreter + file_search: + allOf: + - $ref: '#/components/schemas/CreateThreadAndRunRequestToolResourcesFileSearch' + x-ballerina-name: fileSearch + description: | + A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs + nullable: true + ChatCompletionFunctionCallOption: + required: + - name + type: object + properties: + name: + type: string + description: The name of the function to call + description: | + Specifying a particular function via `{"name": "my_function"}` forces the model to call that function + FineTuningJob: + title: FineTuningJob + required: + - created_at + - error + - fine_tuned_model + - finished_at + - hyperparameters + - id + - model + - object + - organization_id + - result_files + - seed + - status + - trained_tokens + - training_file + - validation_file + type: object + properties: + training_file: + type: string + description: "The file ID used for training. You can retrieve the training\ + \ data with the [Files API](/docs/api-reference/files/retrieve-contents)" + x-ballerina-name: trainingFile + result_files: + type: array + description: "The compiled results file ID(s) for the fine-tuning job. You\ + \ can retrieve the results with the [Files API](/docs/api-reference/files/retrieve-contents)" + items: + type: string + example: file-abc123 + x-ballerina-name: resultFiles + finished_at: + type: integer + description: The Unix timestamp (in seconds) for when the fine-tuning job + was finished. The value will be null if the fine-tuning job is still running + nullable: true + x-ballerina-name: finishedAt + seed: + type: integer + description: The seed used for the fine-tuning job + fine_tuned_model: + type: string + description: The name of the fine-tuned model that is being created. The + value will be null if the fine-tuning job is still running + nullable: true + x-ballerina-name: fineTunedModel + validation_file: + type: string + description: "The file ID used for validation. You can retrieve the validation\ + \ results with the [Files API](/docs/api-reference/files/retrieve-contents)" + nullable: true + x-ballerina-name: validationFile + created_at: + type: integer + description: The Unix timestamp (in seconds) for when the fine-tuning job + was created + x-ballerina-name: createdAt + error: + $ref: '#/components/schemas/FineTuningJobError' + estimated_finish: + type: integer + description: The Unix timestamp (in seconds) for when the fine-tuning job + is estimated to finish. The value will be null if the fine-tuning job + is not running + nullable: true + x-ballerina-name: estimatedFinish + organization_id: + type: string + description: The organization that owns the fine-tuning job + x-ballerina-name: organizationId + hyperparameters: + $ref: '#/components/schemas/FineTuningJobHyperparameters' + model: + type: string + description: The base model that is being fine-tuned + id: + type: string + description: "The object identifier, which can be referenced in the API\ + \ endpoints" + trained_tokens: + type: integer + description: The total number of billable tokens processed by this fine-tuning + job. The value will be null if the fine-tuning job is still running + nullable: true + x-ballerina-name: trainedTokens + integrations: + maxItems: 5 + type: array + description: A list of integrations to enable for this fine-tuning job + nullable: true + items: + $ref: '#/components/schemas/FineTuningJobIntegrations' + object: + type: string + description: "The object type, which is always \"fine_tuning.job\"" + enum: + - fine_tuning.job + status: + type: string + description: "The current status of the fine-tuning job, which can be either\ + \ `validating_files`, `queued`, `running`, `succeeded`, `failed`, or `cancelled`" + enum: + - validating_files + - queued + - running + - succeeded + - failed + - cancelled + description: | + The `fine_tuning.job` object represents a fine-tuning job that has been created through the API + x-oaiMeta: + name: The fine-tuning job object + example: | + { + "object": "fine_tuning.job", + "id": "ftjob-abc123", + "model": "davinci-002", + "created_at": 1692661014, + "finished_at": 1692661190, + "fine_tuned_model": "ft:davinci-002:my-org:custom_suffix:7q8mpxmy", + "organization_id": "org-123", + "result_files": [ + "file-abc123" + ], + "status": "succeeded", + "validation_file": null, + "training_file": "file-abc123", + "hyperparameters": { + "n_epochs": 4, + "batch_size": 1, + "learning_rate_multiplier": 1.0 + }, + "trained_tokens": 5768, + "integrations": [], + "seed": 0, + "estimated_finish": 0 + } + RunStepDeltaStepDetailsToolCallsFunctionObjectFunction: + type: object + properties: + output: + type: string + description: "The output of the function. This will be `null` if the outputs\ + \ have not been [submitted](/docs/api-reference/runs/submitToolOutputs)\ + \ yet" + nullable: true + name: + type: string + description: The name of the function + arguments: + type: string + description: The arguments passed to the function + description: The definition of the function that was called + ChatCompletionRequestSystemMessage: + title: System message + required: + - content + - role + type: object + properties: + role: + type: string + description: "The role of the messages author, in this case `system`" + enum: + - system + name: + type: string + description: An optional name for the participant. Provides the model information + to differentiate between participants of the same role + content: + type: string + description: The contents of the system message + CreateTranslationResponseVerboseJson: + required: + - duration + - language + - text + type: object + properties: + duration: + type: string + description: The duration of the input audio + language: + type: string + description: The language of the output translation (always `english`) + text: + type: string + description: The translated text + segments: + type: array + description: Segments of the translated text and their corresponding details + items: + $ref: '#/components/schemas/TranscriptionSegment' + MessageContentTextObjectText: + required: + - annotations + - value + type: object + properties: + annotations: + type: array + items: + $ref: '#/components/schemas/MessageContentTextObjectTextAnnotations' + value: + type: string + description: The data that makes up the text + MessageObjectAttachments: + type: object + properties: + file_id: + type: string + description: The ID of the file to attach to the message + x-ballerina-name: fileId + tools: + type: array + description: The tools to add this file to + items: + $ref: '#/components/schemas/MessageObjectTools' + CreateChatCompletionImageResponse: + type: object + description: "Represents a streamed chunk of a chat completion response returned\ + \ by model, based on the provided input" + x-oaiMeta: + name: The chat completion chunk object + group: chat + example: | + { + "id": "chatcmpl-123", + "object": "chat.completion", + "created": 1677652288, + "model": "gpt-4o-mini", + "system_fingerprint": "fp_44709d6fcb", + "choices": [{ + "index": 0, + "message": { + "role": "assistant", + "content": "\n\nThis image shows a wooden boardwalk extending through a lush green marshland.", + }, + "logprobs": null, + "finish_reason": "stop" + }], + "usage": { + "prompt_tokens": 9, + "completion_tokens": 12, + "total_tokens": 21 + } + } + RunStreamEvent: + oneOf: + - $ref: '#/components/schemas/RunStreamEventOneOf1' + - $ref: '#/components/schemas/RunStreamEventRunStreamEventOneOf12' + - $ref: '#/components/schemas/RunStreamEventRunStreamEventRunStreamEventOneOf123' + - $ref: '#/components/schemas/RunStreamEventRunStreamEventRunStreamEventRunStreamEventOneOf1234' + - $ref: '#/components/schemas/RunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventOneOf12345' + - $ref: '#/components/schemas/RunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventOneOf123456' + - $ref: '#/components/schemas/RunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventOneOf1234567' + - $ref: '#/components/schemas/RunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventOneOf12345678' + - $ref: '#/components/schemas/RunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventOneOf123456789' + - $ref: '#/components/schemas/RunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventRunStreamEventOneOf12345678910' + CreateCompletionResponseLogprobs: + type: object + properties: + top_logprobs: + type: array + items: + type: object + additionalProperties: + type: number + x-ballerina-name: topLogprobs + token_logprobs: + type: array + items: + type: number + x-ballerina-name: tokenLogprobs + tokens: + type: array + items: + type: string + text_offset: + type: array + items: + type: integer + x-ballerina-name: textOffset + nullable: true + FineTuningJobIntegrations: + oneOf: + - $ref: '#/components/schemas/FineTuningIntegration' + x-oaiExpandable: true + DeleteFileResponse: + required: + - deleted + - id + - object + type: object + properties: + deleted: + type: boolean + id: + type: string + object: + type: string + enum: + - file + RunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventRunStepStreamEventOneOf123456: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunStepObject' + event: + type: string + enum: + - thread.run.step.cancelled + description: "Occurs when a [run step](/docs/api-reference/runs/step-object)\ + \ is cancelled" + x-oaiMeta: + dataDescription: "`data` is a [run step](/docs/api-reference/runs/step-object)" + ListFineTuningJobEventsResponse: + required: + - data + - object + type: object + properties: + data: + type: array + items: + $ref: '#/components/schemas/FineTuningJobEvent' + object: + type: string + enum: + - list + CreateMessageRequest: + required: + - content + - role + type: object + properties: + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + role: + type: string + description: | + The role of the entity that is creating the message. Allowed values include: + - `user`: Indicates the message is sent by an actual user and should be used in most cases to represent user-generated messages. + - `assistant`: Indicates the message is generated by the assistant. Use this value to insert messages from the assistant into the conversation + enum: + - user + - assistant + attachments: + required: + - file_id + - tools + type: array + description: "A list of files attached to the message, and the tools they\ + \ should be added to" + nullable: true + items: + $ref: '#/components/schemas/CreateMessageRequestAttachments' + content: + oneOf: + - title: Text content + type: string + description: The text contents of the message. + - title: Array of content parts + minItems: 1 + type: array + description: "An array of content parts with a defined type, each can\ + \ be of type `text` or images can be passed with `image_url` or `image_file`.\ + \ Image types are only supported on [Vision-compatible models](/docs/models/overview)." + items: + oneOf: + - $ref: '#/components/schemas/MessageContentImageFileObject' + - $ref: '#/components/schemas/MessageContentImageUrlObject' + - $ref: '#/components/schemas/MessageRequestContentTextObject' + x-oaiExpandable: true + x-oaiExpandable: true + additionalProperties: false + CreateAssistantRequestToolResourcesFileSearch: + type: object + properties: + vector_store_ids: + maxItems: 1 + type: array + description: | + The [vector store](/docs/api-reference/vector-stores/object) attached to this assistant. There can be a maximum of 1 vector store attached to the assistant. + items: + type: string + vector_stores: + maxItems: 1 + type: array + description: | + A helper to create a [vector store](/docs/api-reference/vector-stores/object) with file_ids and attach it to this assistant. There can be a maximum of 1 vector store attached to the assistant. + items: + $ref: '#/components/schemas/CreateAssistantRequestToolResourcesFileSearchVectorStores' + oneOf: + - required: + - vector_store_ids + - required: + - vector_stores + RunStepObject: + title: Run steps + required: + - assistant_id + - cancelled_at + - completed_at + - created_at + - expired_at + - failed_at + - id + - last_error + - metadata + - object + - run_id + - status + - step_details + - thread_id + - type + - usage + type: object + properties: + cancelled_at: + type: integer + description: The Unix timestamp (in seconds) for when the run step was cancelled + nullable: true + x-ballerina-name: cancelledAt + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + assistant_id: + type: string + description: "The ID of the [assistant](/docs/api-reference/assistants)\ + \ associated with the run step" + x-ballerina-name: assistantId + run_id: + type: string + description: "The ID of the [run](/docs/api-reference/runs) that this run\ + \ step is a part of" + x-ballerina-name: runId + usage: + $ref: '#/components/schemas/RunStepCompletionUsage' + created_at: + type: integer + description: The Unix timestamp (in seconds) for when the run step was created + x-ballerina-name: createdAt + expired_at: + type: integer + description: The Unix timestamp (in seconds) for when the run step expired. + A step is considered expired if the parent run is expired + nullable: true + x-ballerina-name: expiredAt + type: + type: string + description: "The type of run step, which can be either `message_creation`\ + \ or `tool_calls`" + enum: + - message_creation + - tool_calls + step_details: + type: object + description: The details of the run step + oneOf: + - $ref: '#/components/schemas/RunStepDetailsMessageCreationObject' + - $ref: '#/components/schemas/RunStepDetailsToolCallsObject' + x-oaiExpandable: true + x-ballerina-name: stepDetails + completed_at: + type: integer + description: The Unix timestamp (in seconds) for when the run step completed + nullable: true + x-ballerina-name: completedAt + thread_id: + type: string + description: "The ID of the [thread](/docs/api-reference/threads) that was\ + \ run" + x-ballerina-name: threadId + id: + type: string + description: "The identifier of the run step, which can be referenced in\ + \ API endpoints" + last_error: + allOf: + - $ref: '#/components/schemas/RunStepObjectLastError' + x-ballerina-name: lastError + failed_at: + type: integer + description: The Unix timestamp (in seconds) for when the run step failed + nullable: true + x-ballerina-name: failedAt + object: + type: string + description: "The object type, which is always `thread.run.step`" + enum: + - thread.run.step + status: + type: string + description: "The status of the run step, which can be either `in_progress`,\ + \ `cancelled`, `failed`, `completed`, or `expired`" + enum: + - in_progress + - cancelled + - failed + - completed + - expired + description: | + Represents a step in execution of a run + x-oaiMeta: + name: The run step object + beta: true + example: | + { + "id": "step_abc123", + "object": "thread.run.step", + "created_at": 1699063291, + "run_id": "run_abc123", + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "type": "message_creation", + "status": "completed", + "cancelled_at": null, + "completed_at": 1699063291, + "expired_at": null, + "failed_at": null, + "last_error": null, + "step_details": { + "type": "message_creation", + "message_creation": { + "message_id": "msg_abc123" + } + }, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + } + } + ChatCompletionNamedToolChoice: + required: + - function + - type + type: object + properties: + function: + $ref: '#/components/schemas/ChatCompletionNamedToolChoiceFunction' + type: + type: string + description: "The type of the tool. Currently, only `function` is supported" + enum: + - function + description: Specifies a tool the model should use. Use to force the model to + call a specific function + CreateModerationResponseResults: + required: + - categories + - category_scores + - flagged + type: object + properties: + category_scores: + allOf: + - $ref: '#/components/schemas/CreateModerationResponseCategoryScores' + x-ballerina-name: categoryScores + flagged: + type: boolean + description: Whether any of the below categories are flagged + categories: + $ref: '#/components/schemas/CreateModerationResponseCategories' + MessageObjectContent: + oneOf: + - $ref: '#/components/schemas/MessageContentImageFileObject' + - $ref: '#/components/schemas/MessageContentImageUrlObject' + - $ref: '#/components/schemas/MessageContentTextObject' + x-oaiExpandable: true + MessageDeltaContentImageFileObject: + title: Image file + required: + - index + - type + type: object + properties: + index: + type: integer + description: The index of the content part in the message + image_file: + allOf: + - $ref: '#/components/schemas/MessageDeltaContentImageFileObjectImageFile' + x-ballerina-name: imageFile + type: + type: string + description: Always `image_file` + enum: + - image_file + description: "References an image [File](/docs/api-reference/files) in the content\ + \ of a message" + InlineResponse200: + oneOf: + - $ref: '#/components/schemas/CreateTranscriptionResponseJson' + - $ref: '#/components/schemas/CreateTranscriptionResponseVerboseJson' + RunStepDetailsToolCallsFunctionObjectFunction: + required: + - arguments + - name + - output + type: object + properties: + output: + type: string + description: "The output of the function. This will be `null` if the outputs\ + \ have not been [submitted](/docs/api-reference/runs/submitToolOutputs)\ + \ yet" + nullable: true + name: + type: string + description: The name of the function + arguments: + type: string + description: The arguments passed to the function + description: The definition of the function that was called + RunStepDeltaStepDetailsToolCallsCodeObject: + title: Code interpreter tool call + required: + - index + - type + type: object + properties: + code_interpreter: + allOf: + - $ref: '#/components/schemas/RunStepDeltaStepDetailsToolCallsCodeObjectCodeInterpreter' + x-ballerina-name: codeInterpreter + index: + type: integer + description: The index of the tool call in the tool calls array + id: + type: string + description: The ID of the tool call + type: + type: string + description: The type of tool call. This is always going to be `code_interpreter` + for this type of tool call + enum: + - code_interpreter + description: Details of the Code Interpreter tool call the run step was involved + in + FunctionObject: + required: + - name + type: object + properties: + name: + type: string + description: "The name of the function to be called. Must be a-z, A-Z, 0-9,\ + \ or contain underscores and dashes, with a maximum length of 64" + description: + type: string + description: "A description of what the function does, used by the model\ + \ to choose when and how to call the function" + parameters: + $ref: '#/components/schemas/FunctionParameters' + CreateChatCompletionStreamResponseLogprobs: + required: + - content + type: object + properties: + content: + type: array + description: A list of message content tokens with log probability information + nullable: true + items: + $ref: '#/components/schemas/ChatCompletionTokenLogprob' + description: Log probability information for the choice + nullable: true + CreateAssistantRequestToolResources: + type: object + properties: + code_interpreter: + allOf: + - $ref: '#/components/schemas/CreateAssistantRequestToolResourcesCodeInterpreter' + x-ballerina-name: codeInterpreter + file_search: + allOf: + - $ref: '#/components/schemas/CreateAssistantRequestToolResourcesFileSearch' + x-ballerina-name: fileSearch + description: | + A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs + nullable: true + CreateAssistantRequest: + required: + - model + type: object + properties: + top_p: + maximum: 1 + minimum: 0 + type: number + description: | + An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + + We generally recommend altering this or temperature but not both + nullable: true + example: 1 + default: 1 + x-ballerina-name: topP + instructions: + maxLength: 256000 + type: string + description: | + The system instructions that the assistant uses. The maximum length is 256,000 characters + nullable: true + tool_resources: + allOf: + - $ref: '#/components/schemas/CreateAssistantRequestToolResources' + x-ballerina-name: toolResources + metadata: + type: object + description: | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long + nullable: true + x-oaiTypeLabel: map + response_format: + allOf: + - $ref: '#/components/schemas/AssistantsApiResponseFormatOption' + x-ballerina-name: responseFormat + name: + maxLength: 256 + type: string + description: | + The name of the assistant. The maximum length is 256 characters + nullable: true + temperature: + maximum: 2 + minimum: 0 + type: number + description: | + What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic + nullable: true + example: 1 + default: 1 + description: + maxLength: 512 + type: string + description: | + The description of the assistant. The maximum length is 512 characters + nullable: true + model: + description: | + ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](/docs/models/overview) for descriptions of them + example: gpt-4-turbo + anyOf: + - type: string + - type: string + enum: + - gpt-4o + - gpt-4o-2024-05-13 + - gpt-4o-mini + - gpt-4o-mini-2024-07-18 + - gpt-4-turbo + - gpt-4-turbo-2024-04-09 + - gpt-4-0125-preview + - gpt-4-turbo-preview + - gpt-4-1106-preview + - gpt-4-vision-preview + - gpt-4 + - gpt-4-0314 + - gpt-4-0613 + - gpt-4-32k + - gpt-4-32k-0314 + - gpt-4-32k-0613 + - gpt-3.5-turbo + - gpt-3.5-turbo-16k + - gpt-3.5-turbo-0613 + - gpt-3.5-turbo-1106 + - gpt-3.5-turbo-0125 + - gpt-3.5-turbo-16k-0613 + x-oaiTypeLabel: string + tools: + maxItems: 128 + type: array + description: | + A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `file_search`, or `function` + items: + $ref: '#/components/schemas/CreateAssistantRequestTools' + default: [] + additionalProperties: false + DeleteVectorStoreResponse: + required: + - deleted + - id + - object + type: object + properties: + deleted: + type: boolean + id: + type: string + object: + type: string + enum: + - vector_store.deleted + DeleteAssistantResponse: + required: + - deleted + - id + - object + type: object + properties: + deleted: + type: boolean + id: + type: string + object: + type: string + enum: + - assistant.deleted + CreateAssistantRequestToolResourcesCodeInterpreter: + type: object + properties: + file_ids: + maxItems: 20 + type: array + description: | + A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool + items: + type: string + default: [] + x-ballerina-name: fileIds + ThreadStreamEventOneOf1: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/ThreadObject' + event: + type: string + enum: + - thread.created + description: "Occurs when a new [thread](/docs/api-reference/threads/object)\ + \ is created" + x-oaiMeta: + dataDescription: "`data` is a [thread](/docs/api-reference/threads/object)" + RunStepDetailsToolCallsFileSearchObject: + title: File search tool call + required: + - file_search + - id + - type + type: object + properties: + file_search: + type: object + description: "For now, this is always going to be an empty object" + x-oaiTypeLabel: map + x-ballerina-name: fileSearch + id: + type: string + description: The ID of the tool call object + type: + type: string + description: The type of tool call. This is always going to be `file_search` + for this type of tool call + enum: + - file_search + UploadPart: + title: UploadPart + required: + - created_at + - id + - object + - upload_id + type: object + properties: + upload_id: + type: string + description: The ID of the Upload object that this Part was added to + x-ballerina-name: uploadId + created_at: + type: integer + description: The Unix timestamp (in seconds) for when the Part was created + x-ballerina-name: createdAt + id: + type: string + description: "The upload Part unique identifier, which can be referenced\ + \ in API endpoints" + object: + type: string + description: "The object type, which is always `upload.part`" + enum: + - upload.part + description: | + The upload Part represents a chunk of bytes we can add to an Upload object + x-oaiMeta: + name: The upload part object + example: | + { + "id": "part_def456", + "object": "upload.part", + "created_at": 1719186911, + "upload_id": "upload_abc123" + } + RunStreamEventRunStreamEventRunStreamEventRunStreamEventOneOf1234: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/RunObject' + event: + type: string + enum: + - thread.run.requires_action + description: "Occurs when a [run](/docs/api-reference/runs/object) moves to\ + \ a `requires_action` status" + x-oaiMeta: + dataDescription: "`data` is a [run](/docs/api-reference/runs/object)" + CreateChatCompletionResponse: + required: + - choices + - created + - id + - model + - object + type: object + properties: + created: + type: integer + description: The Unix timestamp (in seconds) of when the chat completion + was created + usage: + $ref: '#/components/schemas/CompletionUsage' + model: + type: string + description: The model used for the chat completion + service_tier: + type: string + description: The service tier used for processing the request. This field + is only included if the `service_tier` parameter is specified in the request + nullable: true + example: scale + enum: + - scale + - default + x-ballerina-name: serviceTier + id: + type: string + description: A unique identifier for the chat completion + choices: + type: array + description: A list of chat completion choices. Can be more than one if + `n` is greater than 1 + items: + $ref: '#/components/schemas/CreateChatCompletionResponseChoices' + system_fingerprint: + type: string + description: | + This fingerprint represents the backend configuration that the model runs with. + + Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism + x-ballerina-name: systemFingerprint + object: + type: string + description: "The object type, which is always `chat.completion`" + enum: + - chat.completion + description: "Represents a chat completion response returned by model, based\ + \ on the provided input" + x-oaiMeta: + name: The chat completion object + group: chat + example: | + { + "id": "chatcmpl-123", + "object": "chat.completion", + "created": 1677652288, + "model": "gpt-4o-mini", + "system_fingerprint": "fp_44709d6fcb", + "choices": [{ + "index": 0, + "message": { + "role": "assistant", + "content": "\n\nHello there, how may I assist you today?", + }, + "logprobs": null, + "finish_reason": "stop" + }], + "usage": { + "prompt_tokens": 9, + "completion_tokens": 12, + "total_tokens": 21 + } + } + Error: + required: + - code + - message + - param + - type + type: object + properties: + code: + type: string + nullable: true + param: + type: string + nullable: true + message: + type: string + nullable: false + type: + type: string + nullable: false + ChatCompletionRequestAssistantMessageFunctionCall: + required: + - arguments + - name + type: object + properties: + name: + type: string + description: The name of the function to call + arguments: + type: string + description: "The arguments to call the function with, as generated by the\ + \ model in JSON format. Note that the model does not always generate valid\ + \ JSON, and may hallucinate parameters not defined by your function schema.\ + \ Validate the arguments in your code before calling your function" + description: "Deprecated and replaced by `tool_calls`. The name and arguments\ + \ of a function that should be called, as generated by the model" + nullable: true + deprecated: true + ChatCompletionRequestToolMessage: + title: Tool message + required: + - content + - role + - tool_call_id + type: object + properties: + role: + type: string + description: "The role of the messages author, in this case `tool`" + enum: + - tool + tool_call_id: + type: string + description: Tool call that this message is responding to + x-ballerina-name: toolCallId + content: + type: string + description: The contents of the tool message + CreateTranslationResponseJson: + required: + - text + type: object + properties: + text: + type: string + ChatCompletionRequestMessageContentPartImageImageUrl: + required: + - url + type: object + properties: + detail: + type: string + description: "Specifies the detail level of the image. Learn more in the\ + \ [Vision guide](/docs/guides/vision/low-or-high-fidelity-image-understanding)" + default: auto + enum: + - auto + - low + - high + url: + type: string + description: Either a URL of the image or the base64 encoded image data + format: uri + CreateImageVariationRequest: + required: + - image + type: object + properties: + image: + type: string + description: "The image to use as the basis for the variation(s). Must be\ + \ a valid PNG file, less than 4MB, and square" + format: binary + response_format: + type: string + description: The format in which the generated images are returned. Must + be one of `url` or `b64_json`. URLs are only valid for 60 minutes after + the image has been generated + nullable: true + example: url + default: url + enum: + - url + - b64_json + x-ballerina-name: responseFormat + size: + type: string + description: "The size of the generated images. Must be one of `256x256`,\ + \ `512x512`, or `1024x1024`" + nullable: true + example: 1024x1024 + default: 1024x1024 + enum: + - 256x256 + - 512x512 + - 1024x1024 + model: + description: The model to use for image generation. Only `dall-e-2` is supported + at this time + nullable: true + example: dall-e-2 + anyOf: + - type: string + - type: string + enum: + - dall-e-2 + default: dall-e-2 + x-oaiTypeLabel: string + user: + type: string + description: | + A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids) + example: user-1234 + "n": + maximum: 10 + minimum: 1 + type: integer + description: "The number of images to generate. Must be between 1 and 10.\ + \ For `dall-e-3`, only `n=1` is supported" + nullable: true + example: 1 + default: 1 + MessageStreamEventOneOf1: + required: + - data + - event + type: object + properties: + data: + $ref: '#/components/schemas/MessageObject' + event: + type: string + enum: + - thread.message.created + description: "Occurs when a [message](/docs/api-reference/messages/object) is\ + \ created" + x-oaiMeta: + dataDescription: "`data` is a [message](/docs/api-reference/messages/object)" + ChatCompletionResponseMessage: + required: + - content + - role + type: object + properties: + role: + type: string + description: The role of the author of this message + enum: + - assistant + function_call: + allOf: + - $ref: '#/components/schemas/ChatCompletionResponseMessageFunctionCall' + x-ballerina-name: functionCall + tool_calls: + allOf: + - $ref: '#/components/schemas/ChatCompletionMessageToolCalls' + x-ballerina-name: toolCalls + content: + type: string + description: The contents of the message + nullable: true + description: A chat completion message generated by the model + DeleteThreadResponse: + required: + - deleted + - id + - object + type: object + properties: + deleted: + type: boolean + id: + type: string + object: + type: string + enum: + - thread.deleted + BatchRequestOutput: + type: object + properties: + response: + $ref: '#/components/schemas/BatchRequestOutputResponse' + custom_id: + type: string + description: A developer-provided per-request id that will be used to match + outputs to inputs + x-ballerina-name: customId + id: + type: string + error: + $ref: '#/components/schemas/BatchRequestOutputError' + description: The per-line object of the batch output and error files + x-oaiMeta: + name: The request output object + example: | + {"id": "batch_req_wnaDys", "custom_id": "request-2", "response": {"status_code": 200, "request_id": "req_c187b3", "body": {"id": "chatcmpl-9758Iw", "object": "chat.completion", "created": 1711475054, "model": "gpt-3.5-turbo", "choices": [{"index": 0, "message": {"role": "assistant", "content": "2 + 2 equals 4."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 24, "completion_tokens": 15, "total_tokens": 39}, "system_fingerprint": null}}, "error": null} + RunStepDetailsToolCallsCodeOutputLogsObject: + title: Code Interpreter log output + required: + - logs + - type + type: object + properties: + type: + type: string + description: Always `logs` + enum: + - logs + logs: + type: string + description: The text output from the Code Interpreter tool call + description: Text output from the Code Interpreter tool call as part of a run + step + StaticChunkingStrategyResponseParam: + title: Static Chunking Strategy + required: + - static + - type + type: object + properties: + static: + $ref: '#/components/schemas/StaticChunkingStrategy' + type: + type: string + description: Always `static` + enum: + - static + additionalProperties: false + MessageObjectTools: + oneOf: + - $ref: '#/components/schemas/AssistantToolsCode' + - $ref: '#/components/schemas/AssistantToolsFileSearchTypeOnly' + x-oaiExpandable: true + RunStepDetailsMessageCreationObject: + title: Message creation + required: + - message_creation + - type + type: object + properties: + message_creation: + allOf: + - $ref: '#/components/schemas/RunStepDetailsMessageCreationObjectMessageCreation' + x-ballerina-name: messageCreation + type: + type: string + description: Always `message_creation` + enum: + - message_creation + description: Details of the message creation by the run step + ThreadObjectToolResourcesCodeInterpreter: + type: object + properties: + file_ids: + maxItems: 20 + type: array + description: | + A list of [file](/docs/api-reference/files) IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool + items: + type: string + default: [] + x-ballerina-name: fileIds + MessageContentImageFileObjectImageFile: + required: + - file_id + type: object + properties: + file_id: + type: string + description: "The [File](/docs/api-reference/files) ID of the image in the\ + \ message content. Set `purpose=\"vision\"` when uploading the File if\ + \ you need to later display the file content" + x-ballerina-name: fileId + detail: + type: string + description: "Specifies the detail level of the image if specified by the\ + \ user. `low` uses fewer tokens, you can opt in to high resolution using\ + \ `high`" + default: auto + enum: + - auto + - low + - high + securitySchemes: + ApiKeyAuth: + type: http + scheme: bearer x-oaiMeta: - navigationGroups: - - id: endpoints - title: Endpoints - - id: assistants - title: Assistants - - id: legacy - title: Legacy - groups: - # > General Notes - # The `groups` section is used to generate the API reference pages and navigation, in the same - # order listed below. Additionally, each `group` can have a list of `sections`, each of which - # will become a navigation subroute and subsection under the group. Each section has: - # - `type`: Currently, either an `endpoint` or `object`, depending on how the section needs to - # be rendered - # - `key`: The reference key that can be used to lookup the section definition - # - `path`: The path (url) of the section, which is used to generate the navigation link. - # - # > The `object` sections maps to a schema component and the following fields are read for rendering - # - `x-oaiMeta.name`: The name of the object, which will become the section title - # - `x-oaiMeta.example`: The example object, which will be used to generate the example sample (always JSON) - # - `description`: The description of the object, which will be used to generate the section description - # - # > The `endpoint` section maps to an operation path and the following fields are read for rendering: - # - `x-oaiMeta.name`: The name of the endpoint, which will become the section title - # - `x-oaiMeta.examples`: The endpoint examples, which can be an object (meaning a single variation, most - # endpoints, or an array of objects, meaning multiple variations, e.g. the - # chat completion and completion endpoints, with streamed and non-streamed examples. - # - `x-oaiMeta.returns`: text describing what the endpoint returns. - # - `summary`: The summary of the endpoint, which will be used to generate the section description - - id: audio - title: Audio - description: | - Learn how to turn audio into text or text into audio. - - Related guide: [Speech to text](/docs/guides/speech-to-text) - navigationGroup: endpoints - sections: - - type: endpoint - key: createSpeech - path: createSpeech - - type: endpoint - key: createTranscription - path: createTranscription - - type: endpoint - key: createTranslation - path: createTranslation - - type: object - key: CreateTranscriptionResponseJson - path: json-object - - type: object - key: CreateTranscriptionResponseVerboseJson - path: verbose-json-object - - id: chat - title: Chat - description: | - Given a list of messages comprising a conversation, the model will return a response. - - Related guide: [Chat Completions](/docs/guides/text-generation) - navigationGroup: endpoints - sections: - - type: endpoint - key: createChatCompletion - path: create - - type: object - key: CreateChatCompletionResponse - path: object - - type: object - key: CreateChatCompletionStreamResponse - path: streaming - - id: embeddings - title: Embeddings - description: | - Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms. - - Related guide: [Embeddings](/docs/guides/embeddings) - navigationGroup: endpoints - sections: - - type: endpoint - key: createEmbedding - path: create - - type: object - key: Embedding - path: object - - id: fine-tuning - title: Fine-tuning - description: | - Manage fine-tuning jobs to tailor a model to your specific training data. - - Related guide: [Fine-tune models](/docs/guides/fine-tuning) - navigationGroup: endpoints - sections: - - type: endpoint - key: createFineTuningJob - path: create - - type: endpoint - key: listPaginatedFineTuningJobs - path: list - - type: endpoint - key: listFineTuningEvents - path: list-events - - type: endpoint - key: listFineTuningJobCheckpoints - path: list-checkpoints - - type: endpoint - key: retrieveFineTuningJob - path: retrieve - - type: endpoint - key: cancelFineTuningJob - path: cancel - - type: object - key: FinetuneChatRequestInput - path: chat-input - - type: object - key: FinetuneCompletionRequestInput - path: completions-input - - type: object - key: FineTuningJob - path: object - - type: object - key: FineTuningJobEvent - path: event-object - - type: object - key: FineTuningJobCheckpoint - path: checkpoint-object - - id: batch - title: Batch - description: | - Create large batches of API requests for asynchronous processing. The Batch API returns completions within 24 hours for a 50% discount. - - Related guide: [Batch](/docs/guides/batch) - navigationGroup: endpoints - sections: - - type: endpoint - key: createBatch - path: create - - type: endpoint - key: retrieveBatch - path: retrieve - - type: endpoint - key: cancelBatch - path: cancel - - type: endpoint - key: listBatches - path: list - - type: object - key: Batch - path: object - - type: object - key: BatchRequestInput - path: request-input - - type: object - key: BatchRequestOutput - path: request-output - - id: files - title: Files - description: | - Files are used to upload documents that can be used with features like [Assistants](/docs/api-reference/assistants), [Fine-tuning](/docs/api-reference/fine-tuning), and [Batch API](/docs/guides/batch). - navigationGroup: endpoints - sections: - - type: endpoint - key: createFile - path: create - - type: endpoint - key: listFiles - path: list - - type: endpoint - key: retrieveFile - path: retrieve - - type: endpoint - key: deleteFile - path: delete - - type: endpoint - key: downloadFile - path: retrieve-contents - - type: object - key: OpenAIFile - path: object - - id: uploads - title: Uploads - description: | - Allows you to upload large files in multiple parts. - navigationGroup: endpoints - sections: - - type: endpoint - key: createUpload - path: create - - type: endpoint - key: addUploadPart - path: add-part - - type: endpoint - key: completeUpload - path: complete - - type: endpoint - key: cancelUpload - path: cancel - - type: object - key: Upload - path: object - - type: object - key: UploadPart - path: part-object - - id: images - title: Images - description: | - Given a prompt and/or an input image, the model will generate a new image. - - Related guide: [Image generation](/docs/guides/images) - navigationGroup: endpoints - sections: - - type: endpoint - key: createImage - path: create - - type: endpoint - key: createImageEdit - path: createEdit - - type: endpoint - key: createImageVariation - path: createVariation - - type: object - key: Image - path: object - - id: models - title: Models - description: | - List and describe the various models available in the API. You can refer to the [Models](/docs/models) documentation to understand what models are available and the differences between them. - navigationGroup: endpoints - sections: - - type: endpoint - key: listModels - path: list - - type: endpoint - key: retrieveModel - path: retrieve - - type: endpoint - key: deleteModel - path: delete - - type: object - key: Model - path: object - - id: moderations - title: Moderations - description: | - Given some input text, outputs if the model classifies it as potentially harmful across several categories. - - Related guide: [Moderations](/docs/guides/moderation) - navigationGroup: endpoints - sections: - - type: endpoint - key: createModeration - path: create - - type: object - key: CreateModerationResponse - path: object - - id: assistants - title: Assistants - beta: true - description: | - Build assistants that can call models and use tools to perform tasks. - - [Get started with the Assistants API](/docs/assistants) - navigationGroup: assistants - sections: - - type: endpoint - key: createAssistant - path: createAssistant - - type: endpoint - key: listAssistants - path: listAssistants - - type: endpoint - key: getAssistant - path: getAssistant - - type: endpoint - key: modifyAssistant - path: modifyAssistant - - type: endpoint - key: deleteAssistant - path: deleteAssistant - - type: object - key: AssistantObject - path: object - - id: threads - title: Threads - beta: true - description: | - Create threads that assistants can interact with. - - Related guide: [Assistants](/docs/assistants/overview) - navigationGroup: assistants - sections: - - type: endpoint - key: createThread - path: createThread - - type: endpoint - key: getThread - path: getThread - - type: endpoint - key: modifyThread - path: modifyThread - - type: endpoint - key: deleteThread - path: deleteThread - - type: object - key: ThreadObject - path: object - - id: messages - title: Messages - beta: true - description: | - Create messages within threads - - Related guide: [Assistants](/docs/assistants/overview) - navigationGroup: assistants - sections: - - type: endpoint - key: createMessage - path: createMessage - - type: endpoint - key: listMessages - path: listMessages - - type: endpoint - key: getMessage - path: getMessage - - type: endpoint - key: modifyMessage - path: modifyMessage - - type: endpoint - key: deleteMessage - path: deleteMessage - - type: object - key: MessageObject - path: object - - id: runs - title: Runs - beta: true - description: | - Represents an execution run on a thread. - - Related guide: [Assistants](/docs/assistants/overview) - navigationGroup: assistants - sections: - - type: endpoint - key: createRun - path: createRun - - type: endpoint - key: createThreadAndRun - path: createThreadAndRun - - type: endpoint - key: listRuns - path: listRuns - - type: endpoint - key: getRun - path: getRun - - type: endpoint - key: modifyRun - path: modifyRun - - type: endpoint - key: submitToolOuputsToRun - path: submitToolOutputs - - type: endpoint - key: cancelRun - path: cancelRun - - type: object - key: RunObject - path: object - - id: run-steps - title: Run Steps - beta: true - description: | - Represents the steps (model and tool calls) taken during the run. - - Related guide: [Assistants](/docs/assistants/overview) - navigationGroup: assistants - sections: - - type: endpoint - key: listRunSteps - path: listRunSteps - - type: endpoint - key: getRunStep - path: getRunStep - - type: object - key: RunStepObject - path: step-object - - id: vector-stores - title: Vector Stores - beta: true - description: | - Vector stores are used to store files for use by the `file_search` tool. - - Related guide: [File Search](/docs/assistants/tools/file-search) - navigationGroup: assistants - sections: - - type: endpoint - key: createVectorStore - path: create - - type: endpoint - key: listVectorStores - path: list - - type: endpoint - key: getVectorStore - path: retrieve - - type: endpoint - key: modifyVectorStore - path: modify - - type: endpoint - key: deleteVectorStore - path: delete - - type: object - key: VectorStoreObject - path: object - - id: vector-stores-files - title: Vector Store Files - beta: true - description: | - Vector store files represent files inside a vector store. - - Related guide: [File Search](/docs/assistants/tools/file-search) - navigationGroup: assistants - sections: - - type: endpoint - key: createVectorStoreFile - path: createFile - - type: endpoint - key: listVectorStoreFiles - path: listFiles - - type: endpoint - key: getVectorStoreFile - path: getFile - - type: endpoint - key: deleteVectorStoreFile - path: deleteFile - - type: object - key: VectorStoreFileObject - path: file-object - - id: vector-stores-file-batches - title: Vector Store File Batches - beta: true - description: | - Vector store file batches represent operations to add multiple files to a vector store. - - Related guide: [File Search](/docs/assistants/tools/file-search) - navigationGroup: assistants - sections: - - type: endpoint - key: createVectorStoreFileBatch - path: createBatch - - type: endpoint - key: getVectorStoreFileBatch - path: getBatch - - type: endpoint - key: cancelVectorStoreFileBatch - path: cancelBatch - - type: endpoint - key: listFilesInVectorStoreBatch - path: listBatchFiles - - type: object - key: VectorStoreFileBatchObject - path: batch-object - - id: assistants-streaming - title: Streaming - beta: true - description: | - Stream the result of executing a Run or resuming a Run after submitting tool outputs. - - You can stream events from the [Create Thread and Run](/docs/api-reference/runs/createThreadAndRun), - [Create Run](/docs/api-reference/runs/createRun), and [Submit Tool Outputs](/docs/api-reference/runs/submitToolOutputs) - endpoints by passing `"stream": true`. The response will be a [Server-Sent events](https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events) stream. - - Our Node and Python SDKs provide helpful utilities to make streaming easy. Reference the - [Assistants API quickstart](/docs/assistants/overview) to learn more. - navigationGroup: assistants - sections: - - type: object - key: MessageDeltaObject - path: message-delta-object - - type: object - key: RunStepDeltaObject - path: run-step-delta-object - - type: object - key: AssistantStreamEvent - path: events - - id: completions - title: Completions - legacy: true - navigationGroup: legacy - description: | - Given a prompt, the model will return one or more predicted completions along with the probabilities of alternative tokens at each position. Most developer should use our [Chat Completions API](/docs/guides/text-generation/text-generation-models) to leverage our best and newest models. - sections: - - type: endpoint - key: createCompletion - path: create - - type: object - key: CreateCompletionResponse - path: object \ No newline at end of file + navigationGroups: + - id: endpoints + title: Endpoints + - id: assistants + title: Assistants + - id: legacy + title: Legacy + groups: + - id: audio + title: Audio + description: | + Learn how to turn audio into text or text into audio. + + Related guide: [Speech to text](/docs/guides/speech-to-text) + navigationGroup: endpoints + sections: + - type: endpoint + key: createSpeech + path: createSpeech + - type: endpoint + key: createTranscription + path: createTranscription + - type: endpoint + key: createTranslation + path: createTranslation + - type: object + key: CreateTranscriptionResponseJson + path: json-object + - type: object + key: CreateTranscriptionResponseVerboseJson + path: verbose-json-object + - id: chat + title: Chat + description: | + Given a list of messages comprising a conversation, the model will return a response. + + Related guide: [Chat Completions](/docs/guides/text-generation) + navigationGroup: endpoints + sections: + - type: endpoint + key: createChatCompletion + path: create + - type: object + key: CreateChatCompletionResponse + path: object + - type: object + key: CreateChatCompletionStreamResponse + path: streaming + - id: embeddings + title: Embeddings + description: | + Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms. + + Related guide: [Embeddings](/docs/guides/embeddings) + navigationGroup: endpoints + sections: + - type: endpoint + key: createEmbedding + path: create + - type: object + key: Embedding + path: object + - id: fine-tuning + title: Fine-tuning + description: | + Manage fine-tuning jobs to tailor a model to your specific training data. + + Related guide: [Fine-tune models](/docs/guides/fine-tuning) + navigationGroup: endpoints + sections: + - type: endpoint + key: createFineTuningJob + path: create + - type: endpoint + key: listPaginatedFineTuningJobs + path: list + - type: endpoint + key: listFineTuningEvents + path: list-events + - type: endpoint + key: listFineTuningJobCheckpoints + path: list-checkpoints + - type: endpoint + key: retrieveFineTuningJob + path: retrieve + - type: endpoint + key: cancelFineTuningJob + path: cancel + - type: object + key: FinetuneChatRequestInput + path: chat-input + - type: object + key: FinetuneCompletionRequestInput + path: completions-input + - type: object + key: FineTuningJob + path: object + - type: object + key: FineTuningJobEvent + path: event-object + - type: object + key: FineTuningJobCheckpoint + path: checkpoint-object + - id: batch + title: Batch + description: | + Create large batches of API requests for asynchronous processing. The Batch API returns completions within 24 hours for a 50% discount. + + Related guide: [Batch](/docs/guides/batch) + navigationGroup: endpoints + sections: + - type: endpoint + key: createBatch + path: create + - type: endpoint + key: retrieveBatch + path: retrieve + - type: endpoint + key: cancelBatch + path: cancel + - type: endpoint + key: listBatches + path: list + - type: object + key: Batch + path: object + - type: object + key: BatchRequestInput + path: request-input + - type: object + key: BatchRequestOutput + path: request-output + - id: files + title: Files + description: | + Files are used to upload documents that can be used with features like [Assistants](/docs/api-reference/assistants), [Fine-tuning](/docs/api-reference/fine-tuning), and [Batch API](/docs/guides/batch). + navigationGroup: endpoints + sections: + - type: endpoint + key: createFile + path: create + - type: endpoint + key: listFiles + path: list + - type: endpoint + key: retrieveFile + path: retrieve + - type: endpoint + key: deleteFile + path: delete + - type: endpoint + key: downloadFile + path: retrieve-contents + - type: object + key: OpenAIFile + path: object + - id: uploads + title: Uploads + description: | + Allows you to upload large files in multiple parts. + navigationGroup: endpoints + sections: + - type: endpoint + key: createUpload + path: create + - type: endpoint + key: addUploadPart + path: add-part + - type: endpoint + key: completeUpload + path: complete + - type: endpoint + key: cancelUpload + path: cancel + - type: object + key: Upload + path: object + - type: object + key: UploadPart + path: part-object + - id: images + title: Images + description: | + Given a prompt and/or an input image, the model will generate a new image. + + Related guide: [Image generation](/docs/guides/images) + navigationGroup: endpoints + sections: + - type: endpoint + key: createImage + path: create + - type: endpoint + key: createImageEdit + path: createEdit + - type: endpoint + key: createImageVariation + path: createVariation + - type: object + key: Image + path: object + - id: models + title: Models + description: | + List and describe the various models available in the API. You can refer to the [Models](/docs/models) documentation to understand what models are available and the differences between them. + navigationGroup: endpoints + sections: + - type: endpoint + key: listModels + path: list + - type: endpoint + key: retrieveModel + path: retrieve + - type: endpoint + key: deleteModel + path: delete + - type: object + key: Model + path: object + - id: moderations + title: Moderations + description: | + Given some input text, outputs if the model classifies it as potentially harmful across several categories. + + Related guide: [Moderations](/docs/guides/moderation) + navigationGroup: endpoints + sections: + - type: endpoint + key: createModeration + path: create + - type: object + key: CreateModerationResponse + path: object + - id: assistants + title: Assistants + beta: true + description: | + Build assistants that can call models and use tools to perform tasks. + + [Get started with the Assistants API](/docs/assistants) + navigationGroup: assistants + sections: + - type: endpoint + key: createAssistant + path: createAssistant + - type: endpoint + key: listAssistants + path: listAssistants + - type: endpoint + key: getAssistant + path: getAssistant + - type: endpoint + key: modifyAssistant + path: modifyAssistant + - type: endpoint + key: deleteAssistant + path: deleteAssistant + - type: object + key: AssistantObject + path: object + - id: threads + title: Threads + beta: true + description: | + Create threads that assistants can interact with. + + Related guide: [Assistants](/docs/assistants/overview) + navigationGroup: assistants + sections: + - type: endpoint + key: createThread + path: createThread + - type: endpoint + key: getThread + path: getThread + - type: endpoint + key: modifyThread + path: modifyThread + - type: endpoint + key: deleteThread + path: deleteThread + - type: object + key: ThreadObject + path: object + - id: messages + title: Messages + beta: true + description: | + Create messages within threads + + Related guide: [Assistants](/docs/assistants/overview) + navigationGroup: assistants + sections: + - type: endpoint + key: createMessage + path: createMessage + - type: endpoint + key: listMessages + path: listMessages + - type: endpoint + key: getMessage + path: getMessage + - type: endpoint + key: modifyMessage + path: modifyMessage + - type: endpoint + key: deleteMessage + path: deleteMessage + - type: object + key: MessageObject + path: object + - id: runs + title: Runs + beta: true + description: | + Represents an execution run on a thread. + + Related guide: [Assistants](/docs/assistants/overview) + navigationGroup: assistants + sections: + - type: endpoint + key: createRun + path: createRun + - type: endpoint + key: createThreadAndRun + path: createThreadAndRun + - type: endpoint + key: listRuns + path: listRuns + - type: endpoint + key: getRun + path: getRun + - type: endpoint + key: modifyRun + path: modifyRun + - type: endpoint + key: submitToolOuputsToRun + path: submitToolOutputs + - type: endpoint + key: cancelRun + path: cancelRun + - type: object + key: RunObject + path: object + - id: run-steps + title: Run Steps + beta: true + description: | + Represents the steps (model and tool calls) taken during the run. + + Related guide: [Assistants](/docs/assistants/overview) + navigationGroup: assistants + sections: + - type: endpoint + key: listRunSteps + path: listRunSteps + - type: endpoint + key: getRunStep + path: getRunStep + - type: object + key: RunStepObject + path: step-object + - id: vector-stores + title: Vector Stores + beta: true + description: | + Vector stores are used to store files for use by the `file_search` tool. + + Related guide: [File Search](/docs/assistants/tools/file-search) + navigationGroup: assistants + sections: + - type: endpoint + key: createVectorStore + path: create + - type: endpoint + key: listVectorStores + path: list + - type: endpoint + key: getVectorStore + path: retrieve + - type: endpoint + key: modifyVectorStore + path: modify + - type: endpoint + key: deleteVectorStore + path: delete + - type: object + key: VectorStoreObject + path: object + - id: vector-stores-files + title: Vector Store Files + beta: true + description: | + Vector store files represent files inside a vector store. + + Related guide: [File Search](/docs/assistants/tools/file-search) + navigationGroup: assistants + sections: + - type: endpoint + key: createVectorStoreFile + path: createFile + - type: endpoint + key: listVectorStoreFiles + path: listFiles + - type: endpoint + key: getVectorStoreFile + path: getFile + - type: endpoint + key: deleteVectorStoreFile + path: deleteFile + - type: object + key: VectorStoreFileObject + path: file-object + - id: vector-stores-file-batches + title: Vector Store File Batches + beta: true + description: | + Vector store file batches represent operations to add multiple files to a vector store. + + Related guide: [File Search](/docs/assistants/tools/file-search) + navigationGroup: assistants + sections: + - type: endpoint + key: createVectorStoreFileBatch + path: createBatch + - type: endpoint + key: getVectorStoreFileBatch + path: getBatch + - type: endpoint + key: cancelVectorStoreFileBatch + path: cancelBatch + - type: endpoint + key: listFilesInVectorStoreBatch + path: listBatchFiles + - type: object + key: VectorStoreFileBatchObject + path: batch-object + - id: assistants-streaming + title: Streaming + beta: true + description: | + Stream the result of executing a Run or resuming a Run after submitting tool outputs. + + You can stream events from the [Create Thread and Run](/docs/api-reference/runs/createThreadAndRun), + [Create Run](/docs/api-reference/runs/createRun), and [Submit Tool Outputs](/docs/api-reference/runs/submitToolOutputs) + endpoints by passing `"stream": true`. The response will be a [Server-Sent events](https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events) stream. + + Our Node and Python SDKs provide helpful utilities to make streaming easy. Reference the + [Assistants API quickstart](/docs/assistants/overview) to learn more. + navigationGroup: assistants + sections: + - type: object + key: MessageDeltaObject + path: message-delta-object + - type: object + key: RunStepDeltaObject + path: run-step-delta-object + - type: object + key: AssistantStreamEvent + path: events + - id: completions + title: Completions + legacy: true + navigationGroup: legacy + description: | + Given a prompt, the model will return one or more predicted completions along with the probabilities of alternative tokens at each position. Most developer should use our [Chat Completions API](/docs/guides/text-generation/text-generation-models) to leverage our best and newest models. + sections: + - type: endpoint + key: createCompletion + path: create + - type: object + key: CreateCompletionResponse + path: object diff --git a/gradle.properties b/gradle.properties index 6b44219..0e40dcf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.caching=true group=io.ballerina.lib -version=2.0.1-SNAPSHOT +version=3.0.0-SNAPSHOT releasePluginVersion=2.8.0 ballerinaGradlePluginVersion=2.2.4 -ballerinaLangVersion=2201.9.3 \ No newline at end of file +ballerinaLangVersion=2201.12.2