diff --git a/README.md b/README.md index 04bcd9be3..eff608de4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ -# OpenAPI spec for the OpenAI API +# A conversion of the OpenAI OpenAPI to TypeSpec -This repository contains an [OpenAPI](https://www.openapis.org/) specification for the [OpenAI API](https://platform.openai.com/docs/api-reference). +Snapshot: https://raw.githubusercontent.com/openai/openai-openapi/b648b7823135e6fa5148ac9a303c16fdad050da6/openapi.yaml + +There are some deltas: + +### Changes to API Semantics + +- Many things are missing defaults (mostly due to bug where we can't set null defaults) +- Error responses have been added. +- Where known, the `object` property's type is narrowed from string to the constant value it will always be + +### Changes to API metadata or OpenAPI format + +- Much of the x-oaiMeta entries have not been added. +- In some cases, new schemas needed to be defined in order to be defined in TypeSpec (e.g. because the constraints could not be added to a model property with a heterogeneous type) +- There is presently no way to set `title` diff --git a/assistants/main.tsp b/assistants/main.tsp new file mode 100644 index 000000000..6a754bcb5 --- /dev/null +++ b/assistants/main.tsp @@ -0,0 +1 @@ +import "./operations.tsp"; \ No newline at end of file diff --git a/assistants/meta.tsp b/assistants/meta.tsp new file mode 100644 index 000000000..fd2481ecb --- /dev/null +++ b/assistants/meta.tsp @@ -0,0 +1,42 @@ +import "./models.tsp"; + +import "@typespec/openapi"; + +using TypeSpec.OpenAPI; + +namespace OpenAI; + +// TODO: Fill in example here. +@@extension(OpenAI.ListAssistantsResponse, + "x-oaiMeta", + """ + name: List assistants response object + group: chat + example: *list_assistants_example + """ +); + +// TODO: Fill in example here. +@@extension(OpenAI.AssistantObject, + "x-oaiMeta", + """ + name: The assistant object + beta: true + example: *create_assistants_example + """ +); + +@@extension(OpenAI.AssistantFileObject, + "x-oaiMeta", + """ + name: The assistant file object + beta: true + example: | + { + "id": "file-abc123", + "object": "assistant.file", + "created_at": 1699055364, + "assistant_id": "asst_abc123" + } + """ +); \ No newline at end of file diff --git a/assistants/models.tsp b/assistants/models.tsp new file mode 100644 index 000000000..acea5a1d4 --- /dev/null +++ b/assistants/models.tsp @@ -0,0 +1,231 @@ +import "../common/models.tsp"; + +using TypeSpec.Http; +using TypeSpec.OpenAPI; + +namespace OpenAI; + +model CreateAssistantRequest { + /** + * 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. + */ + `model`: string; + + /** The name of the assistant. The maximum length is 256 characters. */ + @maxLength(256) + name?: string | null; + + /** The description of the assistant. The maximum length is 512 characters. */ + @maxLength(512) + description?: string | null; + + /** The system instructions that the assistant uses. The maximum length is 32768 characters. */ + @maxLength(32768) + instructions?: string | null; + + /** + * 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`, `retrieval`, or `function`. + */ + + tools?: CreateAssistantRequestTools = []; + + /** + * A list of [file](/docs/api-reference/files) IDs attached to this assistant. There can be a + * maximum of 20 files attached to the assistant. Files are ordered by their creation date in + * ascending order. + */ + @maxItems(20) + file_ids?: string[] = []; + + /** + * 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. + */ + @extension("x-oaiTypeLabel", "map") + metadata?: Record | null; +} + +model ModifyAssistantRequest { + /** + * 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. + */ + `model`?: string; + + /** The name of the assistant. The maximum length is 256 characters. */ + @maxLength(256) + name?: string | null; + + /** The description of the assistant. The maximum length is 512 characters. */ + @maxLength(512) + description?: string | null; + + /** The system instructions that the assistant uses. The maximum length is 32768 characters. */ + @maxLength(32768) + instructions?: string | null; + + /** + * 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`, `retrieval`, or `function`. + */ + tools?: CreateAssistantRequestTools = []; + + /** + * A list of [file](/docs/api-reference/files) IDs attached to this assistant. There can be a + * maximum of 20 files attached to the assistant. Files are ordered by their creation date in + * ascending order. + */ + @maxItems(20) + file_ids?: string[] = []; + + /** + * 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. + */ + @extension("x-oaiTypeLabel", "map") + metadata?: Record | null; +} + +model CreateAssistantFileRequest { + /** + * A [File](/docs/api-reference/files) ID (with `purpose="assistants"`) that the assistant should + * use. Useful for tools like `retrieval` and `code_interpreter` that can access files. + */ + file_id: string; +} + +model ListAssistantsResponse { + object: "list"; + data: AssistantObject[]; + first_id: string; + last_id: string; + has_more: boolean; +} + +model DeleteAssistantResponse { + id: string; + deleted: boolean; + object: "assistant.deleted"; +} + +model ListAssistantFilesResponse { + object: "list"; + data: AssistantFileObject[]; + first_id: string; + last_id: string; + has_more: boolean; +} + +/** + * Deletes the association between the assistant and the file, but does not delete the + * [File](/docs/api-reference/files) object itself. + */ +model DeleteAssistantFileResponse { + id: string; + deleted: boolean; + object: "assistant.file.deleted"; +} + +@maxItems(128) +model CreateAssistantRequestTools is CreateAssistantRequestTool[]; + +@oneOf +@extension("x-oaiExpandable", true) +union CreateAssistantRequestTool { + AssistantToolsCode, + AssistantToolsRetrieval, + AssistantToolsFunction +} + +model AssistantToolsCode { + /** The type of tool being defined: `code_interpreter` */ + type: "code_interpreter"; +} + +model AssistantToolsRetrieval { + /** The type of tool being defined: `retrieval` */ + type: "retrieval"; +} + +model AssistantToolsFunction { + /** The type of tool being defined: `function` */ + type: "function"; + + function: FunctionObject; +} + +/** Represents an `assistant` that can call the model and use tools. */ +model AssistantObject { + /** The identifier, which can be referenced in API endpoints. */ + id: string; + + /** The object type, which is always `assistant`. */ + object: "assistant"; + + /** The Unix timestamp (in seconds) for when the assistant was created. */ + @encode("unixTimestamp", int32) + created_at: utcDateTime; + + /** The name of the assistant. The maximum length is 256 characters. */ + @maxLength(256) + name: string | null; + + /** The description of the assistant. The maximum length is 512 characters. */ + @maxLength(512) + description: string | null; + + /** + * 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. + */ + `model`: string; + + /** The system instructions that the assistant uses. The maximum length is 32768 characters. */ + @maxLength(32768) + instructions: string | null; + + /** + * 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`, `retrieval`, or `function`. + */ + tools: CreateAssistantRequestTools = []; + + /** + * A list of [file](/docs/api-reference/files) IDs attached to this assistant. There can be a + * maximum of 20 files attached to the assistant. Files are ordered by their creation date in + * ascending order. + */ + @maxItems(20) + file_ids: string[] = []; + + /** + * 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. + */ + @extension("x-oaiTypeLabel", "map") + metadata: Record | null; +} + +/** A list of [Files](/docs/api-reference/files) attached to an `assistant`. */ +model AssistantFileObject { + /** The identifier, which can be referenced in API endpoints. */ + id: string; + + /** The object type, which is always `assistant.file`. */ + object: "assistant.file"; + + /** The Unix timestamp (in seconds) for when the assistant file was created. */ + @encode("unixTimestamp", int32) + created_at: utcDateTime; + + /** The assistant ID that the file is attached to. */ + assistant_id: string; +} \ No newline at end of file diff --git a/assistants/operations.tsp b/assistants/operations.tsp new file mode 100644 index 000000000..350f68d7b --- /dev/null +++ b/assistants/operations.tsp @@ -0,0 +1,161 @@ +import "@typespec/http"; +import "@typespec/openapi"; + +import "../common/errors.tsp"; +import "./models.tsp"; + +using TypeSpec.Http; +using TypeSpec.OpenAPI; + +namespace OpenAI; + +@route("/assistants") +interface Assistants { + @post + @operationId("createAssistant") + @tag("Assistants") + @summary("Create an assistant with a model and instructions.") + createAssistant( + @body assistant: CreateAssistantRequest, + ): AssistantObject | ErrorResponse; + + @get + @operationId("listAssistants") + @tag("Assistants") + @summary("Returns a list of assistants.") + listAssistants( + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + * default is 20. + */ + @query limit?: int32 = 20; + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc` + * for descending order. + */ + @query order?: "asc" | "desc" = "desc"; + + /** + * 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. + */ + @query after?: string; + + /** + * 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. + */ + @query before?: string; + ): ListAssistantsResponse | ErrorResponse; + + @route("{assistant_id}") + @get + @operationId("getAssistant") + @tag("Assistants") + @summary("Retrieves an assistant.") + getAssistant( + /** The ID of the assistant to retrieve. */ + @path assistant_id: string, + ): AssistantObject | ErrorResponse; + + @route("{assistant_id}") + @post + @operationId("modifyAssistant") + @tag("Assistants") + @summary("Modifies an assistant.") + modifyAssistant( + /** The ID of the assistant to modify. */ + @path assistant_id: string, + + @body assistant: ModifyAssistantRequest, + ): AssistantObject | ErrorResponse; + + @route("{assistant_id}") + @delete + @operationId("deleteAssistant") + @tag("Assistants") + @summary("Delete an assistant.") + deleteAssistant( + /** The ID of the assistant to delete. */ + @path assistant_id: string, + ): DeleteAssistantResponse | ErrorResponse; + + @route("{assistant_id}/files") + @post + @operationId("createAssistantFile") + @tag("Assistants") + @summary(""" + Create an assistant file by attaching a [File](/docs/api-reference/files) to a + [assistant](/docs/api-reference/assistants). + """) + createAssistantFile( + /** The ID of the assistant for which to create a file. */ + @path assistant_id: string, + @body file: CreateAssistantFileRequest, + ): AssistantFileObject | ErrorResponse; + + @route("{assistant_id}/files") + @get + @operationId("listAssistantFiles") + @tag("Assistants") + @summary("Returns a list of assistant files.") + listAssistantFiles( + /** The ID of the assistant the file belongs to. */ + @path assistant_id: string, + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + * default is 20. + */ + @query limit?: int32 = 20; + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc` + * for descending order. + */ + @query order?: "asc" | "desc" = "desc"; + + /** + * 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. + */ + @query after?: string; + + /** + * 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. + */ + @query before?: string; + ): ListAssistantFilesResponse | ErrorResponse; + + @route("{assistant_id}/files/{file_id}") + @get + @operationId("getAssistantFile") + @tag("Assistants") + @summary("Retrieves an assistant file.") + getAssistantFile( + /** The ID of the assistant the file belongs to. */ + @path assistant_id: string, + + /** The ID of the file we're getting. */ + @path file_id: string, + ): AssistantFileObject | ErrorResponse; + + @route("{assistant_id}/files/{file_id}") + @delete + @operationId("deleteAssistantFile") + @tag("Assistants") + @summary("Delete an assistant file.") + deleteAssistantFile( + /** The ID of the assistant the file belongs to. */ + @path assistant_id: string, + + /** The ID of the file to delete. */ + @path file_id: string, + ): DeleteAssistantFileResponse | ErrorResponse; +} diff --git a/audio/main.tsp b/audio/main.tsp index c6458821f..144c4aeaf 100644 --- a/audio/main.tsp +++ b/audio/main.tsp @@ -1,2 +1 @@ import "./operations.tsp"; -import "./models.tsp"; diff --git a/audio/models.tsp b/audio/models.tsp index a2a440a90..53d7757c3 100644 --- a/audio/models.tsp +++ b/audio/models.tsp @@ -1,6 +1,39 @@ -namespace OpenAI; +import "../common/models.tsp"; + +using TypeSpec.Http; using TypeSpec.OpenAPI; +namespace OpenAI; + +model CreateSpeechRequest { + /** One of the available [TTS models](/docs/models/tts): `tts-1` or `tts-1-hd` */ + @extension("x-oaiTypeLabel", "string") + `model`: string | TEXT_TO_SPEECH_MODELS; + + /** + * The text to generate audio for. The maximum length is 4096 characters. + */ + @maxLength(4096) + input: string; + + /** + * 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). + */ + voice: "alloy" | "echo" | "fable" | "onyx" | "nova" | "shimmer"; + + /** The format to audio in. Supported formats are `mp3`, `opus`, `aac`, and `flac`. */ + response_format?: "mp3" | "opus" | "aac" | "flac" = "mp3"; + + /** + * The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is the default. + */ + @minValue(0.25) + @maxValue(4.0) + speed?: float64 = 1.0; +} + model CreateTranscriptionRequest { /** * The audio file object (not file name) to transcribe, in one of these formats: flac, mp3, mp4, @@ -12,7 +45,14 @@ model CreateTranscriptionRequest { /** ID of the model to use. Only `whisper-1` is currently available. */ @extension("x-oaiTypeLabel", "string") - `model`: string | "whisper-1"; + `model`: string | SPEECH_TO_TEXT_MODELS; + + /** + * 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. + */ + language?: string; /** * An optional text to guide the model's style or continue a previous audio segment. The @@ -32,21 +72,10 @@ model CreateTranscriptionRequest { * the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to * automatically increase the temperature until certain thresholds are hit. */ + // NOTE: Min and max values are absent in the OpenAPI spec but mentioned in the description. @minValue(0) @maxValue(1) temperature?: float64 = 0; - - /** - * 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. - */ - language?: string; -} - -// Note: This does not currently support the non-default response format types. -model CreateTranscriptionResponse { - text: string; } model CreateTranslationRequest { @@ -60,7 +89,7 @@ model CreateTranslationRequest { /** ID of the model to use. Only `whisper-1` is currently available. */ @extension("x-oaiTypeLabel", "string") - `model`: string | "whisper-1"; + `model`: string | SPEECH_TO_TEXT_MODELS; /** * An optional text to guide the model's style or continue a previous audio segment. The @@ -81,12 +110,104 @@ model CreateTranslationRequest { * the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to * automatically increase the temperature until certain thresholds are hit. */ + // NOTE: Min and max values are absent in the OpenAPI spec but mentioned in the description. @minValue(0) @maxValue(1) temperature?: float64 = 0; } -// Note: This does not currently support the non-default response format types. +// NOTE: This model is not defined in the OpenAI API spec. +model CreateTranscriptionResponse { + /** The transcribed text for the provided audio data. */ + text: string; + + /** The label that describes which operation type generated the accompanying response data. */ + task?: "transcribe"; + + /** The spoken language that was detected in the audio data. */ + language?: string; + + /** + * The total duration of the audio processed to produce accompanying transcription information. + */ + @encode("seconds", float64) + duration?: duration; + + /** + * A collection of information about the timing, probabilities, and other detail of each processed + * audio segment. + */ + segments?: AudioSegment[]; +} + +// NOTE: This model is not defined in the OpenAI API spec. model CreateTranslationResponse { + /** The translated text for the provided audio data. */ text: string; + + /** The label that describes which operation type generated the accompanying response data. */ + task?: "translate"; + + /** The spoken language that was detected in the audio data. */ + language?: string; + + /** The total duration of the audio processed to produce accompanying translation information. */ + @encode("seconds", float64) + duration?: duration; + + /** + * A collection of information about the timing, probabilities, and other detail of each processed + * audio segment. + */ + segments?: AudioSegment[]; } + +alias TEXT_TO_SPEECH_MODELS = + | "tts-1" + | "tts-1-hd"; + +alias SPEECH_TO_TEXT_MODELS = + | "whisper-1"; + +// NOTE: This model is not defined in the OpenAI API spec. +model AudioSegment { + /** The zero-based index of this segment. */ + id: safeint; + + /** + * The seek position associated with the processing of this audio segment. Seek positions are + * expressed as hundredths of seconds. The model may process several segments from a single seek + * position, so while the seek position will never represent a later time than the segment's + * start, the segment's start may represent a significantly later time than the segment's + * associated seek position. + */ + seek: safeint; + + /** The time at which this segment started relative to the beginning of the audio. */ + @encode("seconds", float64) + start: duration; + + /** The time at which this segment ended relative to the beginning of the audio. */ + @encode("seconds", float64) + end: duration; + + /** The text that was part of this audio segment. */ + text: string; + + /** The token IDs matching the text in this audio segment. */ + tokens: TokenArray; + + /** The temperature score associated with this audio segment. */ + @minValue(0) + @maxValue(1) + temperature: float64; + + /** The average log probability associated with this audio segment. */ + avg_logprob: float64; + + /** The compression ratio of this audio segment. */ + compression_ratio: float64; + + /** The probability of no speech detection within this audio segment. */ + no_speech_prob: float64; +} \ No newline at end of file diff --git a/audio/operations.tsp b/audio/operations.tsp index 636fb941a..ee1cb428e 100644 --- a/audio/operations.tsp +++ b/audio/operations.tsp @@ -2,34 +2,61 @@ import "@typespec/http"; import "@typespec/openapi"; import "../common/errors.tsp"; +import "./models.tsp"; using TypeSpec.Http; using TypeSpec.OpenAPI; namespace OpenAI; + @route("/audio") -namespace Audio { +interface Audio { + @route("speech") + @post + @operationId("createSpeech") + @tag("Audio") + @summary("Generates audio from the input text.") + createSpeech( + @body speech: CreateSpeechRequest, + ): { + /** chunked */ + @header("Transfer-Encoding") transferEncoding?: string; + + @header contentType: "application/octet-stream"; + @body @encode("binary") audio: bytes; + }; + @route("transcriptions") - interface Transcriptions { - @post - @operationId("createTranscription") - @tag("OpenAI") - @summary("Transcribes audio into the input language.") - createTranscription( - @header contentType: "multipart/form-data", - @body audio: CreateTranscriptionRequest, - ): CreateTranscriptionResponse | ErrorResponse; - } + @post + @operationId("createTranscription") + @tag("Audio") + @summary("Transcribes audio into the input language.") + createTranscription( + @header contentType: "multipart/form-data", + @body audio: CreateTranscriptionRequest, + ): + | CreateTranscriptionResponse + | { + // TODO: Is this the appropriate way to describe the multiple possible response types? + @header contentType: "text/plain"; + @body text: string; + } + | ErrorResponse; @route("translations") - interface Translations { - @post - @operationId("createTranslation") - @tag("OpenAI") - @summary("Transcribes audio into the input language.") - createTranslation( - @header contentType: "multipart/form-data", - @body audio: CreateTranslationRequest, - ): CreateTranslationResponse | ErrorResponse; - } -} + @post + @operationId("createTranslation") + @tag("Audio") + @summary("Translates audio into English..") + createTranslation( + @header contentType: "multipart/form-data", + @body audio: CreateTranslationRequest, + ): + | CreateTranslationResponse + | { + // TODO: Is this the appropriate way to describe the multiple possible response types? + @header contentType: "text/plain"; + @body text: string; + } + | ErrorResponse; +} \ No newline at end of file diff --git a/edits/main.tsp b/chat/main.tsp similarity index 100% rename from edits/main.tsp rename to chat/main.tsp diff --git a/completions/chat-meta.tsp b/chat/meta.tsp similarity index 94% rename from completions/chat-meta.tsp rename to chat/meta.tsp index 7823da41d..6df478c87 100644 --- a/completions/chat-meta.tsp +++ b/chat/meta.tsp @@ -1,6 +1,10 @@ +import "./operations.tsp"; + using TypeSpec.OpenAPI; -@@extension(OpenAI.Completions.createCompletion, +namespace OpenAI; + +@@extension(OpenAI.Chat.createChatCompletion, "x-oaiMeta", { name: "Create chat completion", @@ -166,3 +170,13 @@ using TypeSpec.OpenAPI; ], } ); + +// TODO: Fill in example here. +@@extension(OpenAI.CreateChatCompletionResponse, + "x-oaiMeta", + { + name: "The chat completion object", + group: "chat", + example: "", + } +); \ No newline at end of file diff --git a/chat/models.tsp b/chat/models.tsp new file mode 100644 index 000000000..160afb122 --- /dev/null +++ b/chat/models.tsp @@ -0,0 +1,580 @@ +import "../common/models.tsp"; + +using TypeSpec.OpenAPI; + +namespace OpenAI; + +model CreateChatCompletionRequest { + /** + * A list of messages comprising the conversation so far. + * [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb). + */ + @minItems(1) + messages: ChatCompletionRequestMessage[]; + + /** + * 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. + */ + @extension("x-oaiTypeLabel", "string") + `model`: string | CHAT_COMPLETION_MODELS; + + /** + * 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/gpt/parameter-details) + */ + @minValue(-2) + @maxValue(2) + frequency_penalty?: float64 | null = 0; + + /** + * 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. + */ + @extension("x-oaiTypeLabel", "map") + logit_bias?: Record | null = null; + + /** + * 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`. This option is + * currently not available on the `gpt-4-vision-preview` model. + */ + logprobs?: boolean | null = false; + + /** + * An integer between 0 and 5 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. + */ + @minValue(0) + @maxValue(5) + top_logprobs?: safeint | null; + + /** + * 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. + */ + @minValue(0) + max_tokens?: safeint | null = 16; + + /** + * 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. + */ + @minValue(1) + @maxValue(128) + n?: safeint | null = 1; + + /** + * 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/gpt/parameter-details) + */ + @minValue(-2) + @maxValue(2) + presence_penalty?: float64 | null = 0; + + /** + * An object specifying the format that the model must output. Compatible with + * [GPT-4 Turbo](/docs/models/gpt-4-and-gpt-4-turbo) and `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. + */ + response_format?: { + /** Must be one of `text` or `json_object`. */ + type?: "text" | "json_object" = "text"; + }; + + /** + * 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. + */ + @extension( + "x-oaiMeta", + { + beta: true + } + ) + @minValue(-9223372036854775808) // TODO: Min and max exceed the limits of safeint. + @maxValue(9223372036854775807) + seed?: safeint | null; + + // TODO: Consider inlining when https://github.com/microsoft/typespec/issues/2356 is resolved + // https://github.com/microsoft/typespec/issues/2355 + /** Up to 4 sequences where the API will stop generating further tokens. */ + stop?: Stop | null = null; + + /** + * 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). + */ + stream?: boolean | null = 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. + */ + @minValue(0) + @maxValue(2) + temperature?: float64 | null = 1; + + /** + * 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. + */ + @minValue(0) + @maxValue(1) + top_p?: float64 | null = 1; + + /** + * 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. */ + tools?: ChatCompletionTool[]; + + tool_choice?: ChatCompletionToolChoiceOption; + + /** + * 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). + */ + user?: User; + + /** + * 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 "deprecated" + @extension("x-oaiExpandable", true) + function_call?: "none" | "auto" | ChatCompletionFunctionCallOption; + + /** + * Deprecated in favor of `tools`. + * + * A list of functions the model may generate JSON inputs for. + */ + #deprecated "deprecated" + @minItems(1) + @maxItems(128) + functions?: ChatCompletionFunctions[]; +} + +/** Represents a chat completion response returned by model, based on the provided input. */ +model CreateChatCompletionResponse { + /** A unique identifier for the chat completion. */ + id: string; + + /** A list of chat completion choices. Can be more than one if `n` is greater than 1. */ + choices: { + /** + * 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. + */ + finish_reason: "stop" | "length" | "tool_calls" | "content_filter" | "function_call"; + + /** The index of the choice in the list of choices. */ + index: safeint; + + message: ChatCompletionResponseMessage; + + /** Log probability information for the choice. */ + logprobs: { + content: ChatCompletionTokenLogprob[] | null; + } | null; + }[]; + + /** The Unix timestamp (in seconds) of when the chat completion was created. */ + @encode("unixTimestamp", int32) + created: utcDateTime; + + /** The model used for the chat completion. */ + `model`: string; + + /** + * 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. + */ + system_fingerprint?: string; + + /** The object type, which is always `chat.completion`. */ + object: "chat.completion"; + + usage?: CompletionUsage; +} + +alias CHAT_COMPLETION_MODELS = + | "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-16k-0613"; + +@oneOf +union Stop { + string, + StopSequences, +} + +@minItems(1) +@maxItems(4) +model StopSequences is string[]; + +/** Usage statistics for the completion request. */ +model CompletionUsage { + /** Number of tokens in the prompt. */ + prompt_tokens: safeint; + + /** Number of tokens in the generated completion */ + completion_tokens: safeint; + + /** Total number of tokens used in the request (prompt + completion). */ + total_tokens: safeint; +} + +model ChatCompletionTool { + /** The type of the tool. Currently, only `function` is supported. */ + type: "function"; + + function: FunctionObject; +} + +/** + * 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 + * `{"type": "function", "function": {"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 +@extension("x-oaiExpandable", true) +union ChatCompletionToolChoiceOption { + "none", + "auto", + ChatCompletionNamedToolChoice, +} + +/** Specifies a tool the model should use. Use to force the model to call a specific function. */ +model ChatCompletionNamedToolChoice { + /** The type of the tool. Currently, only `function` is supported. */ + type: "function"; + + function: { + /** The name of the function to call. */ + name: string; + } +} + +@oneOf +union ChatCompletionRequestUserMessageContent { + /** The text contents of the message. */ + string, + + /** + * 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-4-visual-preview` model. + */ + ChatCompletionRequestMessageContentParts, +}; + +@minItems(1) +model ChatCompletionRequestMessageContentParts is ChatCompletionRequestMessageContentPart[]; + +@oneOf +@extension("x-oaiExpandable", true) +union ChatCompletionRequestMessageContentPart { + ChatCompletionRequestMessageContentPartText, + ChatCompletionRequestMessageContentPartImage, +} + +model ChatCompletionRequestMessageContentPartText { + /** The type of the content part. */ + type: "text"; + + /** The text content. */ + text: string; +} + +model ChatCompletionRequestMessageContentPartImage { + /** The type of the content part. */ + type: "image_url"; + + image_url: { + /** Either a URL of the image or the base64 encoded image data. */ + // TODO: The original OpenAPI spec only describes this as a URL. + url: url | string; + + /** + * Specifies the detail level of the image. Learn more in the + * [Vision guide](/docs/guides/vision/low-or-high-fidelity-image-understanding). + */ + detail?: "auto" | "low" | "high" = "auto"; + } +} + +/** The tool calls generated by the model, such as function calls. */ +model ChatCompletionMessageToolCalls is ChatCompletionMessageToolCall[]; + +model ChatCompletionMessageToolCall { + /** The ID of the tool call. */ + id: string; + + /** The type of the tool. Currently, only `function` is supported. */ + type: "function"; + + /** The function that the model called. */ + function: { + /** The name of the function to call. */ + name: string; + + /** + * 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. + */ + arguments: string; + } +}; + +@oneOf +@extension("x-oaiExpandable", true) +union ChatCompletionRequestMessage { + ChatCompletionRequestSystemMessage, + ChatCompletionRequestUserMessage, + ChatCompletionRequestAssistantMessage, + ChatCompletionRequestToolMessage, + ChatCompletionRequestFunctionMessage, +} + +model ChatCompletionRequestSystemMessage { + /** The contents of the system message. */ + @extension("x-oaiExpandable", true) + content: string , + + /** The role of the messages author, in this case `system`. */ + role: "system", + + /** + * An optional name for the participant. Provides the model information to differentiate between + * participants of the same role. + */ + name?: string; +} + +model ChatCompletionRequestUserMessage { + /** The contents of the system message. */ + @extension("x-oaiExpandable", true) + content: ChatCompletionRequestUserMessageContent, + + /** The role of the messages author, in this case `user`. */ + role: "user", + + /** + * An optional name for the participant. Provides the model information to differentiate between + * participants of the same role. + */ + name?: string; +} + +model ChatCompletionRequestAssistantMessage { + /** + * The contents of the assistant message. Required unless `tool_calls` or `function_call` is' + * specified. + */ + content?: string | null, + + /** The role of the messages author, in this case `assistant`. */ + role: "assistant", + + /** + * An optional name for the participant. Provides the model information to differentiate between + * participants of the same role. + */ + name?: string; + + tool_calls?: ChatCompletionMessageToolCalls; + + /** + * Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be + * called, as generated by the model. + */ + #deprecated "deprecated" + function_call?: { + /** + * 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. + */ + arguments: string; + + /** The name of the function to call. */ + name: string; + + } +} + +model ChatCompletionRequestToolMessage { + /** The role of the messages author, in this case `tool`. */ + role: "tool", + + /** The contents of the tool message. */ + content: string; + + /** Tool call that this message is responding to. */ + tool_call_id: string; +} + +model ChatCompletionRequestFunctionMessage { + /** The role of the messages author, in this case `function`. */ + role: "function", + + /** The contents of the function message. */ + content: string | null; + + /** The name of the function to call. */ + name: string; +} + +model ChatCompletionResponseMessage { + /** The contents of the message. */ + content: string | null; + + tool_calls?: ChatCompletionMessageToolCalls; + + /** The role of the author of this message. */ + role: "assistant"; + + /** Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. */ + #deprecated "deprecated" + function_call?: { + /** + * 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. + */ + arguments: string; + + /** The name of the function to call. */ + name: string; + }; +} + +model ChatCompletionTokenLogprob { + /** The token. */ + token: string; + + /** The log probability of this token. */ + logprob: float64; + + /** + * 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. + */ + bytes: safeint[] | null; + + /** + * 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. + */ + top_logprobs: { + /** The token. */ + token: string; + + /** The log probability of this token. */ + logprob: float64; + + /** + * 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. + */ + bytes: safeint[] | null; + }[]; +} + +/** + * Specifying a particular function via `{"name": "my_function"}` forces the model to call that + * function. + */ +model ChatCompletionFunctionCallOption { + /** The name of the function to call. */ + name: string; +} + +#deprecated "deprecated" +model ChatCompletionFunctions { + /** + * A description of what the function does, used by the model to choose when and how to call the + * function. + */ + description?: string; + + /** + * 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. + */ + name: string; + + parameters?: FunctionParameters; +} \ No newline at end of file diff --git a/chat/operations.tsp b/chat/operations.tsp new file mode 100644 index 000000000..0b2972421 --- /dev/null +++ b/chat/operations.tsp @@ -0,0 +1,22 @@ +import "@typespec/http"; +import "@typespec/openapi"; + +import "../common/errors.tsp"; +import "./models.tsp"; + +using TypeSpec.Http; +using TypeSpec.OpenAPI; + +namespace OpenAI; + +@route("/chat") +interface Chat { + @route("completions") + @post + @operationId("createChatCompletion") + @tag("Chat") + @summary("Creates a model response for the given chat conversation.") + createChatCompletion( + ...CreateChatCompletionRequest, + ): CreateChatCompletionResponse | ErrorResponse; +} \ No newline at end of file diff --git a/common/models.tsp b/common/models.tsp index d6d0d4f91..611e53e7a 100644 --- a/common/models.tsp +++ b/common/models.tsp @@ -1,34 +1,6 @@ -namespace OpenAI; using TypeSpec.OpenAPI; -model ListModelsResponse { - object: string; - data: Model[]; -} - -/** Describes an OpenAI model offering that can be used with the API. */ -model Model { - /** The model identifier, which can be referenced in the API endpoints. */ - id: string; - - /** The object type, which is always "model". */ - object: "model"; - - /** The Unix timestamp (in seconds) when the model was created. */ - @encode("unixTimestamp", int32) - created: utcDateTime; - - /** The organization that owns the model. */ - owned_by: string; -} - -model DeleteModelResponse { - id: string; - object: string; - deleted: boolean; -} - -// this is using yaml refs instead of a def in the openapi, not sure if that's required? +namespace OpenAI; scalar User extends string; @@ -37,3 +9,30 @@ model TokenArray is safeint[]; @minItems(1) model TokenArrayArray is TokenArray[]; + +model FunctionObject { + /** + * A description of what the function does, used by the model to choose when and how to call the + * function. + */ + description?: string; + + /** + * 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. + */ + name: string; + + parameters?: FunctionParameters; +} + +/** + * The parameters the functions accepts, described as a JSON Schema object. See the + * [guide](/docs/guides/gpt/function-calling) for examples, and the + * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation + * about the format.\n\nTo describe a function that accepts no parameters, provide the value + * `{\"type\": \"object\", \"properties\": {}}`. + */ +// TODO: The generated spec produces "additionalProperties: {}" for this instead of +// "additionalProperties: true". Are they equivalent? +model FunctionParameters is Record; \ No newline at end of file diff --git a/completions/meta.tsp b/completions/meta.tsp new file mode 100644 index 000000000..708dea11d --- /dev/null +++ b/completions/meta.tsp @@ -0,0 +1,35 @@ +import "./models.tsp"; +import "./operations.tsp"; + +using TypeSpec.OpenAPI; + +namespace OpenAI; + +// TODO: Fill in example here. +@@extension(OpenAI.CreateCompletionResponse, + "x-oaiMeta", + """ + name: The completion object + legacy: true, + example: | + { + "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7", + "object": "text_completion", + "created": 1589478378, + "model": "gpt-3.5-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 + } + } + """ +); \ No newline at end of file diff --git a/completions/models.tsp b/completions/models.tsp index 5aa332b32..4122d8bda 100644 --- a/completions/models.tsp +++ b/completions/models.tsp @@ -1,80 +1,46 @@ -namespace OpenAI; -using TypeSpec.OpenAPI; +import "../common/models.tsp"; +import "../chat/models.tsp"; -alias CHAT_COMPLETION_MODELS = - | "gpt4" - | "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-16k-0613"; +using TypeSpec.OpenAPI; -alias COMPLETION_MODELS = - | "babbage-002" - | "davinci-002" - | "text-davinci-003" - | "text-davinci-002" - | "text-davinci-001" - | "code-davinci-002" - | "text-curie-001" - | "text-babbage-001" - | "text-ada-001"; +namespace OpenAI; -alias SharedCompletionProperties = { +model CreateCompletionRequest { /** - * 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. + * 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. */ - temperature?: Temperature | null = 1; + @extension("x-oaiTypeLabel", "string") + `model`: string | COMPLETION_MODELS; /** - * 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. + * The prompt(s) to generate completions for, encoded as a string, array of strings, array of + * tokens, or array of token arrays. * - * We generally recommend altering this or `temperature` but not both. + * 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. */ - top_p?: TopP | null = 1; + // TODO: consider inlining when https://github.com/microsoft/typespec/issues/2356 fixed + prompt: Prompt | null = "<|endoftext|>"; /** - * How many completions to generate for each prompt. + * 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`. */ - n?: N | null = 1; - - /** - * The maximum number of [tokens](/tokenizer) to generate in the completion. - * - * The token count of your prompt plus `max_tokens` cannot exceed the model's context length. - * [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) - * for counting tokens. - */ - max_tokens?: MaxTokens | null = 16; - - // todo: consider inlining when https://github.com/microsoft/typespec/issues/2356 is resolved - // https://github.com/microsoft/typespec/issues/2355 - /** Up to 4 sequences where the API will stop generating further tokens. */ - stop?: Stop = null; + @minValue(0) + @maxValue(20) + best_of?: safeint | null = 1; - // needs default - // https://github.com/microsoft/typespec/issues/1646 - /** - * 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/gpt/parameter-details) - */ - presence_penalty?: Penalty | null; + /** Echo back the prompt in addition to the completion */ + echo?: boolean | null = false; - // needs default /** * 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 @@ -82,319 +48,137 @@ alias SharedCompletionProperties = { * * [See more information about frequency and presence penalties.](/docs/guides/gpt/parameter-details) */ - frequency_penalty?: Penalty | null; + @minValue(-2) + @maxValue(2) + frequency_penalty?: float64 | null = 0; - // needs default of null /** * 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. + * + * 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. */ @extension("x-oaiTypeLabel", "map") - logit_bias?: Record | null; - - /** - * 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). - */ - user?: User; - - /** - * 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://github.com/openai/openai-cookbook/blob/main/examples/How_to_stream_completions.ipynb). - */ - stream?: boolean | null = true; -}; - -@oneOf -union Stop { - string, - StopSequences, - null, -} - -@minValue(-2) -@maxValue(2) -scalar Penalty extends float64; - -@minItems(1) -@maxItems(4) -model StopSequences is string[]; - -@minValue(0) -@maxValue(2) -scalar Temperature extends float64; - -@minValue(0) -@maxValue(1) -scalar TopP extends float64; - -@minValue(1) -@maxValue(128) -scalar N extends safeint; - -@minValue(0) -scalar MaxTokens extends safeint; - -model CreateChatCompletionRequest { - /** - * 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. - */ - @extension("x-oaiTypeLabel", "string") - `model`: string | CHAT_COMPLETION_MODELS; - - /** - * A list of messages comprising the conversation so far. - * [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb). - */ - @minItems(1) - messages: ChatCompletionRequestMessage[]; - - /** A list of functions the model may generate JSON inputs for. */ - @minItems(1) - @maxItems(128) - functions?: ChatCompletionFunctions[]; - - /** - * Controls how the model responds to function calls. `none` means the model does not call a - * function, and responds to the end-user. `auto` means the model can pick between an end-user 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. - */ - function_call?: "none" | "auto" | ChatCompletionFunctionCallOption; - - ...SharedCompletionProperties; -} - -model ChatCompletionFunctionCallOption { - /** The name of the function to call. */ - name: string; -} + logit_bias?: Record | null = null; -model ChatCompletionFunctions { /** - * 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. + * Include the log probabilities on the `logprobs` most likely 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. */ - name: string; + @minValue(0) + @maxValue(5) + logprobs?: safeint | null = null; /** - * A description of what the function does, used by the model to choose when and how to call the - * function. + * The maximum number of [tokens](/tokenizer) to generate in the completion. + * + * The token count of your prompt plus `max_tokens` cannot exceed the model's context length. + * [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) + * for counting tokens. */ - description?: string; + @minValue(0) + max_tokens?: safeint | null = 16; /** - * The parameters the functions accepts, described as a JSON Schema object. See the - * [guide](/docs/guides/gpt/function-calling) for examples, and the - * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation - * about the format.\n\nTo describe a function that accepts no parameters, provide the value - * `{\"type\": \"object\", \"properties\": {}}`. + * 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`. */ - parameters: ChatCompletionFunctionParameters; -} - -model ChatCompletionFunctionParameters is Record; - -model ChatCompletionRequestMessage { - /** The role of the messages author. One of `system`, `user`, `assistant`, or `function`. */ - role: "system" | "user" | "assistant" | "function"; + @minValue(1) + @maxValue(128) + n?: safeint | null = 1; /** - * The contents of the message. `content` is required for all messages, and may be null for - * assistant messages with function calls. + * 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/gpt/parameter-details) */ - content: string | null; + @minValue(-2) + @maxValue(2) + presence_penalty?: float64 | null = 0; + + /** + * 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. + */ + @extension( + "x-oaiMeta", + { + beta: true + } + ) + @minValue(-9223372036854775808) // TODO: Min and max exceed the limits of safeint. + @maxValue(9223372036854775807) + seed?: safeint | null; + + // TODO: Consider inlining when https://github.com/microsoft/typespec/issues/2356 is resolved + // https://github.com/microsoft/typespec/issues/2355 + /** Up to 4 sequences where the API will stop generating further tokens. */ + stop?: Stop | null = null; - // TODO: the constraints are not specified in the API /** - * The name of the author of this message. `name` is required if role is `function`, and it - * should be the name of the function whose response is in the `content`. May contain a-z, - * A-Z, 0-9, and underscores, with a maximum length of 64 characters. + * 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://github.com/openai/openai-cookbook/blob/main/examples/How_to_stream_completions.ipynb). */ - name?: string; - - /** The name and arguments of a function that should be called, as generated by the model. */ - function_call?: { - /** The name of the function to call. */ - name: string; + stream?: boolean | null = false; - /** - * 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. - */ - arguments: string; - }; -} - -/** Represents a chat completion response returned by model, based on the provided input. */ -// TODO: Fill in example here. -@extension( - "x-oaiMeta", - { - name: "The chat completion object", - group: "chat", - example: "", - } -) -model CreateChatCompletionResponse { - /** A unique identifier for the chat completion. */ - id: string; - - /** The object type, which is always `chat.completion`. */ - object: string; - - /** The Unix timestamp (in seconds) of when the chat completion was created. */ - @encode("unixTimestamp", int32) - created: utcDateTime; - - /** The model used for the chat completion. */ - `model`: string; - - /** A list of chat completion choices. Can be more than one if `n` is greater than 1. */ - choices: { - /** The index of the choice in the list of choices. */ - index: safeint; - - message: ChatCompletionResponseMessage; - - /** - * 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 the content was omitted due to - * a flag from our content filters, or `function_call` if the model called a function. - */ - finish_reason: "stop" | "length" | "function_call" | "content_filter"; - }[]; - - usage?: CompletionUsage; -} - -/** Usage statistics for the completion request. */ -model CompletionUsage { - /** Number of tokens in the prompt. */ - prompt_tokens: safeint; - - /** Number of tokens in the generated completion */ - completion_tokens: safeint; - - /** Total number of tokens used in the request (prompt + completion). */ - total_tokens: safeint; -} - -model ChatCompletionResponseMessage { - /** The role of the author of this message. */ - role: "system" | "user" | "assistant" | "function"; - - /** The contents of the message. */ - content: string | null; - - /** The name and arguments of a function that should be called, as generated by the model. */ - function_call?: { - /** The name of the function to call. */ - name: string; - - /** - * 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. - */ - arguments: string; - }; -} - -model CreateCompletionRequest { - /** - * 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. - */ - @extension("x-oaiTypeLabel", "string") - `model`: string | COMPLETION_MODELS; + /** The suffix that comes after a completion of inserted text. */ + suffix?: string | null = null; /** - * The prompt(s) to generate completions for, encoded as a string, array of strings, array of - * tokens, or array of token arrays. + * 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 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. + * We generally recommend altering this or `top_p` but not both. */ - // TODO: consider inlining when https://github.com/microsoft/typespec/issues/2356 fixed - prompt: Prompt = "<|endoftext|>"; - - /** The suffix that comes after a completion of inserted text. */ - suffix?: string | null = null; - - ...SharedCompletionProperties; + @minValue(0) + @maxValue(2) + temperature?: float64 | null = 1; /** - * Include the log probabilities on the `logprobs` most likely 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. + * 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. * - * The maximum value for `logprobs` is 5. + * We generally recommend altering this or `temperature` but not both. */ - logprobs?: safeint | null = null; - - /** Echo back the prompt in addition to the completion */ - echo?: boolean | null = false; + @minValue(0) + @maxValue(1) + top_p?: float64 | null = 1; /** - * 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`. + * 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). */ - best_of?: safeint | null = 1; + user?: User; } -@oneOf -union Prompt { - string, - string[], - TokenArray, - TokenArrayArray, - null, -} /** * Represents a completion response from the API. Note: both the streamed and non-streamed response * objects share the same shape (unlike the chat endpoint). */ -@extension( - "x-oaiMeta", - { - name: "The completion object", - legacy: true, - example: "", // fill in - } -) model CreateCompletionResponse { /** A unique identifier for the completion. */ id: string; - /** The object type, which is always `text_completion`. */ - object: string; - - /** The Unix timestamp (in seconds) of when the completion was created. */ - @encode("unixTimestamp", int32) - created: utcDateTime; - - /** The model used for the completion. */ - `model`: string; - /** The list of completion choices the model generated for the input. */ choices: { index: safeint; @@ -413,8 +197,42 @@ model CreateCompletionResponse { * in the request was reached, or `content_filter` if content was omitted due to a flag from our * content filters. */ + // TODO: The generated spec includes other values like "tool_calls" and "function_call". + // Is it because we're importing /chat/models.tsp? finish_reason: "stop" | "length" | "content_filter"; }[]; + /** The Unix timestamp (in seconds) of when the completion was created. */ + @encode("unixTimestamp", int32) + created: utcDateTime; + + /** The model used for the completion. */ + `model`: string; + + /** + * 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. + */ + system_fingerprint?: string; + + /** The object type, which is always `text_completion`. */ + object: "text_completion"; + + /** Usage statistics for the completion request. */ usage?: CompletionUsage; } + +alias COMPLETION_MODELS = + | "gpt-3.5-turbo-instruct" + | "davinci-002" + | "babbage-002"; + +@oneOf +union Prompt { + string, + string[], + TokenArray, + TokenArrayArray, +} \ No newline at end of file diff --git a/completions/operations.tsp b/completions/operations.tsp index d53245f7c..b24f018df 100644 --- a/completions/operations.tsp +++ b/completions/operations.tsp @@ -3,30 +3,18 @@ import "@typespec/openapi"; import "../common/errors.tsp"; import "./models.tsp"; -import "./chat-meta.tsp"; using TypeSpec.Http; using TypeSpec.OpenAPI; namespace OpenAI; -@route("/chat") -namespace Chat { - @route("/completions") - interface Completions { - @tag("OpenAI") - @post - @operationId("createChatCompletion") - createChatCompletion( - ...CreateChatCompletionRequest, - ): CreateChatCompletionResponse | ErrorResponse; - } -} @route("/completions") interface Completions { - @tag("OpenAI") @post @operationId("createCompletion") + @tag("Completions") + @summary("Creates a completion for the provided prompt and parameters.") createCompletion( ...CreateCompletionRequest, ): CreateCompletionResponse | ErrorResponse; diff --git a/edits/models.tsp b/edits/models.tsp deleted file mode 100644 index d76372649..000000000 --- a/edits/models.tsp +++ /dev/null @@ -1,69 +0,0 @@ -namespace OpenAI; -using TypeSpec.OpenAPI; - -model CreateEditRequest { - /** - * ID of the model to use. You can use the `text-davinci-edit-001` or `code-davinci-edit-001` - * model with this endpoint. - */ - @extension("x-oaiTypeLabel", "string") - `model`: string | "text-davinci-edit-001" | "code-davinci-edit-001"; - - /** The input text to use as a starting point for the edit. */ - input?: string | null = ""; - - /** The instruction that tells the model how to edit the prompt. */ - instruction: string; - - /** How many edits to generate for the input and instruction. */ - n?: EditN | null = 1; - - /** - * 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. - */ - temperature?: Temperature | null = 1; - - /** - * 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. - */ - top_p?: TopP | null = 1; -} - -#deprecated "deprecated" -model CreateEditResponse { - /** The object type, which is always `edit`. */ - object: "edit"; - - /** The Unix timestamp (in seconds) of when the edit was created. */ - @encode("unixTimestamp", int32) - created: utcDateTime; - - /** description: A list of edit choices. Can be more than one if `n` is greater than 1. */ - choices: { - /** The edited result. */ - text: string; - - /** The index of the choice in the list of choices. */ - index: safeint; - - /** - * The reason the model stopped generating tokens. This will be `stop` if the model hit a - * natural stop point or a provided stop sequence, or `length` if the maximum number of tokens - * specified in the request was reached. - */ - finish_reason: "stop" | "length"; - }[]; - - usage: CompletionUsage; -} - -@minValue(0) -@maxValue(20) -scalar EditN extends safeint; diff --git a/edits/operations.tsp b/edits/operations.tsp deleted file mode 100644 index 08497364e..000000000 --- a/edits/operations.tsp +++ /dev/null @@ -1,19 +0,0 @@ -import "@typespec/http"; -import "@typespec/openapi"; - -import "../common/errors.tsp"; -import "./models.tsp"; - -using TypeSpec.Http; -using TypeSpec.OpenAPI; - -namespace OpenAI; - -@route("/edits") -interface Edits { - #deprecated "deprecated" - @post - @tag("OpenAI") - @operationId("createEdit") - createEdit(@body edit: CreateEditRequest): CreateEditResponse | ErrorResponse; -} diff --git a/embeddings/meta.tsp b/embeddings/meta.tsp new file mode 100644 index 000000000..284eb01dc --- /dev/null +++ b/embeddings/meta.tsp @@ -0,0 +1,24 @@ +import "./models.tsp"; +import "./operations.tsp"; + +using TypeSpec.OpenAPI; + +namespace OpenAI; + +@@extension(OpenAI.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 + } + """ +); \ No newline at end of file diff --git a/embeddings/models.tsp b/embeddings/models.tsp index ab46275b2..fd9c13fde 100644 --- a/embeddings/models.tsp +++ b/embeddings/models.tsp @@ -1,33 +1,58 @@ import "../common/models.tsp"; -namespace OpenAI; using TypeSpec.OpenAPI; -model CreateEmbeddingRequest { - /** 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. */ - @extension("x-oaiTypeLabel", "string") - `model`: string | "text-embedding-ada-002"; +namespace OpenAI; +model CreateEmbeddingRequest { /** * 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. Each input must not exceed - * the max input tokens for the model (8191 tokens for `text-embedding-ada-002`) and cannot be an empty string. + * the max input tokens for the model (8191 tokens for `text-embedding-ada-002`) and cannot be an + * empty string. * [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) * for counting tokens. */ - input: string | string[] | TokenArray | TokenArrayArray; + @extension("x-oaiExpandable", true) + input: CreateEmbeddingRequestInput; + + /** + * 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. + */ + @extension("x-oaiTypeLabel", "string") + `model`: string | EMBEDDINGS_MODELS; + + /** + * The format to return the embeddings in. Can be either `float` or + * [`base64`](https://pypi.org/project/pybase64/). + */ + encoding_format?: "float" | "base64" = "float"; + /** + * The number of dimensions the resulting output embeddings should have. Only supported in + * `text-embedding-3` and later models. + */ + @minValue(1) + dimensions?: safeint; + + /** + * 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). + */ user?: User; } -model CreateEmbeddingResponse { - /** The object type, which is always "embedding". */ - object: "embedding"; - - /** The name of the model used to generate the embedding. */ - `model`: string; +model CreateEmbeddingResponse { /** The list of embeddings generated by the model. */ data: Embedding[]; + + /** The name of the model used to generate the embedding. */ + `model`: string; + + /** The object type, which is always "list". */ + object: "list"; /** The usage information for the request. */ usage: { @@ -39,17 +64,38 @@ model CreateEmbeddingResponse { }; } +alias EMBEDDINGS_MODELS = + | "text-embedding-ada-002" + | "text-embedding-3-small" + | "text-embedding-3-large"; + +@oneOf +union CreateEmbeddingRequestInput +{ + /** The string that will be turned into an embedding. */ + string, + + /** The array of strings that will be turned into an embedding. */ + string[], + + /** The array of integers that will be turned into an embedding. */ + TokenArray, + + /** The array of arrays containing integers that will be turned into an embedding. */ + TokenArrayArray; +} + /** Represents an embedding vector returned by embedding endpoint. */ model Embedding { /** The index of the embedding in the list of embeddings. */ index: safeint; - /** The object type, which is always "embedding". */ - object: "embedding"; - /** - * The embedding vector, which is a list of floats. The length of vector depends on the model as\ + * 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). */ - embedding: float64[]; + embedding: float64[] | string; + + /** The object type, which is always "embedding". */ + object: "embedding"; } diff --git a/embeddings/operations.tsp b/embeddings/operations.tsp index 012d97c58..61c8e1839 100644 --- a/embeddings/operations.tsp +++ b/embeddings/operations.tsp @@ -11,10 +11,10 @@ namespace OpenAI; @route("/embeddings") interface Embeddings { - @tag("OpenAI") - @summary("Creates an embedding vector representing the input text.") @post @operationId("createEmbedding") + @tag("Embeddings") + @summary("Creates an embedding vector representing the input text.") createEmbedding( @body embedding: CreateEmbeddingRequest, ): CreateEmbeddingResponse | ErrorResponse; diff --git a/files/meta.tsp b/files/meta.tsp new file mode 100644 index 000000000..d1c14977b --- /dev/null +++ b/files/meta.tsp @@ -0,0 +1,22 @@ +import "./models.tsp"; +import "./operations.tsp"; + +using TypeSpec.OpenAPI; + +namespace OpenAI; + +@@extension(OpenAI.OpenAIFile, + "x-oaiMeta", + """ + name: The file object + example: | + { + "id": "file-abc123", + "object": "file", + "bytes": 120000, + "created_at": 1677610602, + "filename": "salesOverview.pdf", + "purpose": "assistants", + } + """ +); \ No newline at end of file diff --git a/files/models.tsp b/files/models.tsp index 990c1ea11..fdd2b1f45 100644 --- a/files/models.tsp +++ b/files/models.tsp @@ -1,70 +1,75 @@ -namespace OpenAI; using TypeSpec.OpenAPI; -model ListFilesResponse { - object: string; // presumably this is always some constant, but not defined. - data: OpenAIFile[]; -} +namespace OpenAI; model CreateFileRequest { /** - * Name of the [JSON Lines](https://jsonlines.readthedocs.io/en/latest/) file to be uploaded. - * - * If the `purpose` is set to "fine-tune", the file will be used for fine-tuning. + * The file object (not file name) to be uploaded. */ @encode("binary") file: bytes; /** - * The intended purpose of the uploaded documents. Use "fine-tune" for - * [fine-tuning](/docs/api-reference/fine-tuning). This allows us to validate the format of the - * uploaded file. + * The intended purpose of the uploaded file. Use "fine-tune" for + * [Fine-tuning](/docs/api-reference/fine-tuning) and "assistants" for + * [Assistants](/docs/api-reference/assistants) and [Messages](/docs/api-reference/messages). This + * allows us to validate the format of the uploaded file is correct for fine-tuning. */ - purpose: string; + purpose: "fine-tune" | "assistants"; +} + +model ListFilesResponse { + data: OpenAIFile[]; + object: "list"; +} + +model DeleteFileResponse { + id: string; + object: "file"; + deleted: boolean; } +alias FILE_PURPOSE = + | "fine-tune" + | "fine-tune-results" + | "assistants" + | "assistants_output"; + /** The `File` object represents a document that has been uploaded to OpenAI. */ model OpenAIFile { /** The file identifier, which can be referenced in the API endpoints. */ id: string; - /** The object type, which is always "file". */ - object: "file"; - - /** The size of the file in bytes. */ + /** The size of the file, in bytes. */ bytes: safeint; /** The Unix timestamp (in seconds) for when the file was created. */ @encode("unixTimestamp", int32) - createdAt: utcDateTime; + created_at: utcDateTime; /** The name of the file. */ filename: string; - /** The intended purpose of the file. Currently, only "fine-tune" is supported. */ - purpose: string; + /** The object type, which is always "file". */ + object: "file"; - /** - * The current status of the file, which can be either `uploaded`, `processed`, `pending`, - * `error`, `deleting` or `deleted`. + /** + * The intended purpose of the file. Supported values are `fine-tune`, `fine-tune-results`, + * `assistants`, and `assistants_output`. */ - status: - | "uploaded" - | "processed" - | "pending" - | "error" - | "deleting" - | "deleted"; + purpose: FILE_PURPOSE; /** - * Additional details about the status of the file. If the file is in the `error` state, this will - * include a message describing the error. + * Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or + * `error`. */ - status_details?: string | null; -} + #deprecated "deprecated" + status: "uploaded" | "processed" | "error"; -model DeleteFileResponse { - id: string; - object: string; - deleted: boolean; -} + /** + * Deprecated. For details on why a fine-tuning training file failed validation, see the `error` + * field on `fine_tuning.job`. + */ + #deprecated "deprecated" + status_details?: string; +} \ No newline at end of file diff --git a/files/operations.tsp b/files/operations.tsp index 2e601ae03..dda5f95b8 100644 --- a/files/operations.tsp +++ b/files/operations.tsp @@ -11,48 +11,61 @@ namespace OpenAI; @route("/files") interface Files { - @tag("OpenAI") - @get - @summary("Returns a list of files that belong to the user's organization.") - @operationId("listFiles") - listFiles(): ListFilesResponse | ErrorResponse; - - @tag("OpenAI") @post - @summary("Returns a list of files that belong to the user's organization.") @operationId("createFile") + @tag("Files") + @summary(""" + Upload a file that can be used across various endpoints. The size of all the files uploaded by + one organization can be up to 100 GB. + + The size of individual files can be a maximum of 512 MB or 2 million tokens for Assistants. See + the [Assistants Tools guide](/docs/assistants/tools) to learn more about the types of files + supported. The Fine-tuning API only supports `.jsonl` files. + + Please [contact us](https://help.openai.com/) if you need to increase these storage limits. + """) createFile( @header contentType: "multipart/form-data", @body file: CreateFileRequest, ): OpenAIFile | ErrorResponse; - @tag("OpenAI") - @post - @summary("Returns information about a specific file.") + @get + @operationId("listFiles") + @tag("Files") + @summary("Returns a list of files that belong to the user's organization.") + listFiles( + /** Only return files with the given purpose. */ + // NOTE: This is just a string in the OpenAPI spec. + @query purpose?: FILE_PURPOSE, + ): ListFilesResponse | ErrorResponse; + + @route("{file_id}") + @get @operationId("retrieveFile") - @route("/files/{file_id}") + @tag("Files") + @summary("Returns information about a specific file.") retrieveFile( /** The ID of the file to use for this request. */ @path file_id: string, ): OpenAIFile | ErrorResponse; - @tag("OpenAI") + @route("{file_id}") @delete - @summary("Delete a file") @operationId("deleteFile") - @route("/files/{file_id}") + @tag("Files") + @summary("Delete a file") deleteFile( /** The ID of the file to use for this request. */ @path file_id: string, ): DeleteFileResponse | ErrorResponse; - @route("/files/{file_id}/content") - @tag("OpenAI") + @route("{file_id}/content") @get - @summary("Returns the contents of the specified file.") @operationId("downloadFile") + @tag("Files") + @summary("Returns the contents of the specified file.") downloadFile( /** The ID of the file to use for this request. */ @path file_id: string, - ): string | ErrorResponse; + ): string | ErrorResponse; // TODO: The OpenAPI spec says this is a string but the Content-Type is application/json? } diff --git a/fine-tuning/models.tsp b/fine-tuning/models.tsp index bf846072b..9afce6d02 100644 --- a/fine-tuning/models.tsp +++ b/fine-tuning/models.tsp @@ -1,6 +1,9 @@ -namespace OpenAI; +import "../files/models.tsp"; + using TypeSpec.OpenAPI; +namespace OpenAI; + model FineTuningJob { /** The object identifier, which can be referenced in the API endpoints. */ id: string; diff --git a/fine-tuning/operations.tsp b/fine-tuning/operations.tsp index 15491f62e..07f48e802 100644 --- a/fine-tuning/operations.tsp +++ b/fine-tuning/operations.tsp @@ -22,14 +22,14 @@ namespace FineTuning { * [Learn more about fine-tuning](/docs/guides/fine-tuning) */ @post - @tag("OpenAI") + @tag("Fine-tuning") @operationId("createFineTuningJob") createFineTuningJob( @body job: CreateFineTuningJobRequest, ): FineTuningJob | ErrorResponse; @get - @tag("OpenAI") + @tag("Fine-tuning") @operationId("listPaginatedFineTuningJobs") listPaginatedFineTuningJobs( /** Identifier for the last job from the previous pagination request. */ @@ -45,7 +45,7 @@ namespace FineTuning { [Learn more about fine-tuning](/docs/guides/fine-tuning) """) @route("{fine_tuning_job_id}") - @tag("OpenAI") + @tag("Fine-tuning") @get @operationId("retrieveFineTuningJob") retrieveFineTuningJob( @@ -53,7 +53,7 @@ namespace FineTuning { ): FineTuningJob | ErrorResponse; @summary("Get status updates for a fine-tuning job.") - @tag("OpenAI") + @tag("Fine-tuning") @route("{fine_tuning_job_id}/events") @get @operationId("listFineTuningEvents") @@ -69,7 +69,7 @@ namespace FineTuning { ): ListFineTuningJobEventsResponse | ErrorResponse; @summary("Immediately cancel a fine-tune job.") - @tag("OpenAI") + @tag("Fine-tuning") @route("{fine_tuning_job_id}/cancel") @post @operationId("cancelFineTuningJob") @@ -84,7 +84,7 @@ namespace FineTuning { interface FineTunes { #deprecated "deprecated" @post - @tag("OpenAI") + @tag("Fine-tuning") @summary(""" Creates a job that fine-tunes a specified model from a given dataset. @@ -99,7 +99,7 @@ interface FineTunes { #deprecated "deprecated" @get - @tag("OpenAI") + @tag("Fine-tuning") @summary("List your organization's fine-tuning jobs") @operationId("listFineTunes") listFineTunes(): ListFineTunesResponse | ErrorResponse; @@ -107,7 +107,7 @@ interface FineTunes { #deprecated "deprecated" @get @route("{fine_tune_id}") - @tag("OpenAI") + @tag("Fine-tuning") @summary(""" Gets info about the fine-tune job. @@ -122,7 +122,7 @@ interface FineTunes { #deprecated "deprecated" @route("{fine_tune_id}/events") @get - @tag("OpenAI") + @tag("Fine-tuning") @summary("Get fine-grained status updates for a fine-tune job.") @operationId("listFineTuneEvents") listFineTuneEvents( @@ -144,48 +144,11 @@ interface FineTunes { #deprecated "deprecated" @route("{fine_tune_id}/cancel") @post - @tag("OpenAI") + @tag("Fine-tuning") @summary("Immediately cancel a fine-tune job.") @operationId("cancelFineTune") cancelFineTune( /** The ID of the fine-tune job to cancel */ @path fine_tune_id: string, ): FineTune | ErrorResponse; -} - -@route("/models") -interface Models { - @get - @tag("OpenAI") - @summary(""" - Lists the currently available models, and provides basic information about each one such as the - owner and availability. - """) - @operationId("listModels") - listModels(): ListModelsResponse | ErrorResponse; - - @get - @route("{model}") - @operationId("retrieveModel") - @tag("OpenAI") - @summary(""" - Retrieves a model instance, providing basic information about the model such as the owner and - permissioning. - """) - retrieve( - /** The ID of the model to use for this request. */ - @path `model`: string, - ): Model | ErrorResponse; - - @delete - @route("{model}") - @operationId("deleteModel") - @tag("OpenAI") - @summary(""" - Delete a fine-tuned model. You must have the Owner role in your organization to delete a model. - """) - delete( - /** The model to delete */ - @path `model`: string, - ): DeleteModelResponse | ErrorResponse; -} +} \ No newline at end of file diff --git a/images/meta.tsp b/images/meta.tsp new file mode 100644 index 000000000..79e02b4ee --- /dev/null +++ b/images/meta.tsp @@ -0,0 +1,18 @@ +import "./models.tsp"; +import "./operations.tsp"; + +using TypeSpec.OpenAPI; + +namespace OpenAI; + +@@extension(OpenAI.Image, + "x-oaiMeta", + """ + name: "The image object", + example: | + { + "url": "...", + "revised_prompt": "..." + } + """ +); \ No newline at end of file diff --git a/images/models.tsp b/images/models.tsp index 3d7020b51..e308ade23 100644 --- a/images/models.tsp +++ b/images/models.tsp @@ -1,51 +1,58 @@ import "../common/models.tsp"; -namespace OpenAI; using TypeSpec.OpenAPI; -alias SharedImageProperties = { - /** The number of images to generate. Must be between 1 and 10. */ - n?: ImagesN | null = 1; - - /** The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. */ - size?: IMAGE_SIZES | null = "1024x1024"; - - /** The format in which the generated images are returned. Must be one of `url` or `b64_json`. */ - response_format?: "url" | "b64_json" | null = "url"; - - user?: User; -}; +namespace OpenAI; model CreateImageRequest { - /** A text description of the desired image(s). The maximum length is 1000 characters. */ + /** + * 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`. + */ prompt: string; - ...SharedImageProperties; -} + /** The model to use for image generation. */ + @extension("x-oaiTypeLabel", "string") + `model`?: string | "dall-e-2" | "dall-e-3" = "dall-e-2"; -model ImagesResponse { - @encode("unixTimestamp", int32) - created: utcDateTime; + /** + * The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only `n=1` is + * supported. + */ + // TODO: This is generated as a "oneOf" in the tsp-output? + n?: ImagesN | null = 1; - data: Image[]; -} + /** + * 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`. + */ + // NOTE: This is not marked as nullable in the OpenAPI spec. + quality?: "standard" | "hd" | null = "standard"; -alias IMAGE_SIZES = "256x256" | "512x512" | "1024x1024"; + /** The format in which the generated images are returned. Must be one of `url` or `b64_json`. */ + response_format?: "url" | "b64_json" | null = "url"; -/** Represents the url or the content of an image generated by the OpenAI API. */ -model Image { - /** The URL of the generated image, if `response_format` is `url` (default). */ - url?: 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. + */ + size?: "256x256" | "512x512" | "1024x1024" | "1792x1024" | "1024x1792" | null = "1024x1024"; - /** The base64-encoded JSON of the generated image, if `response_format` is `b64_json`. */ - @encode("base64", string) - b64_json?: bytes; + /** + * 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`. + */ + style?: "vivid" | "natural" | null = "vivid"; + + /** + * 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). + */ + user?: User; } model CreateImageEditRequest { - /** A text description of the desired image(s). The maximum length is 1000 characters. */ - prompt: string; - /** * 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. @@ -53,6 +60,11 @@ model CreateImageEditRequest { @encode("binary") image: bytes; + /** A text description of the desired image(s). The maximum length is 1000 characters. */ + // NOTE: Max length is not defined in the OpenAI spec but mentioned in the description. + @maxLength(1000) + prompt: string; + /** * 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 @@ -61,7 +73,26 @@ model CreateImageEditRequest { @encode("binary") mask?: bytes; - ...SharedImageProperties; + /** The model to use for image generation. Only `dall-e-2` is supported at this time. */ + @extension("x-oaiTypeLabel", "string") + `model`?: string | "dall-e-2" = "dall-e-2"; + + /** + * The number of images to generate. Must be between 1 and 10. + */ + n?: ImagesN | null = 1; + + /** The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. */ + size?: "256x256" | "512x512" | "1024x1024" | null = "1024x1024"; + + /** The format in which the generated images are returned. Must be one of `url` or `b64_json`. */ + response_format?: "url" | "b64_json" | null = "url"; + + /** + * 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). + */ + user?: User; } model CreateImageVariationRequest { @@ -72,9 +103,49 @@ model CreateImageVariationRequest { @encode("binary") image: bytes; - ...SharedImageProperties; + /** The model to use for image generation. Only `dall-e-2` is supported at this time. */ + @extension("x-oaiTypeLabel", "string") + `model`?: string | "dall-e-2" = "dall-e-2"; + + /** + * The number of images to generate. Must be between 1 and 10. + */ + n?: ImagesN | null = 1; + + /** The format in which the generated images are returned. Must be one of `url` or `b64_json`. */ + response_format?: "url" | "b64_json" | null = "url"; + + /** The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. */ + size?: "256x256" | "512x512" | "1024x1024" | null = "1024x1024"; + + /** + * 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). + */ + user?: User; +} + +model ImagesResponse { + @encode("unixTimestamp", int32) + created: utcDateTime; + + data: Image[]; } @minValue(1) @maxValue(10) scalar ImagesN extends safeint; + +/** Represents the url or the content of an image generated by the OpenAI API. */ +model Image { + /** The base64-encoded JSON of the generated image, if `response_format` is `b64_json`. */ + @encode("base64", string) + b64_json?: bytes; + + /** The URL of the generated image, if `response_format` is `url` (default). */ + url?: url; + + /** The prompt that was used to generate the image, if there was any revision to the prompt. */ + revised_prompt?: string; +} + diff --git a/images/operations.tsp b/images/operations.tsp index 09203262b..4db5886ae 100644 --- a/images/operations.tsp +++ b/images/operations.tsp @@ -14,14 +14,16 @@ interface Images { @route("generations") @post @operationId("createImage") - @tag("OpenAI") + @tag("Images") @summary("Creates an image given a prompt") - createImage(@body image: CreateImageRequest): ImagesResponse | ErrorResponse; + createImage( + @body image: CreateImageRequest + ): ImagesResponse | ErrorResponse; @route("edits") @post @operationId("createImageEdit") - @tag("OpenAI") + @tag("Images") @summary("Creates an edited or extended image given an original image and a prompt.") createImageEdit( @header contentType: "multipart/form-data", @@ -31,7 +33,7 @@ interface Images { @route("variations") @post @operationId("createImageVariation") - @tag("OpenAI") + @tag("Images") @summary("Creates an edited or extended image given an original image and a prompt.") createImageVariation( @header contentType: "multipart/form-data", diff --git a/main.tsp b/main.tsp index 2ea8cbbc3..604a75f8c 100644 --- a/main.tsp +++ b/main.tsp @@ -3,13 +3,18 @@ import "@typespec/openapi3"; import "@typespec/openapi"; import "./audio"; +import "./assistants"; +import "./chat"; import "./completions"; -import "./edits"; import "./embeddings"; import "./files"; import "./fine-tuning"; import "./images"; -import "./moderation"; +import "./messages"; +import "./models"; +import "./moderations"; +import "./runs"; +import "./threads"; using TypeSpec.Http; diff --git a/messages/main.tsp b/messages/main.tsp new file mode 100644 index 000000000..6a754bcb5 --- /dev/null +++ b/messages/main.tsp @@ -0,0 +1 @@ +import "./operations.tsp"; \ No newline at end of file diff --git a/messages/meta.tsp b/messages/meta.tsp new file mode 100644 index 000000000..682702c76 --- /dev/null +++ b/messages/meta.tsp @@ -0,0 +1,52 @@ +import "./models.tsp"; + +import "@typespec/openapi"; + +using TypeSpec.OpenAPI; + +namespace OpenAI; + +@@extension(OpenAI.MessageObject, + "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": [] + } + } + ], + "file_ids": [], + "assistant_id": "asst_abc123", + "run_id": "run_abc123", + "metadata": {} + } + """ +); + +@@extension(OpenAI.MessageFileObject, + "x-oaiMeta", + """ + name: The message file object + beta: true + example: | + { + "id": "file-abc123", + "object": "thread.message.file", + "created_at": 1698107661, + "message_id": "message_QLoItBbqwyAJEzlTy4y9kOMM", + "file_id": "file-abc123" + } + """ +); \ No newline at end of file diff --git a/messages/models.tsp b/messages/models.tsp new file mode 100644 index 000000000..67d78db29 --- /dev/null +++ b/messages/models.tsp @@ -0,0 +1,212 @@ +import "../common/models.tsp"; + +using TypeSpec.Http; +using TypeSpec.OpenAPI; + +namespace OpenAI; + +model CreateMessageRequest { + /** The role of the entity that is creating the message. Currently only `user` is supported. */ + role: "user"; // TODO: The generated spec add "assistants" to this enum. + + /** The content of the message. */ + @minLength(1) + @maxLength(32768) + content: string; + + /** + * A list of [File](/docs/api-reference/files) IDs that the message should use. There can be a + * maximum of 10 files attached to a message. Useful for tools like `retrieval` and + * `code_interpreter` that can access and use files. + */ + @minItems(1) + @maxItems(10) + file_ids?: string[] = []; + + /** + * 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. + */ + @extension("x-oaiTypeLabel", "map") + metadata?: Record | null; +} + +model ModifyMessageRequest { + /** + * 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. + */ + @extension("x-oaiTypeLabel", "map") + metadata?: Record | null; +} + +model ListMessagesResponse { + object: "list"; + data: MessageObject[]; + first_id: string; + last_id: string; + has_more: boolean; +} + +model ListMessageFilesResponse { + object: "list"; + data: MessageFileObject[]; + first_id: string; + last_id: string; + has_more: boolean; +} + +model MessageObject { + /** The identifier, which can be referenced in API endpoints. */ + id: string; + + /** The object type, which is always `thread.message`. */ + object: "thread.message"; + + /** The Unix timestamp (in seconds) for when the message was created. */ + @encode("unixTimestamp", int32) + created_at: utcDateTime; + + /** The [thread](/docs/api-reference/threads) ID that this message belongs to. */ + thread_id: string; + + /** The entity that produced the message. One of `user` or `assistant`. */ + role: "user" | "assistant"; + + /** The content of the message in array of text and/or images. */ + content: MessageObjectContent[]; + + /** + * If applicable, the ID of the [assistant](/docs/api-reference/assistants) that authored this + * message. + */ + assistant_id: string | null; + + /** + * If applicable, the ID of the [run](/docs/api-reference/runs) associated with the authoring of + * this message. + */ + run_id: string | null; + + /** + * A list of [file](/docs/api-reference/files) IDs that the assistant should use. Useful for + * tools like retrieval and code_interpreter that can access files. A maximum of 10 files can be + * attached to a message. + */ + @maxItems(10) + file_ids: string[] = []; + + /** + * 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. + */ + @extension("x-oaiTypeLabel", "map") + metadata: Record | null; +} + +@oneOf +@extension("x-oaiExpandable", true) +union MessageObjectContent { + MessageContentImageFileObject, + MessageContentTextObject, +} + +/** References an image [File](/docs/api-reference/files) in the content of a message. */ +model MessageContentImageFileObject { + /** Always `image_file`. */ + type: "image_file"; + + image_file: { + /** The [File](/docs/api-reference/files) ID of the image in the message content. */ + file_id: string; + } +} + +/** The text content that is part of a message. */ +model MessageContentTextObject { + /** Always `text`. */ + type: "text"; // TODO: The generated spec adds "json_object" to this enum. + + text: { + /** The data that makes up the text. */ + value: string; + + annotations: MessageContentTextObjectAnnotations[]; + } +} + +@oneOf +@extension("x-oaiExpandable", true) +union MessageContentTextObjectAnnotations { + MessageContentTextAnnotationsFileCitationObject, + MessageContentTextAnnotationsFilePathObject, +} + +/** + * 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 "retrieval" tool to + * search files. + */ +model MessageContentTextAnnotationsFileCitationObject { + /** Always `file_citation`. */ + type: "file_citation"; + + /** The text in the message content that needs to be replaced. */ + text: string; + + file_citation: { + /** The ID of the specific File the citation is from. */ + file_id: string; + + /** The specific quote in the file. */ + quote: string; + }; + + @minValue(0) + start_index: safeint; + + @minValue(0) + end_index: safeint; +} + +/** + * A URL for the file that's generated when the assistant used the `code_interpreter` tool to + * generate a file. + */ +model MessageContentTextAnnotationsFilePathObject { + /** Always `file_path`. */ + type: "file_path"; + + /** The text in the message content that needs to be replaced. */ + text: string; + + file_path: { + /** The ID of the file that was generated. */ + file_id: string; + }; + + @minValue(0) + start_index: safeint; + + @minValue(0) + end_index: safeint; +} + +/** A list of files attached to a `message`. */ +model MessageFileObject { + /** TThe identifier, which can be referenced in API endpoints. */ + id: string; + + /** The object type, which is always `thread.message.file`. */ + object: "thread.message.file"; + + /** The Unix timestamp (in seconds) for when the message file was created. */ + @encode("unixTimestamp", int32) + created_at: utcDateTime; + + /** The ID of the [message](/docs/api-reference/messages) that the [File](/docs/api-reference/files) is attached to. */ + message_id: string; +} \ No newline at end of file diff --git a/messages/operations.tsp b/messages/operations.tsp new file mode 100644 index 000000000..0c9843e0a --- /dev/null +++ b/messages/operations.tsp @@ -0,0 +1,142 @@ +import "@typespec/http"; +import "@typespec/openapi"; + +import "../common/errors.tsp"; +import "./models.tsp"; + +using TypeSpec.Http; +using TypeSpec.OpenAPI; + +namespace OpenAI; + +@route("threads/{thread_id}/messages") +interface Messages { + @post + @operationId("createMessage") + @tag("Assistants") + @summary("Create a message.") + createMessage( + /** The ID of the [thread](/docs/api-reference/threads) to create a message for. */ + @path thread_id: string, + + @body message: CreateMessageRequest, + ): MessageObject | ErrorResponse; + + @get + @operationId("listMessages") + @tag("Assistants") + @summary("Returns a list of messages for a given thread.") + listMessages( + /** The ID of the [thread](/docs/api-reference/threads) the messages belong to. */ + @path thread_id: string, + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + * default is 20. + */ + @query limit?: int32 = 20; + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc` + * for descending order. + */ + @query order?: "asc" | "desc" = "desc"; + + /** + * 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. + */ + @query after?: string; + + /** + * 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. + */ + @query before?: string; + ): ListMessagesResponse | ErrorResponse; + + @route("{message_id}") + @get + @operationId("getMessage") + @tag("Assistants") + @summary("Retrieve a message.") + getMessage( + /** The ID of the [thread](/docs/api-reference/threads) to which this message belongs. */ + @path thread_id: string, + + /** The ID of the message to retrieve. */ + @path message_id: string, + ): MessageObject | ErrorResponse; + + @route("{message_id}") + @post + @operationId("modifyMessage") + @tag("Assistants") + @summary("Modifies a message.") + modifyMessage( + /** The ID of the thread to which this message belongs. */ + @path thread_id: string, + + /** The ID of the message to modify. */ + @path message_id: string, + + @body message: ModifyMessageRequest, + ): MessageObject | ErrorResponse; + + @route("{message_id}/files") + @get + @operationId("listMessageFiles") + @tag("Assistants") + @summary("Returns a list of message files.") + listMessageFiles( + /** The ID of the thread that the message and files belong to. */ + @path thread_id: string, + + /** The ID of the message that the files belongs to. */ + @path message_id: string, + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + * default is 20. + */ + @query limit?: int32 = 20; + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc` + * for descending order. + */ + @query order?: "asc" | "desc" = "desc"; + + /** + * 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. + */ + @query after?: string; + + /** + * 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. + */ + @query before?: string; + ): ListMessageFilesResponse | ErrorResponse; + + @route("{message_id}/files/{file_id}") + @get + @operationId("getMessageFile") + @tag("Assistants") + @summary("Retrieves a message file.") + getMessageFile( + /** The ID of the thread to which the message and File belong. */ + @path thread_id: string, + + /** The ID of the message the file belongs to. */ + @path message_id: string, + + /** The ID of the file being retrieved. */ + @path file_id: string, + ): MessageFileObject | ErrorResponse; +} diff --git a/models/main.tsp b/models/main.tsp new file mode 100644 index 000000000..6a754bcb5 --- /dev/null +++ b/models/main.tsp @@ -0,0 +1 @@ +import "./operations.tsp"; \ No newline at end of file diff --git a/models/meta.tsp b/models/meta.tsp new file mode 100644 index 000000000..cf8dd65dc --- /dev/null +++ b/models/meta.tsp @@ -0,0 +1,15 @@ +import "./models.tsp"; +import "./operations.tsp"; + +using TypeSpec.OpenAPI; + +namespace OpenAI; + +// TODO: Fill in example here. +@@extension(OpenAI.Model, + "x-oaiMeta", + """ + name: "The model object", + example: "*retrieve_model_response" + """ +); \ No newline at end of file diff --git a/models/models.tsp b/models/models.tsp new file mode 100644 index 000000000..f522ca893 --- /dev/null +++ b/models/models.tsp @@ -0,0 +1,30 @@ +using TypeSpec.OpenAPI; + +namespace OpenAI; + +model ListModelsResponse { + object: "list"; + data: Model[]; +} + +model DeleteModelResponse { + id: string; + deleted: boolean; + object: "model"; // NOTE: This is just a string in the OpenAPI spec, no enum. +} + +/** Describes an OpenAI model offering that can be used with the API. */ +model Model { + /** The model identifier, which can be referenced in the API endpoints. */ + id: string; + + /** The Unix timestamp (in seconds) when the model was created. */ + @encode("unixTimestamp", int32) + created: utcDateTime; + + /** The object type, which is always "model". */ + object: "model"; + + /** The organization that owns the model. */ + owned_by: string; +} \ No newline at end of file diff --git a/models/operations.tsp b/models/operations.tsp new file mode 100644 index 000000000..74f91f332 --- /dev/null +++ b/models/operations.tsp @@ -0,0 +1,47 @@ +import "@typespec/http"; +import "@typespec/openapi"; + +import "../common/errors.tsp"; +import "./models.tsp"; + +using TypeSpec.Http; +using TypeSpec.OpenAPI; + +namespace OpenAI; + +@route("/models") +interface Models { + @get + @operationId("listModels") + @tag("Models") + @summary(""" + Lists the currently available models, and provides basic information about each one such as the + owner and availability. + """) + listModels(): ListModelsResponse | ErrorResponse; + + @route("{model}") + @get + @operationId("retrieveModel") + @tag("Models") + @summary(""" + Retrieves a model instance, providing basic information about the model such as the owner and + permissioning. + """) + retrieve( + /** The ID of the model to use for this request. */ + @path `model`: string, + ): Model | ErrorResponse; + + @route("{model}") + @delete + @operationId("deleteModel") + @tag("Models") + @summary(""" + Delete a fine-tuned model. You must have the Owner role in your organization to delete a model. + """) + delete( + /** The model to delete */ + @path `model`: string, + ): DeleteModelResponse | ErrorResponse; +} diff --git a/moderation/main.tsp b/moderations/main.tsp similarity index 100% rename from moderation/main.tsp rename to moderations/main.tsp diff --git a/moderations/meta.tsp b/moderations/meta.tsp new file mode 100644 index 000000000..7d96cda38 --- /dev/null +++ b/moderations/meta.tsp @@ -0,0 +1,15 @@ +import "./models.tsp"; +import "./operations.tsp"; + +using TypeSpec.OpenAPI; + +namespace OpenAI; + +// TODO: Fill in example here. +@@extension(OpenAI.CreateModerationResponse, + "x-oaiMeta", + """ + name: "The moderation object", + example: "*moderation_example" + """ +); \ No newline at end of file diff --git a/moderation/models.tsp b/moderations/models.tsp similarity index 90% rename from moderation/models.tsp rename to moderations/models.tsp index f47b21be1..b844b2659 100644 --- a/moderation/models.tsp +++ b/moderations/models.tsp @@ -1,9 +1,10 @@ -namespace OpenAI; using TypeSpec.OpenAPI; +namespace OpenAI; + model CreateModerationRequest { /** The input text to classify */ - input: string | string[]; + input: CreateModerationRequestInput; /** * Two content moderations models are available: `text-moderation-stable` and @@ -13,9 +14,12 @@ model CreateModerationRequest { * of `text-moderation-stable` may be slightly lower than for `text-moderation-latest`. */ @extension("x-oaiTypeLabel", "string") - `model`?: string | "text-moderation-latest" | "text-moderation-stable" = "text-moderation-latest"; + `model`?: string | MODERATION_MODELS = "text-moderation-latest"; } +/** + * Represents policy compliance report by OpenAI's content moderation model against a given input. + */ model CreateModerationResponse { /** The unique identifier for the moderation request. */ id: string; @@ -66,7 +70,7 @@ model CreateModerationResponse { * 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. */ - `self-harm/instructive`: boolean; + `self-harm/instructions`: boolean; /** * Content meant to arouse sexual excitement, such as the description of sexual activity, or @@ -105,7 +109,7 @@ model CreateModerationResponse { `self-harm/intent`: float64; /** The score for the category 'self-harm/instructive'. */ - `self-harm/instructive`: float64; + `self-harm/instructions`: float64; /** The score for the category 'sexual'. */ sexual: float64; @@ -121,3 +125,13 @@ model CreateModerationResponse { }; }[]; } + +alias MODERATION_MODELS = + | "text-moderation-latest" + | "text-moderation-stable"; + +@oneOf +union CreateModerationRequestInput { + string, + string[] +} \ No newline at end of file diff --git a/moderation/operations.tsp b/moderations/operations.tsp similarity index 93% rename from moderation/operations.tsp rename to moderations/operations.tsp index 5f29bc3be..7760ec2b2 100644 --- a/moderation/operations.tsp +++ b/moderations/operations.tsp @@ -11,8 +11,9 @@ namespace OpenAI; @route("/moderations") interface Moderations { + @post @operationId("createModeration") - @tag("OpenAI") + @tag("Moderations") @summary("Classifies if text violates OpenAI's Content Policy") createModeration( @body content: CreateModerationRequest, diff --git a/openapi.yaml b/openapi.yaml index 011ccf375..a6e16ee12 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -13,8 +13,26 @@ info: servers: - url: https://api.openai.com/v1 tags: - - name: OpenAI - description: The OpenAI REST API + - name: Assistants + description: Build Assistants that can call models and use tools. + - name: Audio + description: Learn how to 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: Files + description: Files are used to upload documents that can be used with features like Assistants and Fine-tuning. + - 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 violating OpenAI's content policy. 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 @@ -22,7 +40,7 @@ paths: post: operationId: createChatCompletion tags: - - OpenAI + - Chat summary: Creates a model response for the given chat conversation. requestBody: required: true @@ -45,7 +63,7 @@ paths: 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: No Streaming + - title: Default request: curl: | curl https://api.openai.com/v1/chat/completions \ @@ -65,11 +83,10 @@ paths: ] }' python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") + from openai import OpenAI + client = OpenAI() - completion = openai.ChatCompletion.create( + completion = client.chat.completions.create( model="VAR_model_id", messages=[ {"role": "system", "content": "You are a helpful assistant."}, @@ -99,12 +116,111 @@ paths: "object": "chat.completion", "created": 1677652288, "model": "gpt-3.5-turbo-0613", + "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-vision-preview", + "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-vision-preview", + 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-vision-preview", + 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 | + { + "id": "chatcmpl-123", + "object": "chat.completion", + "created": 1677652288, + "model": "gpt-3.5-turbo-0613", + "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": { @@ -134,11 +250,10 @@ paths: "stream": true }' python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") + from openai import OpenAI + client = OpenAI() - completion = openai.ChatCompletion.create( + completion = client.chat.completions.create( model="VAR_model_id", messages=[ {"role": "system", "content": "You are a helpful assistant."}, @@ -172,24 +287,403 @@ paths: main(); response: &chat_completion_chunk_example | + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "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-3.5-turbo-0613", "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-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"!"},"logprobs":null,"finish_reason":null}]} + + .... + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":" today"},"logprobs":null,"finish_reason":null}]} + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"?"},"logprobs":null,"finish_reason":null}]} + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "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-3.5-turbo", + "messages": [ + { + "role": "user", + "content": "What is the weather like in Boston?" + } + ], + "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-3.5-turbo", + messages: messages, + tools: tools, + tool_choice: "auto", + }); + + console.log(response); + } + + main(); + response: &chat_completion_function_example | + { + "id": "chatcmpl-abc123", + "object": "chat.completion", + "created": 1699896916, + "model": "gpt-3.5-turbo-0613", + "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.chunk", - "created": 1677652288, - "model": "gpt-3.5-turbo", - "choices": [{ - "index": 0, - "delta": { - "content": "Hello", - }, - "finish_reason": "stop" - }] + "object": "chat.completion", + "created": 1702685778, + "model": "gpt-3.5-turbo-0613", + "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 } + /completions: post: operationId: createCompletion tags: - - OpenAI + - Completions summary: Creates a completion for the provided prompt and parameters. requestBody: required: true @@ -206,6 +700,7 @@ paths: $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 @@ -223,10 +718,10 @@ paths: "temperature": 0 }' python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Completion.create( + from openai import OpenAI + client = OpenAI() + + client.completions.create( model="VAR_model_id", prompt="Say this is a test", max_tokens=7, @@ -254,6 +749,7 @@ paths: "object": "text_completion", "created": 1589478378, "model": "VAR_model_id", + "system_fingerprint": "fp_44709d6fcb", "choices": [ { "text": "\n\nThis is indeed a test", @@ -282,17 +778,17 @@ paths: "stream": true }' python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - for chunk in openai.Completion.create( + 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']) + print(chunk.choices[0].text) node.js: |- import OpenAI from "openai"; @@ -324,90 +820,14 @@ paths: } ], "model": "gpt-3.5-turbo-instruct" + "system_fingerprint": "fp_44709d6fcb", } - /edits: - post: - operationId: createEdit - deprecated: true - tags: - - OpenAI - summary: Creates a new edit for the provided input, instruction, and parameters. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateEditRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/CreateEditResponse" - x-oaiMeta: - name: Create edit - returns: | - Returns an [edit](/docs/api-reference/edits/object) object. - group: edits - examples: - request: - curl: | - curl https://api.openai.com/v1/edits \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "model": "VAR_model_id", - "input": "What day of the wek is it?", - "instruction": "Fix the spelling mistakes" - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Edit.create( - model="VAR_model_id", - input="What day of the wek is it?", - instruction="Fix the spelling mistakes" - ) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const edit = await openai.edits.create({ - model: "VAR_model_id", - input: "What day of the wek is it?", - instruction: "Fix the spelling mistakes.", - }); - - console.log(edit); - } - - main(); - response: &edit_example | - { - "object": "edit", - "created": 1589478378, - "choices": [ - { - "text": "What day of the week is it?", - "index": 0, - } - ], - "usage": { - "prompt_tokens": 25, - "completion_tokens": 32, - "total_tokens": 57 - } - } /images/generations: post: operationId: createImage tags: - - OpenAI + - Images summary: Creates an image given a prompt. requestBody: required: true @@ -424,6 +844,7 @@ paths: $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: @@ -432,17 +853,19 @@ paths: -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ + "model": "dall-e-3", "prompt": "A cute baby sea otter", - "n": 2, + "n": 1, "size": "1024x1024" }' python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Image.create( + from openai import OpenAI + client = OpenAI() + + client.images.generate( + model="dall-e-3", prompt="A cute baby sea otter", - n=2, + n=1, size="1024x1024" ) node.js: |- @@ -451,7 +874,7 @@ paths: const openai = new OpenAI(); async function main() { - const image = await openai.images.generate({ prompt: "A cute baby sea otter" }); + const image = await openai.images.generate({ model: "dall-e-3", prompt: "A cute baby sea otter" }); console.log(image.data); } @@ -468,12 +891,11 @@ paths: } ] } - /images/edits: post: operationId: createImageEdit tags: - - OpenAI + - Images summary: Creates an edited or extended image given an original image and a prompt. requestBody: required: true @@ -490,6 +912,7 @@ paths: $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: @@ -502,10 +925,10 @@ paths: -F n=2 \ -F size="1024x1024" python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Image.create_edit( + 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", @@ -540,12 +963,11 @@ paths: } ] } - /images/variations: post: operationId: createImageVariation tags: - - OpenAI + - Images summary: Creates a variation of a given image. requestBody: required: true @@ -562,6 +984,7 @@ paths: $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: @@ -572,11 +995,11 @@ paths: -F n=2 \ -F size="1024x1024" python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Image.create_variation( - image=open("otter.png", "rb"), + from openai import OpenAI + client = OpenAI() + + response = client.images.create_variation( + image=open("image_edit_original.png", "rb"), n=2, size="1024x1024" ) @@ -611,7 +1034,7 @@ paths: post: operationId: createEmbedding tags: - - OpenAI + - Embeddings summary: Creates an embedding vector representing the input text. requestBody: required: true @@ -628,6 +1051,7 @@ paths: $ref: "#/components/schemas/CreateEmbeddingResponse" x-oaiMeta: name: Create embeddings + group: embeddings returns: A list of [embedding](/docs/api-reference/embeddings/object) objects. examples: request: @@ -637,15 +1061,17 @@ paths: -H "Content-Type: application/json" \ -d '{ "input": "The food was delicious and the waiter...", - "model": "text-embedding-ada-002" + "model": "text-embedding-ada-002", + "encoding_format": "float" }' python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Embedding.create( + from openai import OpenAI + client = OpenAI() + + client.embeddings.create( model="text-embedding-ada-002", - input="The food was delicious and the waiter..." + input="The food was delicious and the waiter...", + encoding_format="float" ) node.js: |- import OpenAI from "openai"; @@ -656,6 +1082,7 @@ paths: 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); @@ -684,74 +1111,149 @@ paths: } } - /audio/transcriptions: + /audio/speech: post: - operationId: createTranscription + operationId: createSpeech tags: - - OpenAI - summary: Transcribes audio into the input language. + - Audio + summary: Generates audio from the input text. requestBody: required: true content: - multipart/form-data: + application/json: schema: - $ref: "#/components/schemas/CreateTranscriptionRequest" + $ref: "#/components/schemas/CreateSpeechRequest" responses: "200": description: OK + headers: + Transfer-Encoding: + schema: + type: string + description: chunked content: - application/json: + application/octet-stream: schema: - $ref: "#/components/schemas/CreateTranscriptionResponse" + type: string + format: binary x-oaiMeta: - name: Create transcription - returns: The transcriped text. + name: Create speech + group: audio + returns: The audio file content. examples: request: curl: | - curl https://api.openai.com/v1/audio/transcriptions \ + curl https://api.openai.com/v1/audio/speech \ -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: multipart/form-data" \ - -F file="@/path/to/file/audio.mp3" \ - -F model="whisper-1" + -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: | - import os + from pathlib import Path import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - audio_file = open("audio.mp3", "rb") - transcript = openai.Audio.transcribe("whisper-1", audio_file) - node: |- + + 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 transcription = await openai.audio.transcriptions.create({ - file: fs.createReadStream("audio.mp3"), - model: "whisper-1", + 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(transcription.text); + console.log(speechFile); + const buffer = Buffer.from(await mp3.arrayBuffer()); + await fs.promises.writeFile(speechFile, buffer); } 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." - } - - /audio/translations: + /audio/transcriptions: post: - operationId: createTranslation + operationId: createTranscription tags: - - OpenAI - summary: Translates audio into English. + - Audio + summary: Transcribes audio into the input language. requestBody: required: true content: multipart/form-data: schema: - $ref: "#/components/schemas/CreateTranslationRequest" + $ref: "#/components/schemas/CreateTranscriptionRequest" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/CreateTranscriptionResponse" + x-oaiMeta: + name: Create transcription + group: audio + returns: The transcribed text. + examples: + 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." + } + /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 @@ -761,6 +1263,7 @@ paths: $ref: "#/components/schemas/CreateTranslationResponse" x-oaiMeta: name: Create translation + group: audio returns: The translated text. examples: request: @@ -771,21 +1274,29 @@ paths: -F file="@/path/to/file/german.m4a" \ -F model="whisper-1" python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - audio_file = open("german.m4a", "rb") - transcript = openai.Audio.translate("whisper-1", audio_file) + from openai import OpenAI + client = OpenAI() + + audio_file = open("speech.mp3", "rb") + transcript = client.audio.translations.create( + model="whisper-1", + file=audio_file + ) node: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const resp = await openai.createTranslation( - fs.createReadStream("audio.mp3"), - "whisper-1" - ); + 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?" @@ -795,8 +1306,15 @@ paths: get: operationId: listFiles tags: - - OpenAI + - 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 @@ -806,17 +1324,18 @@ paths: $ref: "#/components/schemas/ListFilesResponse" x-oaiMeta: name: List files - returns: A list of [file](/docs/api-reference/files/object) objects. + 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: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.File.list() + from openai import OpenAI + client = OpenAI() + + client.files.list() node.js: |- import OpenAI from "openai"; @@ -839,8 +1358,8 @@ paths: "object": "file", "bytes": 175, "created_at": 1613677385, - "filename": "train.jsonl", - "purpose": "search" + "filename": "salesOverview.pdf", + "purpose": "assistants", }, { "id": "file-abc123", @@ -848,7 +1367,7 @@ paths: "bytes": 140, "created_at": 1613779121, "filename": "puppy.jsonl", - "purpose": "search" + "purpose": "fine-tune", } ], "object": "list" @@ -856,10 +1375,13 @@ paths: post: operationId: createFile tags: - - OpenAI + - Files summary: | - Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact us if you need to increase the storage limit. + Upload a file that can be used across various endpoints. The size of all the files uploaded by one organization can be up to 100 GB. + + The size of individual files can be a maximum of 512 MB or 2 million tokens for Assistants. See the [Assistants Tools guide](/docs/assistants/tools) to learn more about the types of files supported. The Fine-tuning API only supports `.jsonl` files. + Please [contact us](https://help.openai.com/) if you need to increase these storage limits. requestBody: required: true content: @@ -875,7 +1397,8 @@ paths: $ref: "#/components/schemas/OpenAIFile" x-oaiMeta: name: Upload file - returns: The uploaded [file](/docs/api-reference/files/object) object. + group: files + returns: The uploaded [File](/docs/api-reference/files/object) object. examples: request: curl: | @@ -884,12 +1407,12 @@ paths: -F purpose="fine-tune" \ -F file="@mydata.jsonl" python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.File.create( + from openai import OpenAI + client = OpenAI() + + client.files.create( file=open("mydata.jsonl", "rb"), - purpose='fine-tune' + purpose="fine-tune" ) node.js: |- import fs from "fs"; @@ -911,18 +1434,16 @@ paths: { "id": "file-abc123", "object": "file", - "bytes": 140, - "created_at": 1613779121, + "bytes": 120000, + "created_at": 1677610602, "filename": "mydata.jsonl", "purpose": "fine-tune", - "status": "uploaded" | "processed" | "pending" | "error" } - /files/{file_id}: delete: operationId: deleteFile tags: - - OpenAI + - Files summary: Delete a file. parameters: - in: path @@ -940,6 +1461,7 @@ paths: $ref: "#/components/schemas/DeleteFileResponse" x-oaiMeta: name: Delete file + group: files returns: Deletion status. examples: request: @@ -948,10 +1470,10 @@ paths: -X DELETE \ -H "Authorization: Bearer $OPENAI_API_KEY" python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.File.delete("file-abc123") + from openai import OpenAI + client = OpenAI() + + client.files.delete("file-abc123") node.js: |- import OpenAI from "openai"; @@ -973,7 +1495,7 @@ paths: get: operationId: retrieveFile tags: - - OpenAI + - Files summary: Returns information about a specific file. parameters: - in: path @@ -991,17 +1513,18 @@ paths: $ref: "#/components/schemas/OpenAIFile" x-oaiMeta: name: Retrieve file - returns: The [file](/docs/api-reference/files/object) object matching the specified ID. + 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: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.File.retrieve("file-abc123") + from openai import OpenAI + client = OpenAI() + + client.files.retrieve("file-abc123") node.js: |- import OpenAI from "openai"; @@ -1018,17 +1541,16 @@ paths: { "id": "file-abc123", "object": "file", - "bytes": 140, - "created_at": 1613779657, + "bytes": 120000, + "created_at": 1677610602, "filename": "mydata.jsonl", - "purpose": "fine-tune" + "purpose": "fine-tune", } - /files/{file_id}/content: get: operationId: downloadFile tags: - - OpenAI + - Files summary: Returns the contents of the specified file. parameters: - in: path @@ -1046,6 +1568,7 @@ paths: type: string x-oaiMeta: name: Retrieve file content + group: files returns: The file content. examples: request: @@ -1053,10 +1576,10 @@ paths: curl https://api.openai.com/v1/files/file-abc123/content \ -H "Authorization: Bearer $OPENAI_API_KEY" > file.jsonl python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - content = openai.File.download("file-abc123") + from openai import OpenAI + client = OpenAI() + + content = client.files.retrieve_content("file-abc123") node.js: | import OpenAI from "openai"; @@ -1074,9 +1597,9 @@ paths: post: operationId: createFineTuningJob tags: - - OpenAI + - Fine-tuning summary: | - Creates a job that fine-tunes a specified model from a given dataset. + 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. @@ -1096,23 +1619,27 @@ paths: $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: No hyperparameters + - 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-abc123" - "model": "gpt-3.5-turbo", + "training_file": "file-BK7bzQj3FfZFXr7DbL6xJwfo", + "model": "gpt-3.5-turbo" }' python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTuningJob.create(training_file="file-abc123", model="gpt-3.5-turbo") + 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"; @@ -1130,7 +1657,7 @@ paths: response: | { "object": "fine_tuning.job", - "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F", + "id": "ftjob-abc123", "model": "gpt-3.5-turbo-0613", "created_at": 1614807352, "fine_tuned_model": null, @@ -1140,24 +1667,30 @@ paths: "validation_file": null, "training_file": "file-abc123", } - - title: Hyperparameters + - 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" + "training_file": "file-abc123", "model": "gpt-3.5-turbo", "hyperparameters": { "n_epochs": 2 } }' python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTuningJob.create(training_file="file-abc123", model="gpt-3.5-turbo", hyperparameters={"n_epochs":2}) + 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"; @@ -1167,7 +1700,7 @@ paths: const fineTune = await openai.fineTuning.jobs.create({ training_file: "file-abc123", model: "gpt-3.5-turbo", - hyperparameters: { n_epochs: 2 }, + hyperparameters: { n_epochs: 2 } }); console.log(fineTune); @@ -1177,7 +1710,7 @@ paths: response: | { "object": "fine_tuning.job", - "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F", + "id": "ftjob-abc123", "model": "gpt-3.5-turbo-0613", "created_at": 1614807352, "fine_tuned_model": null, @@ -1186,12 +1719,60 @@ paths: "status": "queued", "validation_file": null, "training_file": "file-abc123", - "hyperparameters":{"n_epochs":2}, + "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-0613", + "created_at": 1614807352, + "fine_tuned_model": null, + "organization_id": "org-123", + "result_files": [], + "status": "queued", + "validation_file": "file-abc123", + "training_file": "file-abc123", } get: operationId: listPaginatedFineTuningJobs tags: - - OpenAI + - Fine-tuning summary: | List your organization's fine-tuning jobs parameters: @@ -1217,6 +1798,7 @@ paths: $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: @@ -1224,10 +1806,10 @@ paths: curl https://api.openai.com/v1/fine_tuning/jobs?limit=2 \ -H "Authorization: Bearer $OPENAI_API_KEY" python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTuningJob.list() + from openai import OpenAI + client = OpenAI() + + client.fine_tuning.jobs.list() node.js: |- import OpenAI from "openai"; @@ -1263,7 +1845,7 @@ paths: get: operationId: retrieveFineTuningJob tags: - - OpenAI + - Fine-tuning summary: | Get info about a fine-tuning job. @@ -1286,25 +1868,26 @@ paths: $ref: "#/components/schemas/FineTuningJob" x-oaiMeta: name: Retrieve fine-tuning job - returns: The [fine-tuning](/docs/api-reference/fine-tunes/object) object with the given ID. + 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: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTuningJob.retrieve("ft-anaKUAgnnBkNGB3QcSr4pImR") + 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("ft-AF1WoRqd3aJAHsqc9NY7iL8F"); - + const fineTune = await openai.fineTuning.jobs.retrieve("ftjob-abc123"); + console.log(fineTune); } @@ -1312,7 +1895,7 @@ paths: response: &fine_tuning_example | { "object": "fine_tuning.job", - "id": "ft-zRdUkP4QeZqeYjDcQL0wwam1", + "id": "ftjob-abc123", "model": "davinci-002", "created_at": 1692661014, "finished_at": 1692661190, @@ -1329,12 +1912,11 @@ paths: }, "trained_tokens": 5768 } - /fine_tuning/jobs/{fine_tuning_job_id}/events: get: operationId: listFineTuningEvents tags: - - OpenAI + - Fine-tuning summary: | Get status updates for a fine-tuning job. parameters: @@ -1368,24 +1950,28 @@ paths: $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/ft-AF1WoRqd3aJAHsqc9NY7iL8F/events \ + curl https://api.openai.com/v1/fine_tuning/jobs/ftjob-abc123/events \ -H "Authorization: Bearer $OPENAI_API_KEY" python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTuningJob.list_events(id="ft-w9WJrnTe9vcVopaTy9LrlGQv", limit=2) + 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="ft-w9WJrnTe9vcVopaTy9LrlGQv", limit=2); + const list = await openai.fineTuning.list_events(id="ftjob-abc123", limit=2); for await (const fineTune of list) { console.log(fineTune); @@ -1418,12 +2004,11 @@ paths: ], "has_more": true } - /fine_tuning/jobs/{fine_tuning_job_id}/cancel: post: operationId: cancelFineTuningJob tags: - - OpenAI + - Fine-tuning summary: | Immediately cancel a fine-tune job. parameters: @@ -1444,24 +2029,25 @@ paths: $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/ft-AF1WoRqd3aJAHsqc9NY7iL8F/cancel \ + curl -X POST https://api.openai.com/v1/fine_tuning/jobs/ftjob-abc123/cancel \ -H "Authorization: Bearer $OPENAI_API_KEY" python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTuningJob.cancel("ft-anaKUAgnnBkNGB3QcSr4pImR") + 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("ft-AF1WoRqd3aJAHsqc9NY7iL8F"); + const fineTune = await openai.fineTuning.jobs.cancel("ftjob-abc123"); console.log(fineTune); } @@ -1469,7 +2055,7 @@ paths: response: | { "object": "fine_tuning.job", - "id": "ft-gleYLJhWh1YFufiy29AahVpj", + "id": "ftjob-abc123", "model": "gpt-3.5-turbo-0613", "created_at": 1689376978, "fine_tuned_model": null, @@ -1483,2690 +2069,6608 @@ paths: "training_file": "file-abc123" } - /fine-tunes: - post: - operationId: createFineTune - deprecated: true + /models: + get: + operationId: listModels tags: - - OpenAI - summary: | - Creates a job that fine-tunes a specified model from a given dataset. - - Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete. - - [Learn more about fine-tuning](/docs/guides/legacy-fine-tuning) - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateFineTuneRequest" + - 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/FineTune" + $ref: "#/components/schemas/ListModelsResponse" x-oaiMeta: - name: Create fine-tune - returns: A [fine-tune](/docs/api-reference/fine-tunes/object) object. + 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/fine-tunes \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "training_file": "file-abc123" - }' + curl https://api.openai.com/v1/models \ + -H "Authorization: Bearer $OPENAI_API_KEY" python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTune.create(training_file="file-abc123") - node.js: | + from openai import OpenAI + client = OpenAI() + + client.models.list() + node.js: |- import OpenAI from "openai"; const openai = new OpenAI(); async function main() { - const fineTune = await openai.fineTunes.create({ - training_file: "file-abc123" - }); + const list = await openai.models.list(); - console.log(fineTune); + for await (const model of list) { + console.log(model); + } } - main(); response: | { - "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F", - "object": "fine-tune", - "model": "curie", - "created_at": 1614807352, - "events": [ + "object": "list", + "data": [ { - "object": "fine-tune-event", - "created_at": 1614807352, - "level": "info", - "message": "Job enqueued. Waiting for jobs ahead to complete. Queue number: 0." - } - ], - "fine_tuned_model": null, - "hyperparams": { - "batch_size": 4, - "learning_rate_multiplier": 0.1, - "n_epochs": 4, - "prompt_loss_weight": 0.1, - }, - "organization_id": "org-123", - "result_files": [], - "status": "pending", - "validation_files": [], - "training_files": [ + "id": "model-id-0", + "object": "model", + "created": 1686935002, + "owned_by": "organization-owner" + }, { - "id": "file-abc123", - "object": "file", - "bytes": 1547276, - "created_at": 1610062281, - "filename": "my-data-train.jsonl", - "purpose": "fine-tune-train" - } + "id": "model-id-1", + "object": "model", + "created": 1686935002, + "owned_by": "organization-owner", + }, + { + "id": "model-id-2", + "object": "model", + "created": 1686935002, + "owned_by": "openai" + }, ], - "updated_at": 1614807352, + "object": "list" } + /models/{model}: get: - operationId: listFineTunes - deprecated: true + operationId: retrieveModel tags: - - OpenAI - summary: | - List your organization's fine-tuning jobs + - 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/ListFineTunesResponse" + $ref: "#/components/schemas/Model" x-oaiMeta: - name: List fine-tunes - returns: A list of [fine-tune](/docs/api-reference/fine-tunes/object) objects. + 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/fine-tunes \ + curl https://api.openai.com/v1/models/VAR_model_id \ -H "Authorization: Bearer $OPENAI_API_KEY" python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTune.list() + 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 list = await openai.fineTunes.list(); + const model = await openai.models.retrieve("gpt-3.5-turbo"); - for await (const fineTune of list) { - console.log(fineTune); - } + console.log(model); } main(); - response: | + response: &retrieve_model_response | { - "object": "list", - "data": [ - { - "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F", - "object": "fine-tune", - "model": "curie", - "created_at": 1614807352, - "fine_tuned_model": null, - "hyperparams": { ... }, - "organization_id": "org-123", - "result_files": [], - "status": "pending", - "validation_files": [], - "training_files": [ { ... } ], - "updated_at": 1614807352, - }, - { ... }, - { ... } - ] + "id": "VAR_model_id", + "object": "model", + "created": 1686935002, + "owned_by": "openai" } - - /fine-tunes/{fine_tune_id}: - get: - operationId: retrieveFineTune - deprecated: true + delete: + operationId: deleteModel tags: - - OpenAI - summary: | - Gets info about the fine-tune job. - - [Learn more about fine-tuning](/docs/guides/legacy-fine-tuning) + - Models + summary: Delete a fine-tuned model. You must have the Owner role in your organization to delete a model. parameters: - in: path - name: fine_tune_id + name: model required: true schema: type: string - example: ft-AF1WoRqd3aJAHsqc9NY7iL8F - description: | - The ID of the fine-tune job + 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/FineTune" + $ref: "#/components/schemas/DeleteModelResponse" x-oaiMeta: - name: Retrieve fine-tune - returns: The [fine-tune](/docs/api-reference/fine-tunes/object) object with the given ID. + name: Delete a fine-tuned model + group: models + returns: Deletion status. examples: request: curl: | - curl https://api.openai.com/v1/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F \ + curl https://api.openai.com/v1/models/ft:gpt-3.5-turbo:acemeco:suffix:abc123 \ + -X DELETE \ -H "Authorization: Bearer $OPENAI_API_KEY" python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTune.retrieve(id="ft-AF1WoRqd3aJAHsqc9NY7iL8F") + 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 fineTune = await openai.fineTunes.retrieve("ft-AF1WoRqd3aJAHsqc9NY7iL8F"); + const model = await openai.models.del("ft:gpt-3.5-turbo:acemeco:suffix:abc123"); - console.log(fineTune); + console.log(model); } - main(); - response: &fine_tune_example | + response: | { - "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F", - "object": "fine-tune", - "model": "curie", - "created_at": 1614807352, - "events": [ - { - "object": "fine-tune-event", - "created_at": 1614807352, - "level": "info", - "message": "Job enqueued. Waiting for jobs ahead to complete. Queue number: 0." - }, - { - "object": "fine-tune-event", - "created_at": 1614807356, - "level": "info", - "message": "Job started." - }, - { - "object": "fine-tune-event", - "created_at": 1614807861, - "level": "info", - "message": "Uploaded snapshot: curie:ft-acmeco-2021-03-03-21-44-20." - }, - { - "object": "fine-tune-event", - "created_at": 1614807864, - "level": "info", - "message": "Uploaded result files: file-abc123." - }, - { - "object": "fine-tune-event", - "created_at": 1614807864, - "level": "info", - "message": "Job succeeded." - } - ], - "fine_tuned_model": "curie:ft-acmeco-2021-03-03-21-44-20", - "hyperparams": { - "batch_size": 4, - "learning_rate_multiplier": 0.1, - "n_epochs": 4, - "prompt_loss_weight": 0.1, - }, - "organization_id": "org-123", - "result_files": [ - { - "id": "file-abc123", - "object": "file", - "bytes": 81509, - "created_at": 1614807863, - "filename": "compiled_results.csv", - "purpose": "fine-tune-results" - } - ], - "status": "succeeded", - "validation_files": [], - "training_files": [ - { - "id": "file-abc123", - "object": "file", - "bytes": 1547276, - "created_at": 1610062281, - "filename": "my-data-train.jsonl", - "purpose": "fine-tune-train" - } - ], - "updated_at": 1614807865, + "id": "ft:gpt-3.5-turbo:acemeco:suffix:abc123", + "object": "model", + "deleted": true } - /fine-tunes/{fine_tune_id}/cancel: + /moderations: post: - operationId: cancelFineTune - deprecated: true + operationId: createModeration tags: - - OpenAI - summary: | - Immediately cancel a fine-tune job. - parameters: - - in: path - name: fine_tune_id - required: true - schema: - type: string - example: ft-AF1WoRqd3aJAHsqc9NY7iL8F - description: | - The ID of the fine-tune job to cancel + - Moderations + summary: Classifies if text violates OpenAI's Content Policy + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CreateModerationRequest" responses: "200": description: OK content: application/json: schema: - $ref: "#/components/schemas/FineTune" + $ref: "#/components/schemas/CreateModerationResponse" x-oaiMeta: - name: Cancel fine-tune - returns: The cancelled [fine-tune](/docs/api-reference/fine-tunes/object) object. + name: Create moderation + group: moderations + returns: A [moderation](/docs/api-reference/moderations/object) object. examples: request: curl: | - curl https://api.openai.com/v1/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F/cancel \ - -H "Authorization: Bearer $OPENAI_API_KEY" + 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: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTune.cancel(id="ft-AF1WoRqd3aJAHsqc9NY7iL8F") - node.js: |- + from openai import OpenAI + client = OpenAI() + + client.moderations.create(input="I want to kill them.") + node.js: | import OpenAI from "openai"; const openai = new OpenAI(); async function main() { - const fineTune = await openai.fineTunes.cancel("ft-AF1WoRqd3aJAHsqc9NY7iL8F"); + const moderation = await openai.moderations.create({ input: "I want to kill them." }); - console.log(fineTune); + console.log(moderation); } main(); - response: | + response: &moderation_example | { - "id": "ft-xhrpBbvVUzYGo8oUO1FY4nI7", - "object": "fine-tune", - "model": "curie", - "created_at": 1614807770, - "events": [ { ... } ], - "fine_tuned_model": null, - "hyperparams": { ... }, - "organization_id": "org-123", - "result_files": [], - "status": "cancelled", - "validation_files": [], - "training_files": [ + "id": "modr-XXXXX", + "model": "text-moderation-005", + "results": [ { - "id": "file-abc123", - "object": "file", - "bytes": 1547276, - "created_at": 1610062281, - "filename": "my-data-train.jsonl", - "purpose": "fine-tune-train" + "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, + } } - ], - "updated_at": 1614807789, + ] } - /fine-tunes/{fine_tune_id}/events: + /assistants: get: - operationId: listFineTuneEvents - deprecated: true + operationId: listAssistants tags: - - OpenAI - summary: | - Get fine-grained status updates for a fine-tune job. + - Assistants + summary: Returns a list of assistants. parameters: - - in: path - name: fine_tune_id - required: true + - 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 - example: ft-AF1WoRqd3aJAHsqc9NY7iL8F - description: | - The ID of the fine-tune job to get events for. - - in: query - name: stream - required: false + 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: boolean - default: false - description: | - Whether to stream events for the fine-tune job. If set to true, - events 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. The stream will terminate with a - `data: [DONE]` message when the job is finished (succeeded, cancelled, - or failed). - - If set to false, only events generated so far will be returned. + 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/ListFineTuneEventsResponse" + $ref: "#/components/schemas/ListAssistantsResponse" x-oaiMeta: - name: List fine-tune events - returns: A list of fine-tune event objects. + 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/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F/events \ - -H "Authorization: Bearer $OPENAI_API_KEY" + 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=v1" python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTune.list_events(id="ft-AF1WoRqd3aJAHsqc9NY7iL8F") + 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 fineTune = await openai.fineTunes.listEvents("ft-AF1WoRqd3aJAHsqc9NY7iL8F"); + const myAssistants = await openai.beta.assistants.list({ + order: "desc", + limit: "20", + }); - console.log(fineTune); + console.log(myAssistants.data); } + main(); - response: | + response: &list_assistants_example | { "object": "list", "data": [ { - "object": "fine-tune-event", - "created_at": 1614807352, - "level": "info", - "message": "Job enqueued. Waiting for jobs ahead to complete. Queue number: 0." - }, - { - "object": "fine-tune-event", - "created_at": 1614807356, - "level": "info", - "message": "Job started." - }, - { - "object": "fine-tune-event", - "created_at": 1614807861, - "level": "info", - "message": "Uploaded snapshot: curie:ft-acmeco-2021-03-03-21-44-20." + "id": "asst_abc123", + "object": "assistant", + "created_at": 1698982736, + "name": "Coding Tutor", + "description": null, + "model": "gpt-4", + "instructions": "You are a helpful assistant designed to make me better at coding!", + "tools": [], + "file_ids": [], + "metadata": {} }, { - "object": "fine-tune-event", - "created_at": 1614807864, - "level": "info", - "message": "Uploaded result files: file-abc123" + "id": "asst_abc456", + "object": "assistant", + "created_at": 1698982718, + "name": "My Assistant", + "description": null, + "model": "gpt-4", + "instructions": "You are a helpful assistant designed to make me better at coding!", + "tools": [], + "file_ids": [], + "metadata": {} }, { - "object": "fine-tune-event", - "created_at": 1614807864, - "level": "info", - "message": "Job succeeded." + "id": "asst_abc789", + "object": "assistant", + "created_at": 1698982643, + "name": null, + "description": null, + "model": "gpt-4", + "instructions": null, + "tools": [], + "file_ids": [], + "metadata": {} } - ] + ], + "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=v1" \ + -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" + }' - /models: + 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", + ) + 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", + }); + + console.log(myAssistant); + } + + main(); + response: &create_assistants_example | + { + "id": "asst_abc123", + "object": "assistant", + "created_at": 1698984975, + "name": "Math Tutor", + "description": null, + "model": "gpt-4", + "instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.", + "tools": [ + { + "type": "code_interpreter" + } + ], + "file_ids": [], + "metadata": {} + } + - 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=v1" \ + -d '{ + "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies.", + "tools": [{"type": "retrieval"}], + "model": "gpt-4", + "file_ids": ["file-abc123"] + }' + 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": "retrieval"}], + model="gpt-4", + file_ids=["file-abc123"], + ) + 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: "retrieval" }], + model: "gpt-4", + file_ids: ["file-abc123"], + }); + + console.log(myAssistant); + } + + main(); + response: | + { + "id": "asst_abc123", + "object": "assistant", + "created_at": 1699009403, + "name": "HR Helper", + "description": null, + "model": "gpt-4", + "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies.", + "tools": [ + { + "type": "retrieval" + } + ], + "file_ids": [ + "file-abc123" + ], + "metadata": {} + } + + /assistants/{assistant_id}: get: - operationId: listModels + operationId: getAssistant tags: - - OpenAI - summary: Lists the currently available models, and provides basic information about each one such as the owner and availability. + - 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/ListModelsResponse" + $ref: "#/components/schemas/AssistantObject" x-oaiMeta: - name: List models - returns: A list of [model](/docs/api-reference/models/object) objects. + 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/models \ - -H "Authorization: Bearer $OPENAI_API_KEY" + curl https://api.openai.com/v1/assistants/asst_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Model.list() + 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 list = await openai.models.list(); + const myAssistant = await openai.beta.assistants.retrieve( + "asst_abc123" + ); - for await (const model of list) { - console.log(model); - } + console.log(myAssistant); } + main(); response: | { - "object": "list", - "data": [ - { - "id": "model-id-0", - "object": "model", - "created": 1686935002, - "owned_by": "organization-owner" - }, + "id": "asst_abc123", + "object": "assistant", + "created_at": 1699009709, + "name": "HR Helper", + "description": null, + "model": "gpt-4", + "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies.", + "tools": [ { - "id": "model-id-1", - "object": "model", - "created": 1686935002, - "owned_by": "organization-owner", - }, - { - "id": "model-id-2", - "object": "model", - "created": 1686935002, - "owned_by": "openai" - }, + "type": "retrieval" + } ], - "object": "list" + "file_ids": [ + "file-abc123" + ], + "metadata": {} } - - /models/{model}: - get: - operationId: retrieveModel + post: + operationId: modifyAssistant tags: - - OpenAI - summary: Retrieves a model instance, providing basic information about the model such as the owner and permissioning. + - Assistants + summary: Modifies an assistant. parameters: - in: path - name: model + name: assistant_id 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 + 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/Model" + $ref: "#/components/schemas/AssistantObject" x-oaiMeta: - name: Retrieve model - returns: The [model](/docs/api-reference/models/object) object matching the specified ID. + 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/models/VAR_model_id \ - -H "Authorization: Bearer $OPENAI_API_KEY" + curl https://api.openai.com/v1/assistants/asst_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" \ + -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": "retrieval"}], + "model": "gpt-4", + "file_ids": ["file-abc123", "file-abc456"] + }' python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Model.retrieve("VAR_model_id") + 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": "retrieval"}], + model="gpt-4", + file_ids=["file-abc123", "file-abc456"], + ) + + print(my_updated_assistant) node.js: |- import OpenAI from "openai"; const openai = new OpenAI(); async function main() { - const model = await openai.models.retrieve("gpt-3.5-turbo"); + 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: "retrieval" }], + model: "gpt-4", + file_ids: [ + "file-abc123", + "file-abc456", + ], + } + ); - console.log(model); + console.log(myUpdatedAssistant); } main(); - response: &retrieve_model_response | + response: | { - "id": "VAR_model_id", - "object": "model", - "created": 1686935002, - "owned_by": "openai" + "id": "asst_abc123", + "object": "assistant", + "created_at": 1699009709, + "name": "HR Helper", + "description": null, + "model": "gpt-4", + "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": "retrieval" + } + ], + "file_ids": [ + "file-abc123", + "file-abc456" + ], + "metadata": {} } delete: - operationId: deleteModel + operationId: deleteAssistant tags: - - OpenAI - summary: Delete a fine-tuned model. You must have the Owner role in your organization to delete a model. + - Assistants + summary: Delete an assistant. parameters: - in: path - name: model + name: assistant_id required: true schema: type: string - example: ft:gpt-3.5-turbo:acemeco:suffix:abc123 - description: The model to delete + description: The ID of the assistant to delete. responses: "200": description: OK content: application/json: schema: - $ref: "#/components/schemas/DeleteModelResponse" + $ref: "#/components/schemas/DeleteAssistantResponse" x-oaiMeta: - name: Delete fine-tune model - returns: Deletion status. + name: Delete assistant + group: assistants + beta: true + 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" + curl https://api.openai.com/v1/assistants/asst_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" \ + -X DELETE python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Model.delete("ft:gpt-3.5-turbo:acemeco:suffix:abc123") + 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 model = await openai.models.del("ft:gpt-3.5-turbo:acemeco:suffix:abc123"); + const response = await openai.beta.assistants.del("asst_abc123"); - console.log(model); + console.log(response); } main(); response: | { - "id": "ft:gpt-3.5-turbo:acemeco:suffix:abc123", - "object": "model", + "id": "asst_abc123", + "object": "assistant.deleted", "deleted": true } - /moderations: + /threads: post: - operationId: createModeration + operationId: createThread tags: - - OpenAI - summary: Classifies if text violates OpenAI's Content Policy + - 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=v1" \ + -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": {} + } + - 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=v1" \ + -d '{ + "messages": [{ + "role": "user", + "content": "Hello, what is AI?", + "file_ids": ["file-abc123"] + }, { + "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?", + "file_ids": ["file-abc123"], + }, + { + "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?", + file_ids: ["file-abc123"], + }, + { + 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: {} + } + + /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=v1" + 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": {} + } + 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/CreateModerationRequest" + $ref: "#/components/schemas/ModifyThreadRequest" responses: "200": description: OK content: application/json: schema: - $ref: "#/components/schemas/CreateModerationResponse" + $ref: "#/components/schemas/ThreadObject" x-oaiMeta: - name: Create moderation - returns: A [moderation](/docs/api-reference/moderations/object) object. + 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/moderations \ + curl https://api.openai.com/v1/threads/thread_abc123 \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" \ -d '{ - "input": "I want to kill them." - }' + "metadata": { + "modified": "true", + "user": "abc123" + } + }' python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Moderation.create( - input="I want to kill them.", + from openai import OpenAI + client = OpenAI() + + my_updated_thread = client.beta.threads.update( + "thread_abc123", + metadata={ + "modified": "true", + "user": "abc123" + } ) - node.js: | + print(my_updated_thread) + 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." }); + const updatedThread = await openai.beta.threads.update( + "thread_abc123", + { + metadata: { modified: "true", user: "abc123" }, + } + ); - console.log(moderation); + console.log(updatedThread); } + main(); - response: &moderation_example | + 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, - } - } - ] + "id": "thread_abc123", + "object": "thread", + "created_at": 1699014083, + "metadata": { + "modified": "true", + "user": "abc123" + } } + 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=v1" \ + -X DELETE + python: | + from openai import OpenAI + client = OpenAI() -components: + 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/{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 + 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=v1" + 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, + "thread_id": "thread_abc123", + "role": "user", + "content": [ + { + "type": "text", + "text": { + "value": "How does AI work? Explain it in simple terms.", + "annotations": [] + } + } + ], + "file_ids": [], + "assistant_id": null, + "run_id": null, + "metadata": {} + }, + { + "id": "msg_abc456", + "object": "thread.message", + "created_at": 1699016383, + "thread_id": "thread_abc123", + "role": "user", + "content": [ + { + "type": "text", + "text": { + "value": "Hello, what is AI?", + "annotations": [] + } + } + ], + "file_ids": [ + "file-abc123" + ], + "assistant_id": null, + "run_id": null, + "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=v1" \ + -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": 1699017614, + "thread_id": "thread_abc123", + "role": "user", + "content": [ + { + "type": "text", + "text": { + "value": "How does AI work? Explain it in simple terms.", + "annotations": [] + } + } + ], + "file_ids": [], + "assistant_id": null, + "run_id": null, + "metadata": {} + } + + /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/threads/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=v1" + 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, + "thread_id": "thread_abc123", + "role": "user", + "content": [ + { + "type": "text", + "text": { + "value": "How does AI work? Explain it in simple terms.", + "annotations": [] + } + } + ], + "file_ids": [], + "assistant_id": null, + "run_id": null, + "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/threads/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=v1" \ + -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, + "thread_id": "thread_abc123", + "role": "user", + "content": [ + { + "type": "text", + "text": { + "value": "How does AI work? Explain it in simple terms.", + "annotations": [] + } + } + ], + "file_ids": [], + "assistant_id": null, + "run_id": null, + "metadata": { + "modified": "true", + "user": "abc123" + } + } + + /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: + 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=v1" \ + -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."} + ] + } + ) + 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, + "last_error": null, + "model": "gpt-4", + "instructions": "You are a helpful assistant.", + "tools": [], + "file_ids": [], + "metadata": {}, + "usage": null + } + + /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=v1" + 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-3.5-turbo", + "instructions": null, + "tools": [ + { + "type": "code_interpreter" + } + ], + "file_ids": [ + "file-abc123", + "file-abc456" + ], + "metadata": {}, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + } + }, + { + "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-3.5-turbo", + "instructions": null, + "tools": [ + { + "type": "code_interpreter" + } + ], + "file_ids": [ + "file-abc123", + "file-abc456" + ], + "metadata": {}, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + } + } + ], + "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: + 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=v1" \ + -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", + "instructions": null, + "tools": [ + { + "type": "code_interpreter" + } + ], + "file_ids": [ + "file-abc123", + "file-abc456" + ], + "metadata": {}, + "usage": null + } + + /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=v1" + 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-3.5-turbo", + "instructions": null, + "tools": [ + { + "type": "code_interpreter" + } + ], + "file_ids": [ + "file-abc123", + "file-abc456" + ], + "metadata": {}, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + } + } + 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=v1" \ + -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-3.5-turbo", + "instructions": null, + "tools": [ + { + "type": "code_interpreter" + } + ], + "file_ids": [ + "file-abc123", + "file-abc456" + ], + "metadata": { + "user_id": "user_abc123" + }, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + } + } + + /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: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/submit_tool_outputs \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v1" \ + -d '{ + "tool_outputs": [ + { + "tool_call_id": "call_abc123", + "output": "28C" + } + ] + }' + python: | + from openai import OpenAI + client = OpenAI() + + run = client.beta.threads.runs.submit_tool_outputs( + thread_id="thread_abc123", + run_id="run_abc123", + tool_outputs=[ + { + "tool_call_id": "call_abc123", + "output": "28C" + } + ] + ) + print(run) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const run = await openai.beta.threads.runs.submitToolOutputs( + "thread_abc123", + "run_abc123", + { + tool_outputs: [ + { + tool_call_id: "call_abc123", + output: "28C", + }, + ], + } + ); + + console.log(run); + } + + main(); + response: | + { + "id": "run_abc123", + "object": "thread.run", + "created_at": 1699075592, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "queued", + "started_at": 1699075592, + "expires_at": 1699076192, + "cancelled_at": null, + "failed_at": null, + "completed_at": null, + "last_error": null, + "model": "gpt-4", + "instructions": "You tell the weather.", + "tools": [ + { + "type": "function", + "function": { + "name": "get_weather", + "description": "Determine weather in my location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state e.g. San Francisco, CA" + }, + "unit": { + "type": "string", + "enum": [ + "c", + "f" + ] + } + }, + "required": [ + "location" + ] + } + } + } + ], + "file_ids": [], + "metadata": {}, + "usage": null + } + + /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=v1" \ + -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", + "instructions": "You summarize books.", + "tools": [ + { + "type": "retrieval" + } + ], + "file_ids": [], + "metadata": {}, + "usage": null + } + + /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=v1" + 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=v1" + 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 + } + } + + /assistants/{assistant_id}/files: + get: + operationId: listAssistantFiles + tags: + - Assistants + summary: Returns a list of assistant files. + parameters: + - name: assistant_id + in: path + description: The ID of the assistant the file belongs 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 + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/ListAssistantFilesResponse" + x-oaiMeta: + name: List assistant files + group: assistants + beta: true + returns: A list of [assistant file](/docs/api-reference/assistants/file-object) objects. + examples: + request: + curl: | + curl https://api.openai.com/v1/assistants/asst_abc123/files \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v1" + python: | + from openai import OpenAI + client = OpenAI() + + assistant_files = client.beta.assistants.files.list( + assistant_id="asst_abc123" + ) + print(assistant_files) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const assistantFiles = await openai.beta.assistants.files.list( + "asst_abc123" + ); + console.log(assistantFiles); + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "file-abc123", + "object": "assistant.file", + "created_at": 1699060412, + "assistant_id": "asst_abc123" + }, + { + "id": "file-abc456", + "object": "assistant.file", + "created_at": 1699060412, + "assistant_id": "asst_abc123" + } + ], + "first_id": "file-abc123", + "last_id": "file-abc456", + "has_more": false + } + post: + operationId: createAssistantFile + tags: + - Assistants + summary: Create an assistant file by attaching a [File](/docs/api-reference/files) to an [assistant](/docs/api-reference/assistants). + parameters: + - in: path + name: assistant_id + required: true + schema: + type: string + example: file-abc123 + description: | + The ID of the assistant for which to create a File. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CreateAssistantFileRequest" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/AssistantFileObject" + x-oaiMeta: + name: Create assistant file + group: assistants + beta: true + returns: An [assistant file](/docs/api-reference/assistants/file-object) object. + examples: + request: + curl: | + curl https://api.openai.com/v1/assistants/asst_abc123/files \ + -H 'Authorization: Bearer $OPENAI_API_KEY"' \ + -H 'Content-Type: application/json' \ + -H 'OpenAI-Beta: assistants=v1' \ + -d '{ + "file_id": "file-abc123" + }' + python: | + from openai import OpenAI + client = OpenAI() + + assistant_file = client.beta.assistants.files.create( + assistant_id="asst_abc123", + file_id="file-abc123" + ) + print(assistant_file) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const myAssistantFile = await openai.beta.assistants.files.create( + "asst_abc123", + { + file_id: "file-abc123" + } + ); + console.log(myAssistantFile); + } + + main(); + response: &assistant_file_object | + { + "id": "file-abc123", + "object": "assistant.file", + "created_at": 1699055364, + "assistant_id": "asst_abc123" + } + + /assistants/{assistant_id}/files/{file_id}: + get: + operationId: getAssistantFile + tags: + - Assistants + summary: Retrieves an AssistantFile. + parameters: + - in: path + name: assistant_id + required: true + schema: + type: string + description: The ID of the assistant who the file belongs to. + - in: path + name: file_id + required: true + schema: + type: string + description: The ID of the file we're getting. + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/AssistantFileObject" + x-oaiMeta: + name: Retrieve assistant file + group: assistants + beta: true + returns: The [assistant file](/docs/api-reference/assistants/file-object) object matching the specified ID. + examples: + request: + curl: | + curl https://api.openai.com/v1/assistants/asst_abc123/files/file-abc123 \ + -H 'Authorization: Bearer $OPENAI_API_KEY"' \ + -H 'Content-Type: application/json' \ + -H 'OpenAI-Beta: assistants=v1' + python: | + from openai import OpenAI + client = OpenAI() + + assistant_file = client.beta.assistants.files.retrieve( + assistant_id="asst_abc123", + file_id="file-abc123" + ) + print(assistant_file) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const myAssistantFile = await openai.beta.assistants.files.retrieve( + "asst_abc123", + "file-abc123" + ); + console.log(myAssistantFile); + } + + main(); + response: *assistant_file_object + delete: + operationId: deleteAssistantFile + tags: + - Assistants + summary: Delete an assistant file. + parameters: + - in: path + name: assistant_id + required: true + schema: + type: string + description: The ID of the assistant 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/DeleteAssistantFileResponse" + x-oaiMeta: + name: Delete assistant file + group: assistants + beta: true + returns: Deletion status + examples: + request: + curl: | + curl https://api.openai.com/v1/assistants/asst_abc123/files/file-abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v1" \ + -X DELETE + python: | + from openai import OpenAI + client = OpenAI() + + deleted_assistant_file = client.beta.assistants.files.delete( + assistant_id="asst_abc123", + file_id="file-abc123" + ) + print(deleted_assistant_file) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const deletedAssistantFile = await openai.beta.assistants.files.del( + "asst_abc123", + "file-abc123" + ); + console.log(deletedAssistantFile); + } + + main(); + response: | + { + id: "file-abc123", + object: "assistant.file.deleted", + deleted: true + } + + /threads/{thread_id}/messages/{message_id}/files: + get: + operationId: listMessageFiles + tags: + - Assistants + summary: Returns a list of message files. + parameters: + - name: thread_id + in: path + description: The ID of the thread that the message and files belong to. + required: true + schema: + type: string + - name: message_id + in: path + description: The ID of the message that the files belongs 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 + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/ListMessageFilesResponse" + x-oaiMeta: + name: List message files + group: threads + beta: true + returns: A list of [message file](/docs/api-reference/messages/file-object) objects. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123/files \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v1" + python: | + from openai import OpenAI + client = OpenAI() + + message_files = client.beta.threads.messages.files.list( + thread_id="thread_abc123", + message_id="msg_abc123" + ) + print(message_files) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const messageFiles = await openai.beta.threads.messages.files.list( + "thread_abc123", + "msg_abc123" + ); + console.log(messageFiles); + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "file-abc123", + "object": "thread.message.file", + "created_at": 1699061776, + "message_id": "msg_abc123" + }, + { + "id": "file-abc123", + "object": "thread.message.file", + "created_at": 1699061776, + "message_id": "msg_abc123" + } + ], + "first_id": "file-abc123", + "last_id": "file-abc123", + "has_more": false + } + + /threads/{thread_id}/messages/{message_id}/files/{file_id}: + get: + operationId: getMessageFile + tags: + - Assistants + summary: Retrieves a message file. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + example: thread_abc123 + description: The ID of the thread to which the message and File belong. + - in: path + name: message_id + required: true + schema: + type: string + example: msg_abc123 + description: The ID of the message 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/MessageFileObject" + x-oaiMeta: + name: Retrieve message file + group: threads + beta: true + returns: The [message file](/docs/api-reference/messages/file-object) object. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123/files/file-abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v1" + python: | + from openai import OpenAI + client = OpenAI() + + message_files = client.beta.threads.messages.files.retrieve( + thread_id="thread_abc123", + message_id="msg_abc123", + file_id="file-abc123" + ) + print(message_files) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const messageFile = await openai.beta.threads.messages.files.retrieve( + "thread_abc123", + "msg_abc123", + "file-abc123" + ); + console.log(messageFile); + } + + main(); + response: | + { + "id": "file-abc123", + "object": "thread.message.file", + "created_at": 1699061776, + "message_id": "msg_abc123" + } + +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 + suffix: + description: The suffix that comes after a completion of inserted text. + 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-3.5-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-4-visual-preview` 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." + 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 + + 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/text-generation/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) 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 `{"type": "function", "function": {"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/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 + + ChatCompletionMessageToolCalls: + 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 + + # 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 + enum: + - system + - user + - assistant + - tool + - function + + 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-3.5-turbo" + anyOf: + - type: string + - type: string + enum: + [ + "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-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`. This option is currently not available on the `gpt-4-vision-preview` model. + type: boolean + default: false + nullable: true + top_logprobs: + description: An integer between 0 and 5 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: 5 + 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 `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 + 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 + 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. + items: + $ref: "#/components/schemas/ChatCompletionTool" + tool_choice: + $ref: "#/components/schemas/ChatCompletionToolChoiceOption" + 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. + 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. + 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 be more than one if `n` is greater than 1. + 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. + 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] + 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`. + 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 - securitySchemes: - ApiKeyAuth: - type: http - scheme: 'bearer' + CreateModerationResponse: + type: object + description: Represents policy compliance report by OpenAI's content moderation model against a given input. + 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 the content violates [OpenAI's usage policies](/policies/usage-policies). + 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 - schemas: - Error: + ListFilesResponse: type: object properties: - type: + data: + type: array + items: + $ref: "#/components/schemas/OpenAIFile" + object: type: string - nullable: false - message: + enum: [list] + required: + - object + - data + + CreateFileRequest: + type: object + additionalProperties: false + properties: + file: + description: | + The File object (not file name) to be uploaded. type: string - nullable: false - param: + format: binary + purpose: + description: | + The intended purpose of the uploaded file. + + Use "fine-tune" for [Fine-tuning](/docs/api-reference/fine-tuning) and "assistants" for [Assistants](/docs/api-reference/assistants) and [Messages](/docs/api-reference/messages). This allows us to validate the format of the uploaded file is correct for fine-tuning. type: string - nullable: true - code: + enum: ["fine-tune", "assistants"] + required: + - file + - purpose + + DeleteFileResponse: + type: object + properties: + id: type: string - nullable: true + object: + type: string + enum: [file] + deleted: + type: boolean required: - - type - - message - - param - - code + - id + - object + - deleted - ErrorResponse: + CreateFineTuningJobRequest: type: object properties: - error: - $ref: "#/components/schemas/Error" + 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/upload) 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`. + + 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" required: - - error + - model + - training_file - ListModelsResponse: + ListFineTuningJobEventsResponse: type: object properties: - object: - type: string data: type: array items: - $ref: "#/components/schemas/Model" - required: - - object - - data - - DeleteModelResponse: - type: object - properties: - id: - type: string + $ref: "#/components/schemas/FineTuningJobEvent" object: type: string - deleted: - type: boolean + enum: [list] required: - - id - object - - deleted + - data - CreateCompletionRequest: + CreateEmbeddingRequest: type: object + additionalProperties: false 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: - [ - "babbage-002", - "davinci-002", - "gpt-3.5-turbo-instruct", - "text-davinci-003", - "text-davinci-002", - "text-davinci-001", - "code-davinci-002", - "text-curie-001", - "text-babbage-001", - "text-ada-001", - ] - 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 + 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." + 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]]" - suffix: - description: The suffix that comes after a completion of inserted text. - default: null - nullable: true + 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 - example: "test." - max_tokens: - type: integer - minimum: 0 - default: 16 - example: 16 - nullable: true - description: &completions_max_tokens_description | - The maximum number of [tokens](/tokenizer) to generate in the completion. - - The token count of your prompt plus `max_tokens` cannot exceed the model's context length. [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) for counting tokens. - 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. - n: + 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 - maximum: 128 - default: 1 - example: 1 - nullable: true - description: &completions_completions_description | - How many completions to generate for each prompt. + user: *end_user_param_configuration + required: + - model + - input - **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`. - 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://github.com/openai/openai-cookbook/blob/main/examples/How_to_stream_completions.ipynb). - type: boolean - nullable: true - default: false - 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 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. + 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 - The maximum value for `logprobs` is 5. - echo: - type: boolean - default: false - nullable: true - description: &completions_echo_description > - Echo back the prompt in addition to the completion - 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: + 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` is currently available. + example: whisper-1 + anyOf: - type: string - default: <|endoftext|> - example: "\n" - nullable: true - - type: array - minItems: 1 - maxItems: 4 - items: - type: string - example: '["\n"]' - presence_penalty: + - 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 - 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. + required: + - file + - model - [See more information about frequency and presence penalties.](/docs/guides/gpt/parameter-details) - frequency_penalty: + # Note: This does not currently support the non-default response format types. + CreateTranscriptionResponse: + type: object + properties: + text: + type: string + required: + - text + + 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` 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 - 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/gpt/parameter-details) - 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`. - 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) (which works for both GPT-2 and GPT-3) 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. + required: + - file + - model - As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being generated. - user: &end_user_param_configuration + # Note: This does not currently support the non-default response format types. + CreateTranslationResponse: + type: object + properties: + text: type: string - example: user-1234 + required: + - text + + CreateSpeechRequest: + type: object + additionalProperties: false + properties: + model: 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). + 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`, and `flac`." + default: "mp3" + type: string + enum: ["mp3", "opus", "aac", "flac"] + 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 - - prompt + - input + - voice - 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). + Model: + title: Model + description: Describes an OpenAI model offering that can be used with the API. properties: id: type: string - description: A unique identifier for the completion. - object: - type: string - description: The object type, which is always "text_completion" + description: The model identifier, which can be referenced in the API endpoints. created: type: integer - description: The Unix timestamp (in seconds) of when the completion was created. - model: + description: The Unix timestamp (in seconds) when the model was created. + object: type: string - description: The model used for completion. - choices: - type: array - description: The list of completion choices the model generated for the input prompt. - items: - type: object - required: - - text - - index - - logprobs - - finish_reason - properties: - text: - type: string - index: - type: integer - logprobs: - type: object - nullable: true - properties: - tokens: - type: array - items: - type: string - token_logprobs: - type: array - items: - type: number - top_logprobs: - type: array - items: - type: object - additionalProperties: - type: integer - text_offset: - type: array - items: - type: integer - 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"] - usage: - $ref: "#/components/schemas/CompletionUsage" + 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 - - model - - choices + - owned_by x-oaiMeta: - name: The completion object - legacy: true - example: | - { - "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7", - "object": "text_completion", - "created": 1589478378, - "model": "gpt-3.5-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 - } - } + name: The model object + example: *retrieve_model_response - ChatCompletionRequestMessage: - type: object + OpenAIFile: + title: OpenAIFile + description: The `File` object represents a document that has been uploaded to OpenAI. properties: - role: + id: type: string - enum: ["system", "user", "assistant", "function"] - description: The role of the messages author. One of `system`, `user`, `assistant`, or `function`. - content: + 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 - nullable: true - description: The contents of the message. `content` is required for all messages, and may be null for assistant messages with function calls. - name: + description: The name of the file. + object: type: string - description: The name of the author of this message. `name` is required if role is `function`, and it should be the name of the function whose response is in the `content`. May contain a-z, A-Z, 0-9, and underscores, with a maximum length of 64 characters. - function_call: - type: object - description: The name and arguments of a function that should be called, as generated by the model. - 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: - - role - - content - - ChatCompletionFunctionParameters: - type: object - description: "The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/gpt/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation about the format.\n\nTo describe a function that accepts no parameters, provide the value `{\"type\": \"object\", \"properties\": {}}`." - additionalProperties: true - - ChatCompletionFunctions: - type: object - properties: - name: + description: The object type, which is always `file`. + enum: ["file"] + purpose: 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: + description: The intended purpose of the file. Supported values are `fine-tune`, `fine-tune-results`, `assistants`, and `assistants_output`. + enum: + [ + "fine-tune", + "fine-tune-results", + "assistants", + "assistants_output", + ] + status: 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/ChatCompletionFunctionParameters" + 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 + deprecated: true + description: Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`. required: - - name - - parameters - - ChatCompletionFunctionCallOption: + - 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", + } + Embedding: type: object + description: | + Represents an embedding vector returned by embedding endpoint. properties: - name: + 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 name of the function to call. + description: The object type, which is always "embedding". + enum: [embedding] required: - - name + - 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 + } - ChatCompletionResponseMessage: + FineTuningJob: type: object - description: A chat completion message generated by the model. + title: FineTuningJob + description: | + The `fine_tuning.job` object represents a fine-tuning job that has been created through the API. properties: - role: - type: string - enum: ["system", "user", "assistant", "function"] - description: The role of the author of this message. - content: + id: type: string - description: The contents of the message. - nullable: true - function_call: + 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 - description: The name and arguments of a function that should be called, as generated by the model. + nullable: true + description: For fine-tuning jobs that have `failed`, this will contain more information on the cause of the failure. properties: - name: + code: type: string - description: The name of the function to call. - arguments: + description: A machine-readable error code. + message: 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: 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 required: - - name - - arguments - required: - - role - - content - - ChatCompletionStreamResponseDelta: - type: object - description: A chat completion delta generated by streamed model responses. - properties: - role: - type: string - enum: ["system", "user", "assistant", "function"] - description: The role of the author of this message. - content: + - code + - message + - param + fine_tuned_model: type: string - description: The contents of the chunk message. nullable: true - function_call: + 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 name and arguments of a function that should be called, as generated by the model. + description: The hyperparameters used for the fine-tuning job. See the [fine-tuning guide](/docs/guides/fine-tuning) for more details. 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. + 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. - CreateChatCompletionRequest: - type: object - properties: + "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: - 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-3.5-turbo" - anyOf: - - type: string - - type: string - enum: - [ - "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-16k-0613", - ] - x-oaiTypeLabel: string - messages: - description: A list of messages comprising the conversation so far. [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb). - type: array - minItems: 1 - items: - $ref: "#/components/schemas/ChatCompletionRequestMessage" - functions: - description: A list of functions the model may generate JSON inputs for. + 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 - minItems: 1 - maxItems: 128 + 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: - $ref: "#/components/schemas/ChatCompletionFunctions" - function_call: - description: "Controls how the model responds to function calls. `none` means the model does not call a function, and responds to the end-user. `auto` means the model can pick between an end-user 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 - enum: [none, auto] - - $ref: "#/components/schemas/ChatCompletionFunctionCallOption" - 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 - n: + 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 - minimum: 1 - maximum: 128 - default: 1 - example: 1 nullable: true - description: How many chat completion choices to generate for each input message. - 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://github.com/openai/openai-cookbook/blob/main/examples/How_to_stream_completions.ipynb). - type: boolean + 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 - default: false - 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 - max_tokens: - description: | - The maximum number of [tokens](/tokenizer) to generate in the chat completion. + description: The file ID used for validation. You can retrieve the validation results with the [Files API](/docs/api-reference/files/retrieve-contents). + required: + - created_at + - error + - finished_at + - fine_tuned_model + - hyperparameters + - id + - model + - object + - organization_id + - result_files + - status + - trained_tokens + - training_file + - validation_file + x-oaiMeta: + name: The fine-tuning job object + example: *fine_tuning_example - The total length of input tokens and generated tokens is limited by the model's context length. [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) for counting tokens. - default: inf + FineTuningJobEvent: + type: object + description: Fine-tuning job event object + properties: + id: + type: string + created_at: type: integer - nullable: true - presence_penalty: - type: number - default: 0 - minimum: -2 - maximum: 2 - nullable: true - description: *completions_presence_penalty_description - 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. + 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" + } - 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. - user: *end_user_param_configuration + 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: - - model - - messages + - prompt_tokens + - completion_tokens + - total_tokens - CreateChatCompletionResponse: + RunCompletionUsage: type: object - description: Represents a chat completion response returned by model, based on the provided input. + 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: - id: - type: string - description: A unique identifier for the chat completion. - object: - type: string - description: The object type, which is always `chat.completion`. - created: + completion_tokens: 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. - 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: - - index - - message - - finish_reason - properties: - index: - type: integer - description: The index of the choice in the list of choices. - message: - $ref: "#/components/schemas/ChatCompletionResponseMessage" - 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, - or `function_call` if the model called a function. - enum: ["stop", "length", "function_call", "content_filter"] - usage: - $ref: "#/components/schemas/CompletionUsage" + 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: - - id - - object - - created - - model - - choices - x-oaiMeta: - name: The chat completion object - group: chat - example: *chat_completion_example + - prompt_tokens + - completion_tokens + - total_tokens + nullable: true - ListPaginatedFineTuningJobsResponse: + 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: - object: - type: string - data: - type: array - items: - $ref: "#/components/schemas/FineTuningJob" - has_more: - type: boolean + 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: - - object - - data - - has_more + - prompt_tokens + - completion_tokens + - total_tokens + nullable: true - CreateChatCompletionStreamResponse: + AssistantObject: type: object - description: Represents a streamed chunk of a chat completion response returned by model, based on the provided input. + 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 - description: A unique identifier for the chat completion chunk. object: + description: The object type, which is always `assistant`. type: string - description: The object type, which is always `chat.completion.chunk`. - created: + enum: [assistant] + created_at: + description: The Unix timestamp (in seconds) for when the assistant was created. type: integer - description: The Unix timestamp (in seconds) of when the chat completion chunk was created. + 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 - description: The model to generate the completion. - choices: + instructions: + description: &assistant_instructions_param_description | + The system instructions that the assistant uses. The maximum length is 32768 characters. + type: string + maxLength: 32768 + 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`, `retrieval`, or `function`. + default: [] type: array - description: A list of chat completion choices. Can be more than one if `n` is greater than 1. + maxItems: 128 items: - type: object - required: - - index - - delta - - finish_reason - properties: - index: - type: integer - description: The index of the choice in the list of choices. - delta: - $ref: "#/components/schemas/ChatCompletionStreamResponseDelta" - finish_reason: - type: string - description: *chat_completion_finish_reason_description - enum: ["stop", "length", "function_call"] - nullable: true + oneOf: + - $ref: "#/components/schemas/AssistantToolsCode" + - $ref: "#/components/schemas/AssistantToolsRetrieval" + - $ref: "#/components/schemas/AssistantToolsFunction" + x-oaiExpandable: true + file_ids: + description: &assistant_file_param_description | + A list of [file](/docs/api-reference/files) IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. Files are ordered by their creation date in ascending order. + default: [] + type: array + maxItems: 20 + items: + type: string + 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 required: - id - object - - created + - created_at + - name + - description - model - - choices + - instructions + - tools + - file_ids + - metadata x-oaiMeta: - name: The chat completion chunk object - group: chat - example: *chat_completion_chunk_example + name: The assistant object + beta: true + example: *create_assistants_example - CreateEditRequest: + CreateAssistantRequest: type: object + additionalProperties: false properties: model: - description: ID of the model to use. You can use the `text-davinci-edit-001` or `code-davinci-edit-001` model with this endpoint. - example: "text-davinci-edit-001" + description: *model_description anyOf: - type: string - - type: string - enum: ["text-davinci-edit-001", "code-davinci-edit-001"] - x-oaiTypeLabel: string - input: - description: The input text to use as a starting point for the edit. + name: + description: *assistant_name_param_description type: string - default: "" nullable: true - example: "What day of the wek is it?" - instruction: - description: The instruction that tells the model how to edit the prompt. + maxLength: 256 + description: + description: *assistant_description_param_description type: string - example: "Fix the spelling mistakes." - n: - type: integer - minimum: 1 - maximum: 20 - default: 1 - example: 1 - nullable: true - description: How many edits to generate for the input and instruction. - 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 - required: - - model - - instruction - - CreateEditResponse: - type: object - title: Edit - deprecated: true - properties: - object: + maxLength: 512 + instructions: + description: *assistant_instructions_param_description type: string - description: The object type, which is always `edit`. - created: - type: integer - description: The Unix timestamp (in seconds) of when the edit was created. - choices: + nullable: true + maxLength: 32768 + tools: + description: *assistant_tools_param_description + default: [] type: array - description: A list of edit choices. Can be more than one if `n` is greater than 1. + maxItems: 128 items: - type: object - required: - - text - - index - - finish_reason - properties: - text: - type: string - description: The edited result. - index: - type: integer - description: The index of the choice in the list of choices. - finish_reason: - type: string - description: *completion_finish_reason_description - enum: ["stop", "length"] - usage: - $ref: "#/components/schemas/CompletionUsage" + oneOf: + - $ref: "#/components/schemas/AssistantToolsCode" + - $ref: "#/components/schemas/AssistantToolsRetrieval" + - $ref: "#/components/schemas/AssistantToolsFunction" + x-oaiExpandable: true + file_ids: + description: *assistant_file_param_description + default: [] + maxItems: 20 + type: array + items: + type: string + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true required: - - object - - created - - choices - - usage - x-oaiMeta: - name: The edit object - example: *edit_example + - model - CreateImageRequest: + ModifyAssistantRequest: type: object + additionalProperties: false properties: - prompt: - description: A text description of the desired image(s). The maximum length is 1000 characters. + model: + description: *model_description + anyOf: + - type: string + name: + description: *assistant_name_param_description type: string - example: "A cute baby sea otter" - 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. - size: &images_size + maxLength: 256 + description: + description: *assistant_description_param_description 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 + maxLength: 512 + instructions: + description: *assistant_instructions_param_description 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`. - user: *end_user_param_configuration - required: - - prompt - - ImagesResponse: - properties: - created: - type: integer - data: + maxLength: 32768 + tools: + description: *assistant_tools_param_description + default: [] type: array + maxItems: 128 items: - $ref: "#/components/schemas/Image" - required: - - created - - data + oneOf: + - $ref: "#/components/schemas/AssistantToolsCode" + - $ref: "#/components/schemas/AssistantToolsRetrieval" + - $ref: "#/components/schemas/AssistantToolsFunction" + x-oaiExpandable: true + file_ids: + description: | + A list of [File](/docs/api-reference/files) IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. Files are ordered by their creation date in ascending order. If a file was previously attached to the list but does not show up in the list, it will be deleted from the assistant. + default: [] + type: array + maxItems: 20 + items: + type: string + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true - Image: + DeleteAssistantResponse: type: object - description: Represents the url or the content of an image generated by the OpenAI API. properties: - url: + id: type: string - description: The URL of the generated image, if `response_format` is `url` (default). - b64_json: + deleted: + type: boolean + object: type: string - description: The base64-encoded JSON of the generated image, if `response_format` is `b64_json`. - x-oaiMeta: - name: The image object - example: | - { - "url": "..." - } + enum: [assistant.deleted] + required: + - id + - object + - deleted - CreateImageEditRequest: + ListAssistantsResponse: 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. + object: type: string - format: binary - 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`. + example: "list" + data: + type: array + items: + $ref: "#/components/schemas/AssistantObject" + first_id: type: string - format: binary - prompt: - description: A text description of the desired image(s). The maximum length is 1000 characters. + example: "asst_abc123" + last_id: type: string - example: "A cute baby sea otter wearing a beret" - n: *images_n - size: *images_size - response_format: *images_response_format - user: *end_user_param_configuration + example: "asst_abc456" + has_more: + type: boolean + example: false required: - - prompt - - image + - object + - data + - first_id + - last_id + - has_more + x-oaiMeta: + name: List assistants response object + group: chat + example: *list_assistants_example - CreateImageVariationRequest: + AssistantToolsCode: type: object + title: Code interpreter tool 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: type: string - format: binary - n: *images_n - size: *images_size - response_format: *images_response_format - user: *end_user_param_configuration + description: "The type of tool being defined: `code_interpreter`" + enum: ["code_interpreter"] required: - - image + - type - CreateModerationRequest: + AssistantToolsRetrieval: type: object + title: Retrieval tool 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`. + type: + type: string + description: "The type of tool being defined: `retrieval`" + enum: ["retrieval"] + required: + - type - 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 + 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: - - input + - type + - function - CreateModerationResponse: + RunObject: type: object - description: Represents policy compliance report by OpenAI's content moderation model against a given input. + 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 - description: The unique identifier for the moderation request. + 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`, or `expired`. + type: string + enum: + [ + "queued", + "in_progress", + "requires_action", + "cancelling", + "cancelled", + "failed", + "completed", + "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` or `rate_limit_exceeded`. + enum: ["server_error", "rate_limit_exceeded"] + 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 + 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 model: + description: The model that the [assistant](/docs/api-reference/assistants) used for this run. type: string - description: The model used to generate the moderation results. - results: + 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 - description: A list of moderation objects. + maxItems: 20 items: - type: object - properties: - flagged: - type: boolean - description: Whether the content violates [OpenAI's usage policies](/policies/usage-policies). - 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 harrassment. - 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 + oneOf: + - $ref: "#/components/schemas/AssistantToolsCode" + - $ref: "#/components/schemas/AssistantToolsRetrieval" + - $ref: "#/components/schemas/AssistantToolsFunction" + x-oaiExpandable: true + file_ids: + description: The list of [File](/docs/api-reference/files) IDs the [assistant](/docs/api-reference/assistants) used for this run. + default: [] + type: array + items: + type: string + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true + usage: + $ref: "#/components/schemas/RunCompletionUsage" + 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 + - file_ids + - metadata + - usage + 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", + "instructions": null, + "tools": [{"type": "retrieval"}, {"type": "code_interpreter"}], + "file_ids": [], + "metadata": {}, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + } + } + 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. + type: 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 + 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/AssistantToolsRetrieval" + - $ref: "#/components/schemas/AssistantToolsFunction" + x-oaiExpandable: true + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true required: - - id - - model - - results - x-oaiMeta: - name: The moderation object - example: *moderation_example - - ListFilesResponse: + - thread_id + - assistant_id + ListRunsResponse: type: object properties: object: type: string + example: "list" data: type: array items: - $ref: "#/components/schemas/OpenAIFile" + $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 - - CreateFileRequest: + - first_id + - last_id + - has_more + ModifyRunRequest: type: object additionalProperties: false properties: - file: - description: | - Name of the [JSON Lines](https://jsonlines.readthedocs.io/en/latest/) file to be uploaded. + 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. + required: + - tool_outputs - If the `purpose` is set to "fine-tune", the file will be used for fine-tuning. + RunToolCallObject: + type: object + description: Tool call objects + properties: + id: type: string - format: binary - purpose: - description: | - The intended purpose of the uploaded documents. + 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 - Use "fine-tune" for [fine-tuning](/docs/api-reference/fine-tuning). This allows us to validate the format of the uploaded file. + 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. + type: 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/AssistantToolsRetrieval" + - $ref: "#/components/schemas/AssistantToolsFunction" + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true required: - - file - - purpose + - thread_id + - assistant_id - DeleteFileResponse: + 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 - deleted: - type: boolean + enum: ["thread"] + created_at: + description: The Unix timestamp (in seconds) for when the thread was created. + type: integer + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true required: - id - object - - deleted + - created_at + - metadata + x-oaiMeta: + name: The thread object + beta: true + example: | + { + "id": "thread_abc123", + "object": "thread", + "created_at": 1698107661, + "metadata": {} + } - CreateFineTuningJobRequest: + CreateThreadRequest: type: object + additionalProperties: false properties: - training_file: - description: | - The ID of an uploaded file that contains training data. - - See [upload file](/docs/api-reference/files/upload) 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`. - - See the [fine-tuning guide](/docs/guides/fine-tuning) for more details. - type: string - example: "file-abc123" - 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 + messages: + description: A list of [messages](/docs/api-reference/messages) to start the thread with. + type: array + items: + $ref: "#/components/schemas/CreateMessageRequest" + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map nullable: true - example: "file-abc123" - 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 - hyperparameters: + + ModifyThreadRequest: + type: object + additionalProperties: false + properties: + metadata: + description: *metadata_description type: object - description: The hyperparameters used for the fine-tuning job. - properties: - 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. + x-oaiTypeLabel: map + nullable: true - For example, a `suffix` of "custom-model-name" would produce a model name like `ft:gpt-3.5-turbo:openai:custom-model-name:7p4lURel`. + DeleteThreadResponse: + type: object + properties: + id: type: string - minLength: 1 - maxLength: 40 - default: null - nullable: true + deleted: + type: boolean + object: + type: string + enum: [thread.deleted] required: - - training_file - - model + - id + - object + - deleted - ListFineTuningJobEventsResponse: - type: object + ListThreadsResponse: properties: object: type: string + example: "list" data: type: array items: - $ref: "#/components/schemas/FineTuningJobEvent" + $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 - CreateFineTuneRequest: + MessageObject: type: object + title: The message object + description: Represents a message within a [thread](/docs/api-reference/threads). properties: - training_file: - description: | - The ID of an uploaded file that contains training data. - - See [upload file](/docs/api-reference/files/upload) for how to upload a file. - - Your dataset must be formatted as a JSONL file, where each training - example is a JSON object with the keys "prompt" and "completion". - Additionally, you must upload your file with the purpose `fine-tune`. - - See the [fine-tuning guide](/docs/guides/legacy-fine-tuning/creating-training-data) for more details. + id: + description: The identifier, which can be referenced in API endpoints. type: string - example: "file-abc123" - 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](/docs/guides/legacy-fine-tuning/analyzing-your-fine-tuned-model). - Your train and validation data should be mutually exclusive. - - Your dataset must be formatted as a JSONL file, where each validation - example is a JSON object with the keys "prompt" and "completion". - Additionally, you must upload your file with the purpose `fine-tune`. - - See the [fine-tuning guide](/docs/guides/legacy-fine-tuning/creating-training-data) for more details. + object: + description: The object type, which is always `thread.message`. type: string - nullable: true - example: "file-abc123" - model: - description: | - The name of the base model to fine-tune. You can select one of "ada", - "babbage", "curie", "davinci", or a fine-tuned model created after 2022-04-21 and before 2023-08-22. - To learn more about these models, see the - [Models](/docs/models) documentation. - default: "curie" - example: "curie" - nullable: true - anyOf: - - type: string - - type: string - enum: ["ada", "babbage", "curie", "davinci"] - x-oaiTypeLabel: string - n_epochs: - description: | - The number of epochs to train the model for. An epoch refers to one - full cycle through the training dataset. - default: 4 - type: integer - nullable: true - batch_size: - description: | - The batch size to use for training. The batch size is the number of - training examples used to train a single forward and backward pass. - - By default, the batch size will be dynamically configured to be - ~0.2% of the number of examples in the training set, capped at 256 - - in general, we've found that larger batch sizes tend to work better - for larger datasets. - default: null - type: integer - nullable: true - learning_rate_multiplier: - description: | - The learning rate multiplier to use for training. - The fine-tuning learning rate is the original learning rate used for - pretraining multiplied by this value. - - By default, the learning rate multiplier is the 0.05, 0.1, or 0.2 - depending on final `batch_size` (larger learning rates tend to - perform better with larger batch sizes). We recommend experimenting - with values in the range 0.02 to 0.2 to see what produces the best - results. - default: null - type: number - nullable: true - prompt_loss_weight: - description: | - The weight to use for loss on the prompt tokens. This controls how - much the model tries to learn to generate the prompt (as compared - to the completion which always has a weight of 1.0), and can add - a stabilizing effect to training when completions are short. - - If prompts are extremely long (relative to completions), it may make - sense to reduce this weight so as to avoid over-prioritizing - learning the prompt. - default: 0.01 - type: number - nullable: true - compute_classification_metrics: - description: | - If set, we calculate classification-specific metrics such as accuracy - and F-1 score using the validation set at the end of every epoch. - These metrics can be viewed in the [results file](/docs/guides/legacy-fine-tuning/analyzing-your-fine-tuned-model). - - In order to compute classification metrics, you must provide a - `validation_file`. Additionally, you must - specify `classification_n_classes` for multiclass classification or - `classification_positive_class` for binary classification. - type: boolean - default: false - nullable: true - classification_n_classes: - description: | - The number of classes in a classification task. - - This parameter is required for multiclass classification. + enum: ["thread.message"] + created_at: + description: The Unix timestamp (in seconds) for when the message was created. type: integer - default: null - nullable: true - classification_positive_class: - description: | - The positive class in binary classification. - - This parameter is needed to generate precision, recall, and F1 - metrics when doing binary classification. + thread_id: + description: The [thread](/docs/api-reference/threads) ID that this message belongs to. type: string - default: null - nullable: true - classification_betas: - description: | - If this is provided, we calculate F-beta scores at the specified - beta values. The F-beta score is a generalization of F-1 score. - This is only used for binary classification. - - With a beta of 1 (i.e. the F-1 score), precision and recall are - given the same weight. A larger beta score puts more weight on - recall and less on precision. A smaller beta score puts more weight - on precision and less on recall. + 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: - type: number - example: [0.6, 1, 1.5, 2] - default: null - nullable: true - suffix: - description: | - A string of up to 40 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 `ada:ft-your-org:custom-model-name-2022-02-15-04-21-04`. - type: string - minLength: 1 - maxLength: 40 - default: null + oneOf: + - $ref: "#/components/schemas/MessageContentImageFileObject" + - $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 - required: - - training_file - - ListFineTunesResponse: - type: object - properties: - object: + run_id: + description: If applicable, the ID of the [run](/docs/api-reference/runs) associated with the authoring of this message. type: string - data: + nullable: true + file_ids: + description: A list of [file](/docs/api-reference/files) IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can access files. A maximum of 10 files can be attached to a message. + default: [] + maxItems: 10 type: array items: - $ref: "#/components/schemas/FineTune" + type: string + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true required: + - id - object - - data + - created_at + - thread_id + - role + - content + - assistant_id + - run_id + - file_ids + - 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": [] + } + } + ], + "file_ids": [], + "assistant_id": "asst_abc123", + "run_id": "run_abc123", + "metadata": {} + } - ListFineTuneEventsResponse: + CreateMessageRequest: type: object + additionalProperties: false + required: + - role + - content properties: - object: + role: type: string - data: + enum: ["user"] + description: The role of the entity that is creating the message. Currently only `user` is supported. + content: + type: string + minLength: 1 + maxLength: 32768 + description: The content of the message. + file_ids: + description: A list of [File](/docs/api-reference/files) IDs that the message should use. There can be a maximum of 10 files attached to a message. Useful for tools like `retrieval` and `code_interpreter` that can access and use files. + default: [] type: array + minItems: 1 + maxItems: 10 items: - $ref: "#/components/schemas/FineTuneEvent" - required: - - object - - data + type: string + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true - CreateEmbeddingRequest: + ModifyMessageRequest: type: object additionalProperties: false properties: - model: - description: *model_description - example: "text-embedding-ada-002" - anyOf: - - type: string - - type: string - enum: ["text-embedding-ada-002"] - x-oaiTypeLabel: string - 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. Each input must not exceed the max input tokens for the model (8191 tokens for `text-embedding-ada-002`) and cannot be an empty string. [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) for counting tokens. - example: "The quick brown fox jumped over the lazy dog" - 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]]" - user: *end_user_param_configuration - required: - - model - - input + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true - CreateEmbeddingResponse: + DeleteMessageResponse: type: object properties: + id: + type: string + deleted: + type: boolean object: type: string - description: The object type, which is always "embedding". - model: + enum: [thread.message.deleted] + required: + - id + - object + - deleted + + ListMessagesResponse: + properties: + object: type: string - description: The name of the model used to generate the embedding. + example: "list" data: type: array - description: The list of embeddings generated by the model. items: - $ref: "#/components/schemas/Embedding" - 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 + $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 - - model - data - - usage + - first_id + - last_id + - has_more - CreateTranscriptionRequest: + MessageContentImageFileObject: + title: Image file type: object - additionalProperties: false + description: References an image [File](/docs/api-reference/files) in the content of a message. 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` 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 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 - 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: + 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. + type: string + required: + - file_id required: - - file - - model + - type + - image_file - # Note: This does not currently support the non-default response format types. - CreateTranscriptionResponse: + MessageContentTextObject: + title: Text type: object + description: The text content that is part of a message. properties: - text: + 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 - CreateTranslationRequest: + MessageContentTextAnnotationsFileCitationObject: + title: File citation type: object - additionalProperties: false + 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 "retrieval" tool to search files. 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` 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: + description: Always `file_citation`. 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. - CreateTranslationResponse: - type: object - properties: + 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 + required: + - file_id + - quote + start_index: + type: integer + minimum: 0 + end_index: + type: integer + minimum: 0 required: + - type - text + - file_citation + - start_index + - end_index - Model: - title: Model - description: Describes an OpenAI model offering that can be used with the API. + 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: - id: + type: + description: Always `file_path`. type: string - description: The model identifier, which can be referenced in the API endpoints. - object: + enum: ["file_path"] + text: + description: The text in the message content that needs to be replaced. type: string - description: The object type, which is always "model". - created: + 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 - description: The Unix timestamp (in seconds) when the model was created. - 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 + minimum: 0 + end_index: + type: integer + minimum: 0 + required: + - type + - text + - file_path + - start_index + - end_index - OpenAIFile: - title: OpenAIFile + RunStepObject: + type: object + title: Run steps description: | - The `File` object represents a document that has been uploaded to OpenAI. + 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 - description: The file identifier, which can be referenced in the API endpoints. object: + description: The object type, which is always `thread.run.step`. type: string - description: The object type, which is always "file". - bytes: - type: integer - description: The size of the file in bytes. + enum: ["thread.run.step"] created_at: + description: The Unix timestamp (in seconds) for when the run step was created. type: integer - description: The Unix timestamp (in seconds) for when the file was created. - filename: + assistant_id: + description: The ID of the [assistant](/docs/api-reference/assistants) associated with the run step. type: string - description: The name of the file. - purpose: + thread_id: + description: The ID of the [thread](/docs/api-reference/threads) that was run. type: string - description: The intended purpose of the file. Currently, only "fine-tune" is supported. - status: + run_id: + description: The ID of the [run](/docs/api-reference/runs) that this run step is a part of. type: string - description: The current status of the file, which can be either `uploaded`, `processed`, `pending`, `error`, `deleting` or `deleted`. - status_details: + 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 - description: | - Additional details about the status of the file. If the file is in the `error` state, this will include a message describing the error. + 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 - - bytes - created_at - - filename - - purpose - - format + - 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 file object - example: | - { - "id": "file-abc123", - "object": "file", - "bytes": 120000, - "created_at": 1677610602, - "filename": "my_file.jsonl", - "purpose": "fine-tune", - "status": "uploaded", - "status_details": null - } - Embedding: - type: object - description: | - Represents an embedding vector returned by embedding endpoint. + name: The run step object + beta: true + example: *run_step_object_example + + ListRunStepsResponse: properties: - index: - type: integer - description: The index of the embedding in the list of embeddings. object: type: string - description: The object type, which is always "embedding". - embedding: + example: "list" + data: 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 + $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: - - 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 - } + - data + - first_id + - last_id + - has_more - FineTuningJob: - title: FineTuningJob - description: | - The `fine_tuning.job` object represents a fine-tuning job that has been created through the API. + RunStepDetailsMessageCreationObject: + title: Message creation + type: object + description: Details of the message creation by the run step. properties: - id: + type: + description: Always `message_creation`. type: string - description: The object identifier, which can be referenced in the API endpoints. - object: + 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 + + RunStepDetailsToolCallsObject: + title: Tool calls + type: object + description: Details of the tool call. + properties: + type: + description: Always `tool_calls`. type: string - description: The object type, which is always "fine_tuning.job". - created_at: - type: integer - description: The Unix timestamp (in seconds) for when the fine-tuning job was created. - 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. - model: + 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`, `retrieval`, or `function`. + items: + oneOf: + - $ref: "#/components/schemas/RunStepDetailsToolCallsCodeObject" + - $ref: "#/components/schemas/RunStepDetailsToolCallsRetrievalObject" + - $ref: "#/components/schemas/RunStepDetailsToolCallsFunctionObject" + x-oaiExpandable: true + required: + - type + - tool_calls + + 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 base model that is being fine-tuned. - fine_tuned_model: + description: The ID of the tool call. + type: 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. - organization_id: + 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 + + 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 - description: The organization that owns the fine-tuning job. - status: + enum: ["logs"] + logs: type: string - description: The current status of the fine-tuning job, which can be either `validating_files`, `queued`, `running`, `succeeded`, `failed`, or `cancelled`. - hyperparameters: + description: The text output from the Code Interpreter tool call. + required: + - type + - logs + + RunStepDetailsToolCallsCodeOutputImageObject: + title: Code interpreter image output + type: object + properties: + type: + description: Always `image`. + type: string + enum: ["image"] + image: 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. + file_id: + description: The [file](/docs/api-reference/files) ID of the image. + type: string required: - - n_epochs - training_file: + - file_id + required: + - type + - image + + RunStepDetailsToolCallsRetrievalObject: + title: Retrieval tool call + type: object + properties: + id: 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: + description: The ID of the tool call object. + type: 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). - 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 - 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. - error: + description: The type of tool call. This is always going to be `retrieval` for this type of tool call. + enum: ["retrieval"] + retrieval: type: object - nullable: true - description: For fine-tuning jobs that have `failed`, this will contain more information on the cause of the failure. + description: For now, this is always going to be an empty object. + x-oaiTypeLabel: map + required: + - id + - type + - retrieval + + 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: - message: + name: type: string - description: A human-readable error message. - code: + description: The name of the function. + arguments: type: string - description: A machine-readable error code. - param: + description: The arguments passed to the function. + output: 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. + 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: - - message - - code - - param + - name + - arguments + - output required: - id - - object - - created_at - - finished_at - - model - - fine_tuned_model - - organization_id - - status - - hyperparameters - - training_file - - validation_file - - result_files - - trained_tokens - - error - x-oaiMeta: - name: The fine-tuning job object - example: *fine_tuning_example + - type + - function - FineTuningEvent: - title: FineTuningEvent + AssistantFileObject: + type: object + title: Assistant files + description: A list of [Files](/docs/api-reference/files) attached to an `assistant`. properties: + id: + description: The identifier, which can be referenced in API endpoints. + type: string object: + description: The object type, which is always `assistant.file`. type: string + enum: [assistant.file] created_at: + description: The Unix timestamp (in seconds) for when the assistant file was created. type: integer - level: - type: string - message: + assistant_id: + description: The assistant ID that the file is attached to. type: string - data: - oneOf: - - type: string - default: none - enum: [none, string] - type: - oneOf: - - type: string - default: none - enum: ["message", "metrics"] required: + - id - object - - created_at - - level - - message - x-oiMeta: - name: The fine-tuning event object + - created_at + - assistant_id + x-oaiMeta: + name: The assistant file object + beta: true example: | { - "object": "fine_tuning.job.event", - "created_at": "1689376978", - "level": "info" | "warn" | "error", - "message": "", - "data": null | JSON, - "type": "message"| "metrics" + "id": "file-abc123", + "object": "assistant.file", + "created_at": 1699055364, + "assistant_id": "asst_abc123" } - FineTune: - title: FineTune - deprecated: true - description: | - The `FineTune` object represents a legacy fine-tune job that has been created through the API. + CreateAssistantFileRequest: + type: object + additionalProperties: false + properties: + file_id: + description: A [File](/docs/api-reference/files) ID (with `purpose="assistants"`) that the assistant should use. Useful for tools like `retrieval` and `code_interpreter` that can access files. + type: string + required: + - file_id + + DeleteAssistantFileResponse: + type: object + description: Deletes the association between the assistant and the file, but does not delete the [File](/docs/api-reference/files) object itself. properties: id: type: string - description: The object identifier, which can be referenced in the API endpoints. + deleted: + type: boolean object: type: string - description: The object type, which is always "fine-tune". - created_at: - type: integer - description: The Unix timestamp (in seconds) for when the fine-tuning job was created. - updated_at: - type: integer - description: The Unix timestamp (in seconds) for when the fine-tuning job was last updated. - model: - type: string - description: The base model that is being fine-tuned. - fine_tuned_model: - type: string - nullable: true - description: The name of the fine-tuned model that is being created. - organization_id: - type: string - description: The organization that owns the fine-tuning job. - status: + enum: [assistant.file.deleted] + required: + - id + - object + - deleted + ListAssistantFilesResponse: + properties: + object: type: string - description: The current status of the fine-tuning job, which can be either `created`, `running`, `succeeded`, `failed`, or `cancelled`. - hyperparams: - type: object - description: The hyperparameters used for the fine-tuning job. See the [fine-tuning guide](/docs/guides/legacy-fine-tuning/hyperparameters) for more details. - properties: - n_epochs: - type: integer - description: | - The number of epochs to train the model for. An epoch refers to one - full cycle through the training dataset. - batch_size: - type: integer - description: | - The batch size to use for training. The batch size is the number of - training examples used to train a single forward and backward pass. - prompt_loss_weight: - type: number - description: | - The weight to use for loss on the prompt tokens. - learning_rate_multiplier: - type: number - description: | - The learning rate multiplier to use for training. - compute_classification_metrics: - type: boolean - description: | - The classification metrics to compute using the validation dataset at the end of every epoch. - classification_positive_class: - type: string - description: | - The positive class to use for computing classification metrics. - classification_n_classes: - type: integer - description: | - The number of classes to use for computing classification metrics. - required: - - n_epochs - - batch_size - - prompt_loss_weight - - learning_rate_multiplier - training_files: - type: array - description: The list of files used for training. - items: - $ref: "#/components/schemas/OpenAIFile" - validation_files: - type: array - description: The list of files used for validation. - items: - $ref: "#/components/schemas/OpenAIFile" - result_files: - type: array - description: The compiled results files for the fine-tuning job. - items: - $ref: "#/components/schemas/OpenAIFile" - events: + example: "list" + data: type: array - description: The list of events that have been observed in the lifecycle of the FineTune job. items: - $ref: "#/components/schemas/FineTuneEvent" + $ref: "#/components/schemas/AssistantFileObject" + first_id: + type: string + example: "file-abc123" + last_id: + type: string + example: "file-abc456" + has_more: + type: boolean + example: false required: - - id - object - - created_at - - updated_at - - model - - fine_tuned_model - - organization_id - - status - - hyperparams - - training_files - - validation_files - - result_files - x-oaiMeta: - name: The fine-tune object - example: *fine_tune_example + - data + - items + - first_id + - last_id + - has_more - FineTuningJobEvent: - title: FineTuningJobEvent + MessageFileObject: + type: object + title: Message files + description: A list of files attached to a `message`. properties: id: + description: The identifier, which can be referenced in API endpoints. type: string object: + description: The object type, which is always `thread.message.file`. type: string + enum: ["thread.message.file"] created_at: + description: The Unix timestamp (in seconds) for when the message file was created. type: integer - level: - type: string - enum: ["info", "warn", "error"] - message: + message_id: + description: The ID of the [message](/docs/api-reference/messages) that the [File](/docs/api-reference/files) is attached to. type: string required: - id - object - created_at - - level - - message - x-oiMeta: - name: The fine-tuning job event object + - message_id + x-oaiMeta: + name: The message file object + beta: true example: | { - "object": "event", - "id": "ftevent-abc123" - "created_at": 1677610602, - "level": "info", - "message": "Created fine-tuning job" + "id": "file-abc123", + "object": "thread.message.file", + "created_at": 1698107661, + "message_id": "message_QLoItBbqwyAJEzlTy4y9kOMM", + "file_id": "file-abc123" } - FineTuneEvent: - title: FineTuneEvent + ListMessageFilesResponse: properties: object: type: string - created_at: - type: integer - level: + example: "list" + data: + type: array + items: + $ref: "#/components/schemas/MessageFileObject" + first_id: type: string - message: + example: "file-abc123" + last_id: type: string + example: "file-abc456" + has_more: + type: boolean + example: false required: - object - - created_at - - level - - message - x-oiMeta: - name: The fine-tune event object - example: | - { - "object": "event", - "created_at": 1677610602, - "level": "info", - "message": "Created fine-tune job" - } - CompletionUsage: - type: object - description: Usage statistics for the completion request. - properties: - prompt_tokens: - type: integer - description: Number of tokens in the prompt. - completion_tokens: - type: integer - description: Number of tokens in the generated completion. - total_tokens: - type: integer - description: Total number of tokens used in the request (prompt + completion). - required: - - prompt_tokens - - completion_tokens - - total_tokens + - data + - items + - first_id + - last_id + - has_more security: - ApiKeyAuth: [] - x-oaiMeta: groups: # > General Notes @@ -4193,10 +8697,13 @@ x-oaiMeta: - id: audio title: Audio description: | - Learn how to turn audio into text. + Learn how to turn audio into text or text into audio. Related guide: [Speech to text](/docs/guides/speech-to-text) sections: + - type: endpoint + key: createSpeech + path: createSpeech - type: endpoint key: createTranscription path: createTranscription @@ -4208,31 +8715,17 @@ x-oaiMeta: description: | Given a list of messages comprising a conversation, the model will return a response. - Related guide: [Chat completions](/docs/guides/gpt) + Related guide: [Chat Completions](/docs/guides/text-generation) sections: + - type: endpoint + key: createChatCompletion + path: create - type: object key: CreateChatCompletionResponse path: object - type: object key: CreateChatCompletionStreamResponse path: streaming - - type: endpoint - key: createChatCompletion - path: create - - id: completions - title: Completions - legacy: true - 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. We recommend most users use our Chat completions API. [Learn more](/docs/deprecations/2023-07-06-gpt-and-embeddings) - - Related guide: [Legacy Completions](/docs/guides/gpt/completions-api) - sections: - - type: object - key: CreateCompletionResponse - path: object - - type: endpoint - key: createCompletion - path: create - id: embeddings title: Embeddings description: | @@ -4240,59 +8733,63 @@ x-oaiMeta: Related guide: [Embeddings](/docs/guides/embeddings) sections: - - type: object - key: Embedding - path: object - 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) + Related guide: [Fine-tune models](/docs/guides/fine-tuning) sections: - - type: object - path: object - key: FineTuningJob - type: endpoint key: createFineTuningJob path: create - type: endpoint key: listPaginatedFineTuningJobs + path: list + - type: endpoint + key: listFineTuningEvents + path: list-events - type: endpoint key: retrieveFineTuningJob path: retrieve - type: endpoint key: cancelFineTuningJob path: cancel - - type: endpoint - key: listFineTuningEvents - path: list-events + - type: object + key: FineTuningJob + path: object + - type: object + key: FineTuningJobEvent + path: event-object - id: files title: Files description: | - Files are used to upload documents that can be used with features like [fine-tuning](/docs/api-reference/fine-tuning). + Files are used to upload documents that can be used with features like [Assistants](/docs/api-reference/assistants) and [Fine-tuning](/docs/api-reference/fine-tuning). sections: - - type: object - key: OpenAIFile - path: object - - type: endpoint - key: listFiles - path: list - type: endpoint key: createFile path: create - type: endpoint - key: deleteFile - path: delete + 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: images title: Images description: | @@ -4300,9 +8797,6 @@ x-oaiMeta: Related guide: [Image generation](/docs/guides/images) sections: - - type: object - key: Image - path: object - type: endpoint key: createImage path: create @@ -4312,14 +8806,14 @@ x-oaiMeta: - 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. sections: - - type: object - key: Model - path: object - type: endpoint key: listModels path: list @@ -4329,6 +8823,9 @@ x-oaiMeta: - type: endpoint key: deleteModel path: delete + - type: object + key: Model + path: object - id: moderations title: Moderations description: | @@ -4336,47 +8833,158 @@ x-oaiMeta: Related guide: [Moderations](/docs/guides/moderation) 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) + sections: - type: endpoint - key: createModeration - path: create - - id: fine-tunes - title: Fine-tunes - deprecated: true + key: createAssistant + path: createAssistant + - type: endpoint + key: createAssistantFile + path: createAssistantFile + - type: endpoint + key: listAssistants + path: listAssistants + - type: endpoint + key: listAssistantFiles + path: listAssistantFiles + - type: endpoint + key: getAssistant + path: getAssistant + - type: endpoint + key: getAssistantFile + path: getAssistantFile + - type: endpoint + key: modifyAssistant + path: modifyAssistant + - type: endpoint + key: deleteAssistant + path: deleteAssistant + - type: endpoint + key: deleteAssistantFile + path: deleteAssistantFile + - type: object + key: AssistantObject + path: object + - type: object + key: AssistantFileObject + path: file-object + - id: threads + title: Threads + beta: true description: | - Manage legacy fine-tuning jobs to tailor a model to your specific training data. + Create threads that assistants can interact with. - We recommend transitioning to the updating [fine-tuning API](/docs/guides/fine-tuning) + Related guide: [Assistants](/docs/assistants/overview) 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 - key: FineTune + - id: messages + title: Messages + beta: true + description: | + Create messages within threads + + Related guide: [Assistants](/docs/assistants/overview) + sections: - type: endpoint - key: createFineTune - path: create + key: createMessage + path: createMessage - type: endpoint - key: listFineTunes - path: list + key: listMessages + path: listMessages - type: endpoint - key: retrieveFineTune - path: retrieve + key: listMessageFiles + path: listMessageFiles - type: endpoint - key: cancelFineTune - path: cancel + key: getMessage + path: getMessage - type: endpoint - key: listFineTuneEvents - path: list-events - - id: edits - title: Edits - deprecated: true + key: getMessageFile + path: getMessageFile + - type: endpoint + key: modifyMessage + path: modifyMessage + - type: object + key: MessageObject + path: object + - type: object + key: MessageFileObject + path: file-object + - id: runs + title: Runs + beta: true description: | - Given a prompt and an instruction, the model will return an edited version of the prompt. + Represents an execution run on a thread. + + Related guide: [Assistants](/docs/assistants/overview) sections: + - type: endpoint + key: createRun + path: createRun + - type: endpoint + key: createThreadAndRun + path: createThreadAndRun + - type: endpoint + key: listRuns + path: listRuns + - type: endpoint + key: listRunSteps + path: listRunSteps + - type: endpoint + key: getRun + path: getRun + - type: endpoint + key: getRunStep + path: getRunStep + - type: endpoint + key: modifyRun + path: modifyRun + - type: endpoint + key: submitToolOuputsToRun + path: submitToolOutputs + - type: endpoint + key: cancelRun + path: cancelRun - type: object - key: CreateEditResponse + key: RunObject path: object + - type: object + key: RunStepObject + path: step-object + - id: completions + title: Completions + legacy: true + 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. Most models that support the legacy Completions endpoint [will be shut off on January 4th, 2024](/docs/deprecations/2023-07-06-gpt-and-embeddings). + sections: - type: endpoint - key: createEdit + key: createCompletion path: create + - type: object + key: CreateCompletionResponse + path: object \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index a77b672a3..1c8159a55 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,18 +8,77 @@ "name": "openai-tsp", "version": "0.1.0", "dependencies": { - "@typespec/compiler": "^0.49.0-dev.11", - "@typespec/openapi": "^0.49.0-dev.4", - "@typespec/openapi3": "^0.49.0-dev.10", - "@typespec/rest": "^0.49.0-dev.3" + "@azure-tools/typespec-csharp": "latest", + "@typespec/compiler": "^0.52.0", + "@typespec/http": "^0.52.0", + "@typespec/openapi": "^0.52.0", + "@typespec/openapi3": "^0.52.0", + "@typespec/rest": "^0.52.0", + "@typespec/versioning": "^0.52.0" + } + }, + "node_modules/@autorest/csharp": { + "version": "3.0.0-beta.20240202.1", + "resolved": "https://registry.npmjs.org/@autorest/csharp/-/csharp-3.0.0-beta.20240202.1.tgz", + "integrity": "sha512-us+dLFipCJbR0uDLiUg7nFsVpV2bJB6CWSTKc30WbE8HvrX0inYxm97LcDw3k3EiOM5frQGSYetWJgXbyuW+jw==" + }, + "node_modules/@azure-tools/typespec-azure-core": { + "version": "0.38.0", + "resolved": "https://registry.npmjs.org/@azure-tools/typespec-azure-core/-/typespec-azure-core-0.38.0.tgz", + "integrity": "sha512-ASM+njC2lpzPykzw2OicWIaAOH+OBe3bVMrufEnINBjlr7owAtudvjrTLLWmAVMBciL/YOF579KdyjxTbaxJ5A==", + "peer": true, + "engines": { + "node": ">=18.0.0" + }, + "peerDependencies": { + "@typespec/compiler": "~0.52.0", + "@typespec/http": "~0.52.0", + "@typespec/rest": "~0.52.0" + } + }, + "node_modules/@azure-tools/typespec-client-generator-core": { + "version": "0.38.0", + "resolved": "https://registry.npmjs.org/@azure-tools/typespec-client-generator-core/-/typespec-client-generator-core-0.38.0.tgz", + "integrity": "sha512-DUDIHJikz3Ai8uPk3vKFoMkkGPUxoD5DbGdwkN/pQxaL6Aze8HV4LGEOGtvaIu0SsGjCX9G3XPAXoBoupYgXbw==", + "peer": true, + "dependencies": { + "change-case": "~5.3.0", + "pluralize": "^8.0.0" + }, + "engines": { + "node": ">=18.0.0" + }, + "peerDependencies": { + "@typespec/compiler": "~0.52.0", + "@typespec/http": "~0.52.0", + "@typespec/rest": "~0.52.0", + "@typespec/versioning": "~0.52.0" + } + }, + "node_modules/@azure-tools/typespec-csharp": { + "version": "0.2.0-beta.20240202.1", + "resolved": "https://registry.npmjs.org/@azure-tools/typespec-csharp/-/typespec-csharp-0.2.0-beta.20240202.1.tgz", + "integrity": "sha512-V+AvsqS7OMUcYIdIcVEyhS3i2MVP/rPZqCzDpIOJAcH/4oK4dHVz4RcgB/7+fM+PY7agWrM3zvR5XTkAeBqL9A==", + "dependencies": { + "@autorest/csharp": "3.0.0-beta.20240202.1", + "json-serialize-refs": "0.1.0-0", + "winston": "^3.8.2" + }, + "peerDependencies": { + "@azure-tools/typespec-azure-core": ">=0.36.0 <1.0.0", + "@azure-tools/typespec-client-generator-core": ">=0.36.0 <1.0.0", + "@typespec/compiler": ">=0.50.0 <1.0.0", + "@typespec/http": ">=0.50.0 <1.0.0", + "@typespec/rest": ">=0.50.0 <1.0.0", + "@typespec/versioning": ">=0.50.0 <1.0.0" } }, "node_modules/@babel/code-frame": { - "version": "7.22.13", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz", - "integrity": "sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==", + "version": "7.23.5", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.23.5.tgz", + "integrity": "sha512-CgH3s1a96LipHCmSUmYFPwY7MNx8C3avkq7i4Wl3cfa662ldtUe4VM1TPXX70pfmrlWTb6jLqTYrZyT2ZTJBgA==", "dependencies": { - "@babel/highlight": "^7.22.13", + "@babel/highlight": "^7.23.4", "chalk": "^2.4.2" }, "engines": { @@ -27,19 +86,19 @@ } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.5.tgz", - "integrity": "sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz", + "integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==", "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/highlight": { - "version": "7.22.13", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.13.tgz", - "integrity": "sha512-C/BaXcnnvBCmHTpz/VGZ8jgtE2aYlW4hxDhseJAWZb7gqGM/qtCK6iZUb0TyKFf7BOUsBH7Q7fkRsDRhg1XklQ==", + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.23.4.tgz", + "integrity": "sha512-acGdbYSfp2WheJoJm/EBBBLh/ID8KDc64ISZ9DYtBmC8/Q204PZJLHyzeB5qMzJ5trcOkybd78M4x2KWsUq++A==", "dependencies": { - "@babel/helper-validator-identifier": "^7.22.5", + "@babel/helper-validator-identifier": "^7.22.20", "chalk": "^2.4.2", "js-tokens": "^4.0.0" }, @@ -47,6 +106,24 @@ "node": ">=6.9.0" } }, + "node_modules/@colors/colors": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.6.0.tgz", + "integrity": "sha512-Ir+AOibqzrIsL6ajt3Rz3LskB7OiMVHqltZmspbW/TJuTVuyOMirVqAkjfY6JISiLHgyNqicAC8AyHHGzNd/dA==", + "engines": { + "node": ">=0.1.90" + } + }, + "node_modules/@dabh/diagnostics": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@dabh/diagnostics/-/diagnostics-2.0.3.tgz", + "integrity": "sha512-hrlQOIi7hAfzsMqlGSFyVucrx38O+j6wiGOf//H2ecvIEqYN4ADBSS2iLMh5UFyDunCNniUIPk/q3riFv45xRA==", + "dependencies": { + "colorspace": "1.1.x", + "enabled": "2.0.x", + "kuler": "^2.0.0" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -79,23 +156,39 @@ "node": ">= 8" } }, + "node_modules/@sindresorhus/merge-streams": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/merge-streams/-/merge-streams-1.0.0.tgz", + "integrity": "sha512-rUV5WyJrJLoloD4NDN1V1+LDMDWOa4OTsT4yYJwQNpTU6FWxkxHpL7eu4w+DmiH8x/EAM1otkPE1+LaspIbplw==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@types/triple-beam": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.5.tgz", + "integrity": "sha512-6WaYesThRMCl19iryMYP7/x2OVgCtbIVflDGFpWnb9irXI3UjYE4AzmYuiUKY1AJstGijoY+MgUszMgRxIYTYw==" + }, "node_modules/@typespec/compiler": { - "version": "0.49.0-dev.11", - "resolved": "https://registry.npmjs.org/@typespec/compiler/-/compiler-0.49.0-dev.11.tgz", - "integrity": "sha512-SNt6hqu017JhwU3qPpolsGRKgSnb9Wc4FZs5FPQ6i1Ktubtgx9Ac9pxEdSNgOsdoBC3efzbpNCBasLGms0V+Fw==", + "version": "0.52.0", + "resolved": "https://registry.npmjs.org/@typespec/compiler/-/compiler-0.52.0.tgz", + "integrity": "sha512-36cZ5RWxRjL4SUe41KjPh3j3RQibpUoOzHcSllQJ3ByTSZdXv1zckMHLiRfaAbTXUADSAn2GMs4ZO3s8GdOGIQ==", "dependencies": { - "@babel/code-frame": "~7.22.13", + "@babel/code-frame": "~7.23.5", "ajv": "~8.12.0", - "change-case": "~4.1.2", - "globby": "~13.2.2", + "change-case": "~5.3.0", + "globby": "~14.0.0", "mustache": "~4.2.0", "picocolors": "~1.0.0", - "prettier": "~3.0.3", + "prettier": "~3.1.1", "prompts": "~2.4.2", "semver": "^7.5.4", "vscode-languageserver": "~9.0.0", "vscode-languageserver-textdocument": "~1.0.8", - "yaml": "~2.3.2", + "yaml": "~2.3.4", "yargs": "~17.7.2" }, "bin": { @@ -103,72 +196,70 @@ "tsp-server": "cmd/tsp-server.js" }, "engines": { - "node": ">=16.0.0" + "node": ">=18.0.0" } }, "node_modules/@typespec/http": { - "version": "0.48.0", - "resolved": "https://registry.npmjs.org/@typespec/http/-/http-0.48.0.tgz", - "integrity": "sha512-e+0Y0Ky71flUNZSRzCfoOm8XvXsSYGmQgB9VZFDbLl8mQlXwuTfib4tWrU531TCtZHMnylbXx2wAk5+3uC6b9g==", - "peer": true, + "version": "0.52.1", + "resolved": "https://registry.npmjs.org/@typespec/http/-/http-0.52.1.tgz", + "integrity": "sha512-2i7t6eSKi96F/zt1w0yJvhRhubYej0F9o8jDRhPA+TZI6SAxcv/Vyi+lkKnkOcu90HPH7b8T+YNizudb00BO6A==", "engines": { - "node": ">=16.0.0" + "node": ">=18.0.0" }, "peerDependencies": { - "@typespec/compiler": "~0.48.0" + "@typespec/compiler": "~0.52.0" } }, "node_modules/@typespec/openapi": { - "version": "0.49.0-dev.4", - "resolved": "https://registry.npmjs.org/@typespec/openapi/-/openapi-0.49.0-dev.4.tgz", - "integrity": "sha512-qH2borMxQoAdiMDvd88MTvlF2vFZUzusDFtxmKx/GEy+aqkw7pAnR0fqeCbPGR/P8a6slpDchusY/le3608yAQ==", + "version": "0.52.0", + "resolved": "https://registry.npmjs.org/@typespec/openapi/-/openapi-0.52.0.tgz", + "integrity": "sha512-2Otnu9glehxvp6TU7NOHEniBDDKufV03XTmeVGgGEmu/j+cveAMg8lA1/O0RBpS2oHGsCFnMEuPcR8M1c0LI+Q==", "engines": { - "node": ">=16.0.0" + "node": ">=18.0.0" }, "peerDependencies": { - "@typespec/compiler": "~0.48.1 || >=0.49.0-dev <0.49.0", - "@typespec/http": "~0.48.0 || >=0.49.0-dev <0.49.0" + "@typespec/compiler": "~0.52.0", + "@typespec/http": "~0.52.0" } }, "node_modules/@typespec/openapi3": { - "version": "0.49.0-dev.10", - "resolved": "https://registry.npmjs.org/@typespec/openapi3/-/openapi3-0.49.0-dev.10.tgz", - "integrity": "sha512-J9oiVJKv3pTcNIUzftHS676w4LOxvQe6fqAAx37Nql7SJ3AZrqHXwOrlxjMKZHifU7T+V/KZKF8Y6Li4ORPTPw==", + "version": "0.52.0", + "resolved": "https://registry.npmjs.org/@typespec/openapi3/-/openapi3-0.52.0.tgz", + "integrity": "sha512-PPhNdpKQD2iHJemOaRUhnaeFWa4ApW4HtcZI+jrg4hyNSIwDYxL0OwwRohKjRUKM98iacpXvEh+5rKtkPiY2Qw==", "dependencies": { - "yaml": "~2.3.2" + "yaml": "~2.3.4" }, "engines": { - "node": ">=16.0.0" + "node": ">=18.0.0" }, "peerDependencies": { - "@typespec/compiler": "~0.48.1 || >=0.49.0-dev <0.49.0", - "@typespec/http": "~0.48.0 || >=0.49.0-dev <0.49.0", - "@typespec/openapi": "~0.48.0 || >=0.49.0-dev <0.49.0", - "@typespec/versioning": "~0.48.0 || >=0.49.0-dev <0.49.0" + "@typespec/compiler": "~0.52.0", + "@typespec/http": "~0.52.0", + "@typespec/openapi": "~0.52.0", + "@typespec/versioning": "~0.52.0" } }, "node_modules/@typespec/rest": { - "version": "0.49.0-dev.3", - "resolved": "https://registry.npmjs.org/@typespec/rest/-/rest-0.49.0-dev.3.tgz", - "integrity": "sha512-/33xOp3N5wtUZ6O+kNssIzCEXR7+fjThtGysnsUL0lS8W3OesCgF9gKZH9fB0beaRlccmzFoRcHSOQLwalkfmg==", + "version": "0.52.0", + "resolved": "https://registry.npmjs.org/@typespec/rest/-/rest-0.52.0.tgz", + "integrity": "sha512-dLsY0fS60IVaAt4eCRcvEqorX/miPVV33du3dETTYYmbHtfEbvBKgTj/m6OH4noey7oaihlvLz5kYyLv8Am7zA==", "engines": { - "node": ">=16.0.0" + "node": ">=18.0.0" }, "peerDependencies": { - "@typespec/compiler": "~0.48.1 || >=0.49.0-dev <0.49.0", - "@typespec/http": "~0.48.0 || >=0.49.0-dev <0.49.0" + "@typespec/compiler": "~0.52.0", + "@typespec/http": "~0.52.0" } }, "node_modules/@typespec/versioning": { - "version": "0.48.0", - "resolved": "https://registry.npmjs.org/@typespec/versioning/-/versioning-0.48.0.tgz", - "integrity": "sha512-WF26vmMPwizhSnjX0ox23nbp7hthtB4cN/J5w1tlryXyp/BXySHoYsJEMK7fviSpj4WdreVXdM6wmRIG33zqig==", - "peer": true, + "version": "0.52.0", + "resolved": "https://registry.npmjs.org/@typespec/versioning/-/versioning-0.52.0.tgz", + "integrity": "sha512-Vr4WHaZiDOxJqRp8/u6X0R45E+rFKEprYmSZX0o5bzetj0cVjOIEbQZvDJCif1Uz0S3K0KKfqf/kYmdYWMJ7Dw==", "engines": { - "node": ">=16.0.0" + "node": ">=18.0.0" }, "peerDependencies": { - "@typespec/compiler": "~0.48.0" + "@typespec/compiler": "~0.52.0" } }, "node_modules/ajv": { @@ -205,6 +296,11 @@ "node": ">=4" } }, + "node_modules/async": { + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.5.tgz", + "integrity": "sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg==" + }, "node_modules/braces": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", @@ -216,25 +312,6 @@ "node": ">=8" } }, - "node_modules/camel-case": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/camel-case/-/camel-case-4.1.2.tgz", - "integrity": "sha512-gxGWBrTT1JuMx6R+o5PTXMmUnhnVzLQ9SNutD4YqKtI6ap897t3tKECYla6gCWEkplXnlNybEkZg9GEGxKFCgw==", - "dependencies": { - "pascal-case": "^3.1.2", - "tslib": "^2.0.3" - } - }, - "node_modules/capital-case": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/capital-case/-/capital-case-1.0.4.tgz", - "integrity": "sha512-ds37W8CytHgwnhGGTi88pcPyR15qoNkOpYwmMMfnWqqWgESapLqvDx6huFjQ5vqWSn2Z06173XNA7LtMOeUh1A==", - "dependencies": { - "no-case": "^3.0.4", - "tslib": "^2.0.3", - "upper-case-first": "^2.0.2" - } - }, "node_modules/chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -249,23 +326,9 @@ } }, "node_modules/change-case": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/change-case/-/change-case-4.1.2.tgz", - "integrity": "sha512-bSxY2ws9OtviILG1EiY5K7NNxkqg/JnRnFxLtKQ96JaviiIxi7djMrSd0ECT9AC+lttClmYwKw53BWpOMblo7A==", - "dependencies": { - "camel-case": "^4.1.2", - "capital-case": "^1.0.4", - "constant-case": "^3.0.4", - "dot-case": "^3.0.4", - "header-case": "^2.0.4", - "no-case": "^3.0.4", - "param-case": "^3.0.4", - "pascal-case": "^3.1.2", - "path-case": "^3.0.4", - "sentence-case": "^3.0.4", - "snake-case": "^3.0.4", - "tslib": "^2.0.3" - } + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/change-case/-/change-case-5.3.0.tgz", + "integrity": "sha512-Eykca0fGS/xYlx2fG5NqnGSnsWauhSGiSXYhB1kO6E909GUfo8S54u4UZNS7lMJmgZumZ2SUpWaoLgAcfQRICg==" }, "node_modules/cliui": { "version": "8.0.1", @@ -280,6 +343,15 @@ "node": ">=12" } }, + "node_modules/color": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/color/-/color-3.2.1.tgz", + "integrity": "sha512-aBl7dZI9ENN6fUGC7mWpMTPNHmWUSNan9tuWN6ahh5ZLNk9baLJOnSMlrQkHcrfFgz2/RigjUVAjdx36VcemKA==", + "dependencies": { + "color-convert": "^1.9.3", + "color-string": "^1.6.0" + } + }, "node_modules/color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", @@ -293,34 +365,22 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==" }, - "node_modules/constant-case": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/constant-case/-/constant-case-3.0.4.tgz", - "integrity": "sha512-I2hSBi7Vvs7BEuJDr5dDHfzb/Ruj3FyvFyh7KLilAjNQw3Be+xgqUBA2W6scVEcL0hL1dwPRtIqEPVUCKkSsyQ==", + "node_modules/color-string": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.9.1.tgz", + "integrity": "sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==", "dependencies": { - "no-case": "^3.0.4", - "tslib": "^2.0.3", - "upper-case": "^2.0.2" - } - }, - "node_modules/dir-glob": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", - "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", - "dependencies": { - "path-type": "^4.0.0" - }, - "engines": { - "node": ">=8" + "color-name": "^1.0.0", + "simple-swizzle": "^0.2.2" } }, - "node_modules/dot-case": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/dot-case/-/dot-case-3.0.4.tgz", - "integrity": "sha512-Kv5nKlh6yRrdrGvxeJ2e5y2eRUpkUosIW4A2AS38zwSz27zu7ufDwQPi5Jhs3XAlGNetl3bmnGhQsMtkKJnj3w==", + "node_modules/colorspace": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/colorspace/-/colorspace-1.1.4.tgz", + "integrity": "sha512-BgvKJiuVu1igBUF2kEjRCZXol6wiiGbY5ipL/oVPwm0BL9sIpMIzM8IK7vwuxIIzOXMV3Ey5w+vxhm0rR/TN8w==", "dependencies": { - "no-case": "^3.0.4", - "tslib": "^2.0.3" + "color": "^3.1.3", + "text-hex": "1.0.x" } }, "node_modules/emoji-regex": { @@ -328,6 +388,11 @@ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, + "node_modules/enabled": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/enabled/-/enabled-2.0.0.tgz", + "integrity": "sha512-AKrN98kuwOzMIdAizXGI86UFBoo26CL21UM763y1h/GMSJ4/OHU9k2YlsmBpyScFo/wbLzWQJBMCW4+IO3/+OQ==" + }, "node_modules/escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -350,9 +415,9 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, "node_modules/fast-glob": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.1.tgz", - "integrity": "sha512-kNFPyjhh5cKjrUltxs+wFx+ZkbRaxxmZ+X0ZU31SOsxCEtP9VPgtq2teZw1DebupL5GmDaNQ6yKMMVcM41iqDg==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", + "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", "dependencies": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", @@ -365,13 +430,18 @@ } }, "node_modules/fastq": { - "version": "1.15.0", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", - "integrity": "sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==", + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.0.tgz", + "integrity": "sha512-zGygtijUMT7jnk3h26kUms3BkSDp4IfIKjmnqI2tvx6nuBfiF1UqOxbnLfzdv+apBy+53oaImsKtMw/xYbW+1w==", "dependencies": { "reusify": "^1.0.4" } }, + "node_modules/fecha": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.3.tgz", + "integrity": "sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==" + }, "node_modules/fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -383,6 +453,11 @@ "node": ">=8" } }, + "node_modules/fn.name": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fn.name/-/fn.name-1.1.0.tgz", + "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==" + }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -403,18 +478,19 @@ } }, "node_modules/globby": { - "version": "13.2.2", - "resolved": "https://registry.npmjs.org/globby/-/globby-13.2.2.tgz", - "integrity": "sha512-Y1zNGV+pzQdh7H39l9zgB4PJqjRNqydvdYCDG4HFXM4XuvSaQQlEc91IU1yALL8gUTDomgBAfz3XJdmUS+oo0w==", + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-14.0.0.tgz", + "integrity": "sha512-/1WM/LNHRAOH9lZta77uGbq0dAEQM+XjNesWwhlERDVenqothRbnzTrL3/LrIoEPPjeUHC3vrS6TwoyxeHs7MQ==", "dependencies": { - "dir-glob": "^3.0.1", - "fast-glob": "^3.3.0", + "@sindresorhus/merge-streams": "^1.0.0", + "fast-glob": "^3.3.2", "ignore": "^5.2.4", - "merge2": "^1.4.1", - "slash": "^4.0.0" + "path-type": "^5.0.0", + "slash": "^5.1.0", + "unicorn-magic": "^0.1.0" }, "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -428,23 +504,24 @@ "node": ">=4" } }, - "node_modules/header-case": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/header-case/-/header-case-2.0.4.tgz", - "integrity": "sha512-H/vuk5TEEVZwrR0lp2zed9OCo1uAILMlx0JEMgC26rzyJJ3N1v6XkwHHXJQdR2doSjcGPM6OKPYoJgf0plJ11Q==", - "dependencies": { - "capital-case": "^1.0.4", - "tslib": "^2.0.3" - } - }, "node_modules/ignore": { - "version": "5.2.4", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz", - "integrity": "sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==", + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", + "integrity": "sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==", "engines": { "node": ">= 4" } }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "node_modules/is-arrayish": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz", + "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==" + }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -480,6 +557,17 @@ "node": ">=0.12.0" } }, + "node_modules/is-stream": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", + "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -490,6 +578,11 @@ "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" }, + "node_modules/json-serialize-refs": { + "version": "0.1.0-0", + "resolved": "https://registry.npmjs.org/json-serialize-refs/-/json-serialize-refs-0.1.0-0.tgz", + "integrity": "sha512-SnNMfW2RRPDXIMKa8zdLb59UjMSI1UFZCtIb8ae68GcZ0a6x8b77lIWqqTOdq1azzmkXupD6UWriPLd0JCrFng==" + }, "node_modules/kleur": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", @@ -498,12 +591,25 @@ "node": ">=6" } }, - "node_modules/lower-case": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-2.0.2.tgz", - "integrity": "sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==", + "node_modules/kuler": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz", + "integrity": "sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==" + }, + "node_modules/logform": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/logform/-/logform-2.6.0.tgz", + "integrity": "sha512-1ulHeNPp6k/LD8H91o7VYFBng5i1BDE7HoKxVbZiGFidS1Rj65qcywLxX+pVfAPoQJEjRdvKcusKwOupHCVOVQ==", "dependencies": { - "tslib": "^2.0.3" + "@colors/colors": "1.6.0", + "@types/triple-beam": "^1.3.2", + "fecha": "^4.2.0", + "ms": "^2.1.1", + "safe-stable-stringify": "^2.3.1", + "triple-beam": "^1.3.0" + }, + "engines": { + "node": ">= 12.0.0" } }, "node_modules/lru-cache": { @@ -537,6 +643,11 @@ "node": ">=8.6" } }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, "node_modules/mustache": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz", @@ -545,48 +656,23 @@ "mustache": "bin/mustache" } }, - "node_modules/no-case": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz", - "integrity": "sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==", - "dependencies": { - "lower-case": "^2.0.2", - "tslib": "^2.0.3" - } - }, - "node_modules/param-case": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/param-case/-/param-case-3.0.4.tgz", - "integrity": "sha512-RXlj7zCYokReqWpOPH9oYivUzLYZ5vAPIfEmCTNViosC78F8F0H9y7T7gG2M39ymgutxF5gcFEsyZQSph9Bp3A==", - "dependencies": { - "dot-case": "^3.0.4", - "tslib": "^2.0.3" - } - }, - "node_modules/pascal-case": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/pascal-case/-/pascal-case-3.1.2.tgz", - "integrity": "sha512-uWlGT3YSnK9x3BQJaOdcZwrnV6hPpd8jFH1/ucpiLRPh/2zCVJKS19E4GvYHvaCcACn3foXZ0cLB9Wrx1KGe5g==", - "dependencies": { - "no-case": "^3.0.4", - "tslib": "^2.0.3" - } - }, - "node_modules/path-case": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/path-case/-/path-case-3.0.4.tgz", - "integrity": "sha512-qO4qCFjXqVTrcbPt/hQfhTQ+VhFsqNKOPtytgNKkKxSoEp3XPUQ8ObFuePylOIok5gjn69ry8XiULxCwot3Wfg==", + "node_modules/one-time": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/one-time/-/one-time-1.0.0.tgz", + "integrity": "sha512-5DXOiRKwuSEcQ/l0kGCF6Q3jcADFv5tSmRaJck/OqkVFcOzutB134KRSfF0xDrL39MNnqxbHBbUUcjZIhTgb2g==", "dependencies": { - "dot-case": "^3.0.4", - "tslib": "^2.0.3" + "fn.name": "1.x.x" } }, "node_modules/path-type": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", - "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-5.0.0.tgz", + "integrity": "sha512-5HviZNaZcfqP95rwpv+1HDgUamezbqdSYTyzjTvwtJSnIH+3vnbmWsItli8OFEndS984VT55M3jduxZbX351gg==", "engines": { - "node": ">=8" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/picocolors": { @@ -605,10 +691,19 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/pluralize": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-8.0.0.tgz", + "integrity": "sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==", + "peer": true, + "engines": { + "node": ">=4" + } + }, "node_modules/prettier": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", - "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.1.1.tgz", + "integrity": "sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==", "bin": { "prettier": "bin/prettier.cjs" }, @@ -658,6 +753,19 @@ } ] }, + "node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -705,6 +813,33 @@ "queue-microtask": "^1.2.2" } }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/safe-stable-stringify": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.4.3.tgz", + "integrity": "sha512-e2bDA2WJT0wxseVd4lsDP4+3ONX6HpMXQa1ZhFQ7SU+GjvORCmShbCMltrtIDfkYhVHrOcPtj+KhmDBdPdZD1g==", + "engines": { + "node": ">=10" + } + }, "node_modules/semver": { "version": "7.5.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", @@ -719,14 +854,12 @@ "node": ">=10" } }, - "node_modules/sentence-case": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/sentence-case/-/sentence-case-3.0.4.tgz", - "integrity": "sha512-8LS0JInaQMCRoQ7YUytAo/xUu5W2XnQxV2HI/6uM6U7CITS1RqPElr30V6uIqyMKM9lJGRVFy5/4CuzcixNYSg==", + "node_modules/simple-swizzle": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", + "integrity": "sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==", "dependencies": { - "no-case": "^3.0.4", - "tslib": "^2.0.3", - "upper-case-first": "^2.0.2" + "is-arrayish": "^0.3.1" } }, "node_modules/sisteransi": { @@ -735,23 +868,30 @@ "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==" }, "node_modules/slash": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/slash/-/slash-4.0.0.tgz", - "integrity": "sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-5.1.0.tgz", + "integrity": "sha512-ZA6oR3T/pEyuqwMgAKT0/hAv8oAXckzbkmR0UkUosQ+Mc4RxGoJkRmwHgHufaenlyAgE1Mxgpdcrf75y6XcnDg==", "engines": { - "node": ">=12" + "node": ">=14.16" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/snake-case": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/snake-case/-/snake-case-3.0.4.tgz", - "integrity": "sha512-LAOh4z89bGQvl9pFfNF8V146i7o7/CqFPbqzYgP+yYzDIDeS9HaNFtXABamRW+AQzEVODcvE79ljJ+8a9YSdMg==", + "node_modules/stack-trace": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz", + "integrity": "sha512-KGzahc7puUKkzyMt+IqAep+TVNbKP+k2Lmwhub39m1AsTSkaDutx56aDCo+HLDzf/D26BIHTJWNiTG1KAJiQCg==", + "engines": { + "node": "*" + } + }, + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", "dependencies": { - "dot-case": "^3.0.4", - "tslib": "^2.0.3" + "safe-buffer": "~5.2.0" } }, "node_modules/string-width": { @@ -789,6 +929,11 @@ "node": ">=4" } }, + "node_modules/text-hex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/text-hex/-/text-hex-1.0.0.tgz", + "integrity": "sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg==" + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -800,25 +945,23 @@ "node": ">=8.0" } }, - "node_modules/tslib": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", - "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" - }, - "node_modules/upper-case": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/upper-case/-/upper-case-2.0.2.tgz", - "integrity": "sha512-KgdgDGJt2TpuwBUIjgG6lzw2GWFRCW9Qkfkiv0DxqHHLYJHmtmdUIKcZd8rHgFSjopVTlw6ggzCm1b8MFQwikg==", - "dependencies": { - "tslib": "^2.0.3" + "node_modules/triple-beam": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.4.1.tgz", + "integrity": "sha512-aZbgViZrg1QNcG+LULa7nhZpJTZSLm/mXnHXnbAbjmN5aSa0y7V+wvv6+4WaBtpISJzThKy+PIPxc1Nq1EJ9mg==", + "engines": { + "node": ">= 14.0.0" } }, - "node_modules/upper-case-first": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/upper-case-first/-/upper-case-first-2.0.2.tgz", - "integrity": "sha512-514ppYHBaKwfJRK/pNC6c/OxfGa0obSnAl106u97Ed0I625Nin96KAjttZF6ZL3e1XLtphxnqrOi9iWgm+u+bg==", - "dependencies": { - "tslib": "^2.0.3" + "node_modules/unicorn-magic": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/unicorn-magic/-/unicorn-magic-0.1.0.tgz", + "integrity": "sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/uri-js": { @@ -829,6 +972,11 @@ "punycode": "^2.1.0" } }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" + }, "node_modules/vscode-jsonrpc": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.2.0.tgz", @@ -867,6 +1015,40 @@ "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.4.tgz", "integrity": "sha512-9YXi5pA3XF2V+NUQg6g+lulNS0ncRCKASYdK3Cs7kiH9sVFXWq27prjkC/B8M/xJLRPPRSPCHVMuBTgRNFh2sQ==" }, + "node_modules/winston": { + "version": "3.11.0", + "resolved": "https://registry.npmjs.org/winston/-/winston-3.11.0.tgz", + "integrity": "sha512-L3yR6/MzZAOl0DsysUXHVjOwv8mKZ71TrA/41EIduGpOOV5LQVodqN+QdQ6BS6PJ/RdIshZhq84P/fStEZkk7g==", + "dependencies": { + "@colors/colors": "^1.6.0", + "@dabh/diagnostics": "^2.0.2", + "async": "^3.2.3", + "is-stream": "^2.0.0", + "logform": "^2.4.0", + "one-time": "^1.0.0", + "readable-stream": "^3.4.0", + "safe-stable-stringify": "^2.3.1", + "stack-trace": "0.0.x", + "triple-beam": "^1.3.0", + "winston-transport": "^4.5.0" + }, + "engines": { + "node": ">= 12.0.0" + } + }, + "node_modules/winston-transport": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.6.0.tgz", + "integrity": "sha512-wbBA9PbPAHxKiygo7ub7BYRiKxms0tpfU2ljtWzb3SjRjv5yl6Ozuy/TkXf00HTAt+Uylo3gSkNwzc4ME0wiIg==", + "dependencies": { + "logform": "^2.3.2", + "readable-stream": "^3.6.0", + "triple-beam": "^1.3.0" + }, + "engines": { + "node": ">= 12.0.0" + } + }, "node_modules/wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", @@ -927,9 +1109,9 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "node_modules/yaml": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.2.tgz", - "integrity": "sha512-N/lyzTPaJasoDmfV7YTrYCI0G/3ivm/9wdG0aHuheKowWQwGTsK0Eoiw6utmzAnI6pkJa0DUVygvp3spqqEKXg==", + "version": "2.3.4", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.4.tgz", + "integrity": "sha512-8aAvwVUSHpfEqTQ4w/KMlf3HcRdt50E5ODIQJBw1fQ5RL34xabzxtUlzTXVqc4rkZsPbvrXKWnABCD7kWSmocA==", "engines": { "node": ">= 14" } diff --git a/package.json b/package.json index eba48058d..f43e693fb 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,13 @@ "version": "0.1.0", "type": "module", "dependencies": { - "@typespec/compiler": "^0.49.0-dev.11", - "@typespec/openapi": "^0.49.0-dev.4", - "@typespec/openapi3": "^0.49.0-dev.10", - "@typespec/rest": "^0.49.0-dev.3", - "@typespec/http": "^0.49.0-dev.0", - "@typespec/versioning": "^0.49.0-dev.0" + "@azure-tools/typespec-csharp": "latest", + "@typespec/compiler": "^0.52.0", + "@typespec/http": "^0.52.0", + "@typespec/openapi": "^0.52.0", + "@typespec/openapi3": "^0.52.0", + "@typespec/rest": "^0.52.0", + "@typespec/versioning": "^0.52.0" }, "private": true } diff --git a/readme.md b/readme.md deleted file mode 100644 index c4dd93188..000000000 --- a/readme.md +++ /dev/null @@ -1,15 +0,0 @@ -A conversion of the OpenAI OpenAPI to TypeSpec. - -There are some deltas: - -### Changes to API Semantics: - -- Many things are missing defaults (mostly due to bug where we can't set null defaults) -- Error responses have been added. -- Where known, the `object` property's type is narrowed from string to the constant value it will always be - -### Changes to API metadata or OpenAPI format - -- Much of the x-oaiMeta entries have not been added. -- In some cases, new schemas needed to be defined in order to be defined in TypeSpec (e.g. because the constraints could not be added to a model property with a heterogeneous type) -- There is presently no way to set `title` diff --git a/runs/main.tsp b/runs/main.tsp new file mode 100644 index 000000000..6a754bcb5 --- /dev/null +++ b/runs/main.tsp @@ -0,0 +1 @@ +import "./operations.tsp"; \ No newline at end of file diff --git a/runs/meta.tsp b/runs/meta.tsp new file mode 100644 index 000000000..6819970c2 --- /dev/null +++ b/runs/meta.tsp @@ -0,0 +1,50 @@ +import "./models.tsp"; + +import "@typespec/openapi"; + +using TypeSpec.OpenAPI; + +namespace OpenAI; + +@@extension(OpenAI.RunObject, + "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", + "instructions": null, + "tools": [{"type": "retrieval"}, {"type": "code_interpreter"}], + "file_ids": [], + "metadata": {}, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + } + } + """ +); + +// TODO: Fill in example here. +@@extension(OpenAI.RunStepObject, + "x-oaiMeta", + """ + name: The run step object + beta: true + example: *run_step_object_example + """ +); \ No newline at end of file diff --git a/runs/models.tsp b/runs/models.tsp new file mode 100644 index 000000000..d5c33bb22 --- /dev/null +++ b/runs/models.tsp @@ -0,0 +1,486 @@ +import "../common/models.tsp"; +import "../assistants/models.tsp"; +import "../threads/models.tsp"; + +using TypeSpec.Http; +using TypeSpec.OpenAPI; + +namespace OpenAI; + +model CreateRunRequest { + /** The ID of the [assistant](/docs/api-reference/assistants) to use to execute this run. */ + assistant_id: string; + + /** + * 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. */ + `model`?: string | null; + + /** + * Overrides the [instructions](/docs/api-reference/assistants/createAssistant) of the assistant. + * This is useful for modifying the behavior on a per-run basis. + */ + instructions?: string | null; + + /** + * 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. + */ + additional_instructions?: string | null; + + /** + * Override the tools the assistant can use for this run. This is useful for modifying the + * behavior on a per-run basis. + */ + tools?: CreateRunRequestTools | null; + + /** + * 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. + */ + @extension("x-oaiTypeLabel", "map") + metadata?: Record | null; +} + +model ModifyRunRequest { + /** + * 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. + */ + @extension("x-oaiTypeLabel", "map") + metadata?: Record | null; +} + +model CreateThreadAndRunRequest { + /** The ID of the [assistant](/docs/api-reference/assistants) to use to execute this run. */ + assistant_id: string; + + /** If no thread is provided, an empty thread will be created. */ + thread?: CreateThreadRequest; + + /** + * 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. + */ + `model`?: string | null; + + /** + * Override the default system message of the assistant. This is useful for modifying the behavior + * on a per-run basis. + */ + instructions?: string | null; + + /** + * Override the tools the assistant can use for this run. This is useful for modifying the + * behavior on a per-run basis. + */ + tools?: CreateRunRequestTools | null; + + /** + * 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. + */ + @extension("x-oaiTypeLabel", "map") + metadata?: Record | null; +} + +model SubmitToolOutputsRunRequest { + /** A list of tools for which the outputs are being submitted. */ + tool_outputs: { + /** + * The ID of the tool call in the `required_action` object within the run object the output is + * being submitted for. */ + tool_call_id?: string; + + /** The output of the tool call to be submitted to continue the run. */ + output?: string; + } +} + +model ListRunsResponse { + object: "list"; + data: RunObject[]; + first_id: string; + last_id: string; + has_more: boolean; +} + +model ListRunStepsResponse { + object: "list"; + data: RunStepObject[]; + first_id: string; + last_id: string; + has_more: boolean; +} + +@maxItems(20) +model CreateRunRequestTools is CreateRunRequestTool[]; + +@oneOf +@extension("x-oaiExpandable", true) +union CreateRunRequestTool { + AssistantToolsCode, + AssistantToolsRetrieval, + AssistantToolsFunction +} + +@oneOf +@extension("x-oaiExpandable", true) +union RunStepDetails { + RunStepDetailsMessageCreationObject, + RunStepDetailsToolCallsObject, +} + +/** Details of the message creation by the run step. */ +model RunStepDetailsMessageCreationObject { + /** Details of the message creation by the run step. */ + type: "message_creation"; + + message_creation: { + /** The ID of the message that was created by this run step. */ + message_id: string; + } +} + +/** Details of the tool call. */ +model RunStepDetailsToolCallsObject { + /** Always `tool_calls`. */ + type: "tool_calls"; + + /** + * An array of tool calls the run step was involved in. These can be associated with one of three + * types of tools: `code_interpreter`, `retrieval`, or `function`. + */ + tool_calls: RunStepDetailsToolCallsObjectToolCalls; +} + +model RunStepDetailsToolCallsObjectToolCalls is RunStepDetailsToolCallsObjectToolCall[]; + +@oneOf +@extension("x-oaiExpandable", true) +union RunStepDetailsToolCallsObjectToolCall { + RunStepDetailsToolCallsCodeObject, + RunStepDetailsToolCallsRetrievalObject, + RunStepDetailsToolCallsFunctionObject, +} + +/** Details of the Code Interpreter tool call the run step was involved in. */ +model RunStepDetailsToolCallsCodeObject { + /** The ID of the tool call. */ + id: string; + + /** + * The type of tool call. This is always going to be `code_interpreter` for this type of tool + * call. + */ + type: "code_interpreter"; + + /** The Code Interpreter tool call definition. */ + code_interpreter: { + /** The input to the Code Interpreter tool call. */ + input: string; + + /** + * 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. + */ + outputs: RunStepDetailsToolCallsCodeOutputs; + } +} + +model RunStepDetailsToolCallsCodeOutputs is RunStepDetailsToolCallsCodeOutput[]; + +@oneOf +@extension("x-oaiExpandable", true) +union RunStepDetailsToolCallsCodeOutput { + RunStepDetailsToolCallsCodeOutputLogsObject, + RunStepDetailsToolCallsCodeOutputImageObject, +} + +/** Text output from the Code Interpreter tool call as part of a run step. */ +model RunStepDetailsToolCallsCodeOutputLogsObject { + /** Always `logs`. */ + type: "logs"; + + /** The text output from the Code Interpreter tool call. */ + logs: string; +} + +model RunStepDetailsToolCallsCodeOutputImageObject { + /** Always `image`. */ + type: "image"; + + image: { + /** The [file](/docs/api-reference/files) ID of the image. */ + file_id: string; + } +} + +model RunStepDetailsToolCallsRetrievalObject { + /** The ID of the tool call object. */ + id: string; + + /** The type of tool call. This is always going to be `retrieval` for this type of tool call. */ + type: "retrieval"; + + /** For now, this is always going to be an empty object. */ + @extension("x-oaiTypeLabel", "map") + retrieval: { }; // TODO: Is this the appropriate way to represent an empty object? +} + +model RunStepDetailsToolCallsFunctionObject { + /** The ID of the tool call object. */ + id: string; + + /** The type of tool call. This is always going to be `function` for this type of tool call. */ + type: "function"; + + /** The definition of the function that was called. */ + function: { + /** The name of the function. */ + name: string; + + /** The arguments passed to the function. */ + arguments: string; + + /** + * The output of the function. This will be `null` if the outputs have not been + * [submitted](/docs/api-reference/runs/submitToolOutputs) yet. + */ + output: string | null; + } +} + +/** + * 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.). + */ +model RunCompletionUsage { + /** Number of completion tokens used over the course of the run. */ + completion_tokens: safeint; + + /** Number of prompt tokens used over the course of the run. */ + prompt_tokens: safeint; + + /** Total number of tokens used (prompt + completion). */ + total_tokens: safeint; +} + +/** + * Usage statistics related to the run step. This value will be `null` while the run step's status + * is `in_progress`. + */ +model RunStepCompletionUsage { + /** Number of completion tokens used over the course of the run step. */ + completion_tokens: safeint; + + /** Number of prompt tokens used over the course of the run step. */ + prompt_tokens: safeint; + + /** Total number of tokens used (prompt + completion). */ + total_tokens: safeint; +} + +/** Represents an execution run on a [thread](/docs/api-reference/threads). */ +model RunObject { + /** The identifier, which can be referenced in API endpoints. */ + id: string; + + /** The object type, which is always `thread.run`. */ + object: "thread.run"; + + /** The Unix timestamp (in seconds) for when the run was created. */ + @encode("unixTimestamp", int32) + created_at: utcDateTime; + + /** + * The ID of the [thread](/docs/api-reference/threads) that was executed on as a part of this + * run. + */ + thread_id: string; + + /** The ID of the [assistant](/docs/api-reference/assistants) used for execution of this run. */ + assistant_id: string; + + /** + * The status of the run, which can be either `queued`, `in_progress`, `requires_action`, + * `cancelling`, `cancelled`, `failed`, `completed`, or `expired`. + */ + status: + | "queued" + | "in_progress" + | "requires_action" + | "cancelling" + | "cancelled" + | "failed" + | "completed" + | "expired"; + + /** + * Details on the action required to continue the run. Will be `null` if no action is + * required. + */ + required_action: { + /** For now, this is always `submit_tool_outputs`. */ + type: "submit_tool_outputs"; + + /** Details on the tool outputs needed for this run to continue. */ + submit_tool_outputs: { + /** A list of the relevant tool calls. */ + tool_calls: RunToolCallObject[]; + } + } | null; + + /** The last error associated with this run. Will be `null` if there are no errors. */ + last_error: { + /** One of `server_error` or `rate_limit_exceeded`. */ + code: "server_error" | "rate_limit_exceeded"; + + /** A human-readable description of the error. */ + message: string; + } | null; + + /** The Unix timestamp (in seconds) for when the run will expire. */ + @encode("unixTimestamp", int32) + expires_at: utcDateTime; + + /** The Unix timestamp (in seconds) for when the run was started. */ + @encode("unixTimestamp", int32) + started_at: utcDateTime | null; + + /** The Unix timestamp (in seconds) for when the run was cancelled. */ + @encode("unixTimestamp", int32) + cancelled_at: utcDateTime | null; + + /** The Unix timestamp (in seconds) for when the run failed. */ + @encode("unixTimestamp", int32) + failed_at: utcDateTime | null; + + /** The Unix timestamp (in seconds) for when the run was completed. */ + @encode("unixTimestamp", int32) + completed_at: utcDateTime | null; + + /** The model that the [assistant](/docs/api-reference/assistants) used for this run. */ + `model`: string; + + /** The instructions that the [assistant](/docs/api-reference/assistants) used for this run. */ + instructions: string; + + /** The list of tools that the [assistant](/docs/api-reference/assistants) used for this run. */ + tools: CreateRunRequestTools; + + /** + * The list of [File](/docs/api-reference/files) IDs the + * [assistant](/docs/api-reference/assistants) used for this run. + */ + file_ids: string[] = []; + + /** + * 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. + */ + @extension("x-oaiTypeLabel", "map") + metadata: Record | null; + + usage: RunCompletionUsage | null; +} + +/** Represents a step in execution of a run. */ +model RunStepObject { + /** The identifier of the run step, which can be referenced in API endpoints. */ + id: string; + + /** The object type, which is always `thread.run.step`. */ + object: "thread.run.step"; + + /** The Unix timestamp (in seconds) for when the run step was created. */ + @encode("unixTimestamp", int32) + created_at: utcDateTime; + + /** The ID of the [assistant](/docs/api-reference/assistants) associated with the run step. */ + assistant_id: string; + + /** The ID of the [thread](/docs/api-reference/threads) that was run. */ + thread_id: string; + + /** The ID of the [run](/docs/api-reference/runs) that this run step is a part of. */ + run_id: string; + + /** The type of run step, which can be either `message_creation` or `tool_calls`. */ + type: "message_creation" | "tool_calls"; + + /** + * The status of the run step, which can be either `in_progress`, `cancelled`, `failed`, + * `completed`, or `expired`. + */ + status: "in_progress" | "cancelled" | "failed" | "completed" | "expired"; + + /** The details of the run step. */ + step_details: RunStepDetails; + + /** The last error associated with this run step. Will be `null` if there are no errors. */ + last_error: { + /** One of `server_error` or `rate_limit_exceeded`. */ + code: "server_error" | "rate_limit_exceeded"; + + /** A human-readable description of the error. */ + message: string; + } | null; + + /** + * The Unix timestamp (in seconds) for when the run step expired. A step is considered expired + * if the parent run is expired. + */ + @encode("unixTimestamp", int32) + expires_at: utcDateTime | null; + + /** The Unix timestamp (in seconds) for when the run step was cancelled. */ + @encode("unixTimestamp", int32) + cancelled_at: utcDateTime | null; + + /** The Unix timestamp (in seconds) for when the run step failed. */ + @encode("unixTimestamp", int32) + failed_at: utcDateTime | null; + + /** T The Unix timestamp (in seconds) for when the run step completed.. */ + @encode("unixTimestamp", int32) + completed_at: utcDateTime | null; + + /** + * 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. + */ + @extension("x-oaiTypeLabel", "map") + metadata: Record | null; + + usage: RunCompletionUsage | null; +} + +/** Tool call objects */ +model RunToolCallObject { + /** + * 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. + */ + id: string; + + /** The type of tool call the output is required for. For now, this is always `function`. */ + type: "function"; + + /** The function definition. */ + function: { + /** The name of the function. */ + name: string; + + /** The arguments that the model expects you to pass to the function. */ + arguments: string; + } +} \ No newline at end of file diff --git a/runs/operations.tsp b/runs/operations.tsp new file mode 100644 index 000000000..8bf1f0df1 --- /dev/null +++ b/runs/operations.tsp @@ -0,0 +1,185 @@ +import "@typespec/http"; +import "@typespec/openapi"; + +import "../common/errors.tsp"; +import "./models.tsp"; + +using TypeSpec.Http; +using TypeSpec.OpenAPI; + +namespace OpenAI; + +@route("threads") +interface Runs { + @route("runs") + @post + @operationId("createThreadAndRun") + @tag("Assistants") + @summary("Create a thread and run it in one request.") + createThreadAndRun( + @body threadAndRun: CreateThreadAndRunRequest; + ): RunObject | ErrorResponse; + + @route("{thread_id}/runs") + @post + @operationId("createRun") + @tag("Assistants") + @summary("Create a run.") + createRun( + /** The ID of the thread to run. */ + @path thread_id: string, + + @body run: CreateRunRequest, + ): RunObject | ErrorResponse; + + @route("{thread_id}/runs") + @get + @operationId("listRuns") + @tag("Assistants") + @summary("Returns a list of runs belonging to a thread.") + listRuns( + /** The ID of the thread the run belongs to. */ + @path thread_id: string, + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + * default is 20. + */ + @query limit?: int32 = 20; + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc` + * for descending order. + */ + @query order?: "asc" | "desc" = "desc"; + + /** + * 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. + */ + @query after?: string; + + /** + * 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. + */ + @query before?: string; + ): ListRunsResponse | ErrorResponse; + + @route("{thread_id}/runs/{run_id}") + @get + @operationId("getRun") + @tag("Assistants") + @summary("Retrieves a run.") + getRun( + /** The ID of the [thread](/docs/api-reference/threads) that was run. */ + @path thread_id: string, + + /** The ID of the run to retrieve. */ + @path run_id: string, + ): RunObject | ErrorResponse; + + @route("{thread_id}/runs/{run_id}") + @post + @operationId("modifyRun") + @tag("Assistants") + @summary("Modifies a run.") + modifyRun( + /** The ID of the [thread](/docs/api-reference/threads) that was run. */ + @path thread_id: string, + + /** The ID of the run to modify. */ + @path run_id: string, + + @body run: ModifyRunRequest, + ): RunObject | ErrorResponse; + + @route("{thread_id}/runs/{run_id}/cancel") + @post + @operationId("cancelRun") + @tag("Assistants") + @summary("Cancels a run that is `in_progress`.") + cancelRun( + /** The ID of the thread to which this run belongs. */ + @path thread_id: string, + + /** The ID of the run to cancel. */ + @path run_id: string, + ): RunObject | ErrorResponse; + + @route("{thread_id}/runs/{run_id}/submit_tool_outputs") + @post + @operationId("submitToolOuputsToRun") + @tag("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. + """) + submitToolOuputsToRun( + /** The ID of the [thread](/docs/api-reference/threads) to which this run belongs. */ + @path thread_id: string, + + /** The ID of the run that requires the tool output submission. */ + @path run_id: string, + + @body submitToolOutputsRun: SubmitToolOutputsRunRequest, + ): RunObject | ErrorResponse; + + @route("{thread_id}/runs/{run_id}/steps") + @get + @operationId("listRunSteps") + @tag("Assistants") + @summary("Returns a list of run steps belonging to a run.") + listRunSteps( + /** The ID of the thread the run and run steps belong to. */ + @path thread_id: string, + + /** The ID of the run the run steps belong to. */ + @path run_id: string, + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + * default is 20. + */ + @query limit?: int32 = 20; + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc` + * for descending order. + */ + @query order?: "asc" | "desc" = "desc"; + + /** + * 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. + */ + @query after?: string; + + /** + * 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. + */ + @query before?: string; + ): ListRunStepsResponse | ErrorResponse; + + @route("{thread_id}/runs/{run_id}/steps/{step_id}") + @get + @operationId("getRunStep") + @tag("Assistants") + @summary("Retrieves a run step.") + getRunStep( + /** The ID of the thread to which the run and run step belongs. */ + @path thread_id: string, + + /** The ID of the run to which the run step belongs. */ + @path run_id: string, + + /** The ID of the run step to retrieve. */ + @path step_id: string, + ): RunStepObject | ErrorResponse; +} \ No newline at end of file diff --git a/threads/main.tsp b/threads/main.tsp new file mode 100644 index 000000000..6a754bcb5 --- /dev/null +++ b/threads/main.tsp @@ -0,0 +1 @@ +import "./operations.tsp"; \ No newline at end of file diff --git a/threads/meta.tsp b/threads/meta.tsp new file mode 100644 index 000000000..9a6edf95b --- /dev/null +++ b/threads/meta.tsp @@ -0,0 +1,22 @@ +import "./models.tsp"; + +import "@typespec/openapi"; + +using TypeSpec.OpenAPI; + +namespace OpenAI; + +@@extension(OpenAI.ThreadObject, + "x-oaiMeta", + """ + name: The thread object + beta: true + example: | + { + "id": "thread_abc123", + "object": "thread", + "created_at": 1698107661, + "metadata": {} + } + """ +); \ No newline at end of file diff --git a/threads/models.tsp b/threads/models.tsp new file mode 100644 index 000000000..4bdb28fae --- /dev/null +++ b/threads/models.tsp @@ -0,0 +1,55 @@ +import "../common/models.tsp"; +import "../messages/models.tsp"; + +using TypeSpec.Http; +using TypeSpec.OpenAPI; + +namespace OpenAI; + +model CreateThreadRequest { + /** A list of [messages](/docs/api-reference/messages) to start the thread with. */ + messages?: CreateMessageRequest[]; + + /** + * 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. + */ + metadata?: Record | null; +} + +model ModifyThreadRequest { + /** + * 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. + */ + metadata?: Record | null; +} + +model DeleteThreadResponse { + id: string; + deleted: boolean; + object: "thread.deleted"; +} + +/** Represents a thread that contains [messages](/docs/api-reference/messages). */ +model ThreadObject { + /** The identifier, which can be referenced in API endpoints. */ + id: string; + + /** The object type, which is always `thread`. */ + object: "thread"; + + /** The Unix timestamp (in seconds) for when the thread was created. */ + @encode("unixTimestamp", int32) + created_at: utcDateTime; + + /** + * 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. + */ + @extension("x-oaiTypeLabel", "map") + metadata: Record | null; +} \ No newline at end of file diff --git a/threads/operations.tsp b/threads/operations.tsp new file mode 100644 index 000000000..fb1dc5d10 --- /dev/null +++ b/threads/operations.tsp @@ -0,0 +1,52 @@ +import "@typespec/http"; +import "@typespec/openapi"; + +import "../common/errors.tsp"; +import "./models.tsp"; + +using TypeSpec.Http; +using TypeSpec.OpenAPI; + +namespace OpenAI; + +@route("/threads") +interface Threads { + @post + @operationId("createThread") + @tag("Assistants") + @summary("Create a thread.") + createThread( + @body thread: CreateThreadRequest, + ): ThreadObject | ErrorResponse; + + @route("{thread_id}") + @get + @operationId("getThread") + @tag("Assistants") + @summary("Retrieves a thread.") + getThread( + /** The ID of the thread to retrieve. */ + @path thread_id: string, + ): ThreadObject | ErrorResponse; + + @route("{thread_id}") + @post + @operationId("modifyThread") + @tag("Assistants") + @summary("Modifies a thread.") + modifyThread( + /** The ID of the thread to modify. Only the `metadata` can be modified. */ + @path thread_id: string, + @body thread: ModifyThreadRequest, + ): ThreadObject | ErrorResponse; + + @route("{thread_id}") + @delete + @operationId("deleteThread") + @tag("Assistants") + @summary("Delete a thread.") + deleteThread( + /** The ID of the thread to delete. */ + @path thread_id: string, + ): DeleteThreadResponse | ErrorResponse; +} diff --git a/tsp-output/@typespec/openapi3/openapi.yaml b/tsp-output/@typespec/openapi3/openapi.yaml index d37490680..8f62d8667 100644 --- a/tsp-output/@typespec/openapi3/openapi.yaml +++ b/tsp-output/@typespec/openapi3/openapi.yaml @@ -4,14 +4,23 @@ info: version: 2.0.0 description: The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details. tags: - - name: OpenAI + - name: Fine-tuning + - name: Audio + - name: Assistants + - name: Chat + - name: Completions + - name: Embeddings + - name: Files + - name: Images + - name: Models + - name: Moderations paths: - /audio/transcriptions: + /assistants: post: tags: - - OpenAI - operationId: createTranscription - summary: Transcribes audio into the input language. + - Assistants + operationId: createAssistant + summary: Create an assistant with a model and instructions. parameters: [] responses: '200': @@ -19,7 +28,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/CreateTranscriptionResponse' + $ref: '#/components/schemas/AssistantObject' default: description: An unexpected error response. content: @@ -29,73 +38,118 @@ paths: requestBody: required: true content: - multipart/form-data: + application/json: schema: - $ref: '#/components/schemas/CreateTranscriptionRequest' - /audio/translations: - post: + $ref: '#/components/schemas/CreateAssistantRequest' + get: tags: - - OpenAI - operationId: createTranslation - summary: Transcribes audio into the input language. - parameters: [] + - Assistants + operationId: listAssistants + summary: Returns a list of assistants. + parameters: + - name: limit + in: query + required: false + description: |- + A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + default is 20. + schema: + type: integer + format: int32 + default: 20 + - name: order + in: query + required: false + description: |- + Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc` + for descending order. + schema: + type: string + enum: + - asc + - desc + - desc + - desc + - desc + - desc + - desc + default: desc + - name: after + in: query + required: false + 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 + required: false + 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: The request has succeeded. content: application/json: schema: - $ref: '#/components/schemas/CreateTranslationResponse' + $ref: '#/components/schemas/ListAssistantsResponse' default: description: An unexpected error response. content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: '#/components/schemas/CreateTranslationRequest' - /chat/completions: - post: + /assistants/{assistant_id}: + get: tags: - - OpenAI - operationId: createChatCompletion - parameters: [] + - Assistants + operationId: getAssistant + summary: Retrieves an assistant. + parameters: + - name: assistant_id + in: path + required: true + description: The ID of the assistant to retrieve. + schema: + type: string responses: '200': description: The request has succeeded. content: application/json: schema: - $ref: '#/components/schemas/CreateChatCompletionResponse' + $ref: '#/components/schemas/AssistantObject' default: description: An unexpected error response. content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/CreateChatCompletionRequest' - /completions: post: tags: - - OpenAI - operationId: createCompletion - parameters: [] + - Assistants + operationId: modifyAssistant + summary: Modifies an assistant. + parameters: + - name: assistant_id + in: path + required: true + description: The ID of the assistant to modify. + schema: + type: string responses: '200': description: The request has succeeded. content: application/json: schema: - $ref: '#/components/schemas/CreateCompletionResponse' + $ref: '#/components/schemas/AssistantObject' default: description: An unexpected error response. content: @@ -107,195 +161,54 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/CreateCompletionRequest' - 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: No 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!" - } - ] - python: |- - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - - completion = openai.ChatCompletion.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: "string" }], - model: "VAR_model_id", - }); - - console.log(completion.choices[0]); - } - - main(); - response: |- - { - "id": "chatcmpl-123", - "object": "chat.completion", - "created": 1677652288, - "model": "gpt-3.5-turbo-0613", - "choices": [{ - "index": 0, - "message": { - "role": "assistant", - "content": " - - Hello there, how may I assist you today?", - }, - "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: |- - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - - completion = openai.ChatCompletion.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": 1677652288, - "model": "gpt-3.5-turbo", - "choices": [{ - "index": 0, - "delta": { - "content": "Hello", - }, - "finish_reason": "stop" - }] - } - /edits: - post: + $ref: '#/components/schemas/ModifyAssistantRequest' + delete: tags: - - OpenAI - operationId: createEdit - parameters: [] + - Assistants + operationId: deleteAssistant + summary: Delete an assistant. + parameters: + - name: assistant_id + in: path + required: true + description: The ID of the assistant to delete. + schema: + type: string responses: '200': description: The request has succeeded. content: application/json: schema: - $ref: '#/components/schemas/CreateEditResponse' + $ref: '#/components/schemas/DeleteAssistantResponse' default: description: An unexpected error response. content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/CreateEditRequest' - deprecated: true - /embeddings: + /assistants/{assistant_id}/files: post: tags: - - OpenAI - operationId: createEmbedding - summary: Creates an embedding vector representing the input text. - parameters: [] + - Assistants + operationId: createAssistantFile + summary: |- + Create an assistant file by attaching a [File](/docs/api-reference/files) to a + [assistant](/docs/api-reference/assistants). + parameters: + - name: assistant_id + in: path + required: true + description: The ID of the assistant for which to create a file. + schema: + type: string responses: '200': description: The request has succeeded. content: application/json: schema: - $ref: '#/components/schemas/CreateEmbeddingResponse' + $ref: '#/components/schemas/AssistantFileObject' default: description: An unexpected error response. content: @@ -307,63 +220,125 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/CreateEmbeddingRequest' - /files: + $ref: '#/components/schemas/CreateAssistantFileRequest' get: tags: - - OpenAI - operationId: listFiles - summary: Returns a list of files that belong to the user's organization. - parameters: [] + - Assistants + operationId: listAssistantFiles + summary: Returns a list of assistant files. + parameters: + - name: assistant_id + in: path + required: true + description: The ID of the assistant the file belongs to. + schema: + type: string + - name: limit + in: query + required: false + description: |- + A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + default is 20. + schema: + type: integer + format: int32 + default: 20 + - name: order + in: query + required: false + description: |- + Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc` + for descending order. + schema: + type: string + enum: + - asc + - desc + - desc + - desc + - desc + - desc + - desc + default: desc + - name: after + in: query + required: false + 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 + required: false + 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: The request has succeeded. content: application/json: schema: - $ref: '#/components/schemas/ListFilesResponse' + $ref: '#/components/schemas/ListAssistantFilesResponse' default: description: An unexpected error response. content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' - post: + /assistants/{assistant_id}/files/{file_id}: + get: tags: - - OpenAI - operationId: createFile - summary: Returns a list of files that belong to the user's organization. - parameters: [] + - Assistants + operationId: getAssistantFile + summary: Retrieves an assistant file. + parameters: + - name: assistant_id + in: path + required: true + description: The ID of the assistant the file belongs to. + schema: + type: string + - name: file_id + in: path + required: true + description: The ID of the file we're getting. + schema: + type: string responses: '200': description: The request has succeeded. content: application/json: schema: - $ref: '#/components/schemas/OpenAIFile' + $ref: '#/components/schemas/AssistantFileObject' default: description: An unexpected error response. content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: '#/components/schemas/CreateFileRequest' - /files/files/{file_id}: - post: + delete: tags: - - OpenAI - operationId: retrieveFile - summary: Returns information about a specific file. + - Assistants + operationId: deleteAssistantFile + summary: Delete an assistant file. parameters: + - name: assistant_id + in: path + required: true + description: The ID of the assistant the file belongs to. + schema: + type: string - name: file_id in: path required: true - description: The ID of the file to use for this request. + description: The ID of the file to delete. schema: type: string responses: @@ -372,56 +347,84 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/OpenAIFile' + $ref: '#/components/schemas/DeleteAssistantFileResponse' default: description: An unexpected error response. content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' - delete: + /audio/speech: + post: tags: - - OpenAI - operationId: deleteFile - summary: Delete a file - parameters: - - name: file_id - in: path - required: true - description: The ID of the file to use for this request. - schema: - type: string + - Audio + operationId: createSpeech + summary: Generates audio from the input text. + parameters: [] + responses: + '200': + description: The request has succeeded. + headers: + Transfer-Encoding: + required: false + description: chunked + schema: + type: string + content: + application/octet-stream: + schema: + type: string + format: binary + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/CreateSpeechRequest' + /audio/transcriptions: + post: + tags: + - Audio + operationId: createTranscription + summary: Transcribes audio into the input language. + parameters: [] responses: '200': description: The request has succeeded. content: application/json: schema: - $ref: '#/components/schemas/DeleteFileResponse' + $ref: '#/components/schemas/CreateTranscriptionResponse' + text/plain: + schema: + type: string default: description: An unexpected error response. content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' - /files/files/{file_id}/content: - get: + requestBody: + required: true + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/CreateTranscriptionRequestMultiPart' + /audio/translations: + post: tags: - - OpenAI - operationId: downloadFile - summary: Returns the contents of the specified file. - parameters: - - name: file_id - in: path - required: true - description: The ID of the file to use for this request. - schema: - type: string + - Audio + operationId: createTranslation + summary: Translates audio into English.. + parameters: [] responses: '200': description: The request has succeeded. content: application/json: + schema: + $ref: '#/components/schemas/CreateTranslationResponse' + text/plain: schema: type: string default: @@ -430,17 +433,18 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorResponse' - /fine-tunes: + requestBody: + required: true + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/CreateTranslationRequestMultiPart' + /chat/completions: post: tags: - - OpenAI - operationId: createFineTune - summary: |- - Creates a job that fine-tunes a specified model from a given dataset. - - Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete. - - [Learn more about fine-tuning](/docs/guides/legacy-fine-tuning) + - Chat + operationId: createChatCompletion + summary: Creates a model response for the given chat conversation. parameters: [] responses: '200': @@ -448,7 +452,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/FineTune' + $ref: '#/components/schemas/CreateChatCompletionResponse' default: description: An unexpected error response. content: @@ -460,13 +464,13 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/CreateFineTuneRequest' - deprecated: true - get: + $ref: '#/components/schemas/CreateChatCompletionRequest' + /completions: + post: tags: - - OpenAI - operationId: listFineTunes - summary: List your organization's fine-tuning jobs + - Completions + operationId: createCompletion + summary: Creates a completion for the provided prompt and parameters. parameters: [] responses: '200': @@ -474,7 +478,231 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ListFineTunesResponse' + $ref: '#/components/schemas/CreateCompletionResponse' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/CreateCompletionRequest' + /embeddings: + post: + tags: + - Embeddings + operationId: createEmbedding + summary: Creates an embedding vector representing the input text. + parameters: [] + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/CreateEmbeddingResponse' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/CreateEmbeddingRequest' + /files: + post: + tags: + - Files + operationId: createFile + summary: |- + Upload a file that can be used across various endpoints. The size of all the files uploaded by + one organization can be up to 100 GB. + + The size of individual files can be a maximum of 512 MB or 2 million tokens for Assistants. See + the [Assistants Tools guide](/docs/assistants/tools) to learn more about the types of files + supported. The Fine-tuning API only supports `.jsonl` files. + + Please [contact us](https://help.openai.com/) if you need to increase these storage limits. + parameters: [] + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/OpenAIFile' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + required: true + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/CreateFileRequestMultiPart' + get: + tags: + - Files + operationId: listFiles + summary: Returns a list of files that belong to the user's organization. + parameters: + - name: purpose + in: query + required: false + description: Only return files with the given purpose. + schema: + type: string + enum: + - fine-tune + - fine-tune-results + - assistants + - assistants_output + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/ListFilesResponse' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + /files/{file_id}: + get: + tags: + - Files + operationId: retrieveFile + summary: Returns information about a specific file. + parameters: + - name: file_id + in: path + required: true + description: The ID of the file to use for this request. + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/OpenAIFile' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + delete: + tags: + - Files + operationId: deleteFile + summary: Delete a file + parameters: + - name: file_id + in: path + required: true + description: The ID of the file to use for this request. + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/DeleteFileResponse' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + /files/{file_id}/content: + get: + tags: + - Files + operationId: downloadFile + summary: Returns the contents of the specified file. + parameters: + - name: file_id + in: path + required: true + description: The ID of the file to use for this request. + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + type: string + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + /fine-tunes: + post: + tags: + - Fine-tuning + operationId: createFineTune + summary: |- + Creates a job that fine-tunes a specified model from a given dataset. + + Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete. + + [Learn more about fine-tuning](/docs/guides/legacy-fine-tuning) + parameters: [] + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/FineTune' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/CreateFineTuneRequest' + deprecated: true + get: + tags: + - Fine-tuning + operationId: listFineTunes + summary: List your organization's fine-tuning jobs + parameters: [] + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/ListFineTunesResponse' default: description: An unexpected error response. content: @@ -485,7 +713,7 @@ paths: /fine-tunes/{fine_tune_id}: get: tags: - - OpenAI + - Fine-tuning operationId: retrieveFineTune summary: |- Gets info about the fine-tune job. @@ -515,7 +743,7 @@ paths: /fine-tunes/{fine_tune_id}/cancel: post: tags: - - OpenAI + - Fine-tuning operationId: cancelFineTune summary: Immediately cancel a fine-tune job. parameters: @@ -542,7 +770,7 @@ paths: /fine-tunes/{fine_tune_id}/events: get: tags: - - OpenAI + - Fine-tuning operationId: listFineTuneEvents summary: Get fine-grained status updates for a fine-tune job. parameters: @@ -583,7 +811,7 @@ paths: /fine_tuning/jobs: post: tags: - - OpenAI + - Fine-tuning operationId: createFineTuningJob description: |- Creates a job that fine-tunes a specified model from a given dataset. @@ -614,7 +842,7 @@ paths: $ref: '#/components/schemas/CreateFineTuningJobRequest' get: tags: - - OpenAI + - Fine-tuning operationId: listPaginatedFineTuningJobs parameters: - name: after @@ -647,7 +875,7 @@ paths: /fine_tuning/jobs/{fine_tuning_job_id}: get: tags: - - OpenAI + - Fine-tuning operationId: retrieveFineTuningJob summary: |- Get info about a fine-tuning job. @@ -675,7 +903,7 @@ paths: /fine_tuning/jobs/{fine_tuning_job_id}/cancel: post: tags: - - OpenAI + - Fine-tuning operationId: cancelFineTuningJob summary: Immediately cancel a fine-tune job. parameters: @@ -701,7 +929,7 @@ paths: /fine_tuning/jobs/{fine_tuning_job_id}/events: get: tags: - - OpenAI + - Fine-tuning operationId: listFineTuningEvents summary: Get status updates for a fine-tuning job. parameters: @@ -740,7 +968,7 @@ paths: /images/edits: post: tags: - - OpenAI + - Images operationId: createImageEdit summary: Creates an edited or extended image given an original image and a prompt. parameters: [] @@ -762,11 +990,11 @@ paths: content: multipart/form-data: schema: - $ref: '#/components/schemas/CreateImageEditRequest' + $ref: '#/components/schemas/CreateImageEditRequestMultiPart' /images/generations: post: tags: - - OpenAI + - Images operationId: createImage summary: Creates an image given a prompt parameters: [] @@ -792,7 +1020,7 @@ paths: /images/variations: post: tags: - - OpenAI + - Images operationId: createImageVariation summary: Creates an edited or extended image given an original image and a prompt. parameters: [] @@ -814,11 +1042,11 @@ paths: content: multipart/form-data: schema: - $ref: '#/components/schemas/CreateImageVariationRequest' + $ref: '#/components/schemas/CreateImageVariationRequestMultiPart' /models: get: tags: - - OpenAI + - Models operationId: listModels summary: |- Lists the currently available models, and provides basic information about each one such as the @@ -840,7 +1068,7 @@ paths: /models/{model}: get: tags: - - OpenAI + - Models operationId: retrieveModel summary: |- Retrieves a model instance, providing basic information about the model such as the owner and @@ -867,7 +1095,7 @@ paths: $ref: '#/components/schemas/ErrorResponse' delete: tags: - - OpenAI + - Models operationId: deleteModel summary: Delete a fine-tuned model. You must have the Owner role in your organization to delete a model. parameters: @@ -893,7 +1121,7 @@ paths: /moderations: post: tags: - - OpenAI + - Moderations operationId: createModeration summary: Classifies if text violates OpenAI's Content Policy parameters: [] @@ -916,89 +1144,2622 @@ paths: application/json: schema: $ref: '#/components/schemas/CreateModerationRequest' -security: - - BearerAuth: [] -components: - schemas: - ChatCompletionFunctionCallOption: - type: object - required: - - name - properties: - name: - type: string - description: The name of the function to call. - ChatCompletionFunctionParameters: - type: object - additionalProperties: {} - ChatCompletionFunctions: - type: object - required: - - name - - parameters - 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: - allOf: - - $ref: '#/components/schemas/ChatCompletionFunctionParameters' - description: |- - The parameters the functions accepts, described as a JSON Schema object. See the - [guide](/docs/guides/gpt/function-calling) for examples, and the - [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation - about the format.\n\nTo describe a function that accepts no parameters, provide the value - `{\"type\": \"object\", \"properties\": {}}`. - ChatCompletionRequestMessage: - type: object - required: - - role - - content - properties: - role: - type: string - enum: - - system - - user - - assistant - - function - description: The role of the messages author. One of `system`, `user`, `assistant`, or `function`. - content: - type: string - nullable: true - description: |- - The contents of the message. `content` is required for all messages, and may be null for - assistant messages with function calls. - name: - type: string - description: |- - The name of the author of this message. `name` is required if role is `function`, and it - should be the name of the function whose response is in the `content`. May contain a-z, - A-Z, 0-9, and underscores, with a maximum length of 64 characters. - function_call: - type: object - description: The name and arguments of a function that should be called, as generated by the model. - required: - - name + /threads: + post: + tags: + - Assistants + operationId: createThread + summary: Create a thread. + parameters: [] + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/ThreadObject' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/CreateThreadRequest' + /threads/runs: + post: + tags: + - Assistants + operationId: createThreadAndRun + summary: Create a thread and run it in one request. + parameters: [] + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/RunObject' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/CreateThreadAndRunRequest' + /threads/{thread_id}: + get: + tags: + - Assistants + operationId: getThread + summary: Retrieves a thread. + parameters: + - name: thread_id + in: path + required: true + description: The ID of the thread to retrieve. + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/ThreadObject' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + post: + tags: + - Assistants + operationId: modifyThread + summary: Modifies a thread. + parameters: + - name: thread_id + in: path + required: true + description: The ID of the thread to modify. Only the `metadata` can be modified. + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/ThreadObject' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ModifyThreadRequest' + delete: + tags: + - Assistants + operationId: deleteThread + summary: Delete a thread. + parameters: + - name: thread_id + in: path + required: true + description: The ID of the thread to delete. + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/DeleteThreadResponse' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + /threads/{thread_id}/messages: + post: + tags: + - Assistants + operationId: createMessage + summary: Create a message. + parameters: + - name: thread_id + in: path + required: true + description: The ID of the [thread](/docs/api-reference/threads) to create a message for. + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/MessageObject' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/CreateMessageRequest' + get: + tags: + - Assistants + operationId: listMessages + summary: Returns a list of messages for a given thread. + parameters: + - name: thread_id + in: path + required: true + description: The ID of the [thread](/docs/api-reference/threads) the messages belong to. + schema: + type: string + - name: limit + in: query + required: false + description: |- + A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + default is 20. + schema: + type: integer + format: int32 + default: 20 + - name: order + in: query + required: false + description: |- + Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc` + for descending order. + schema: + type: string + enum: + - asc + - desc + - desc + - desc + - desc + - desc + - desc + default: desc + - name: after + in: query + required: false + 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 + required: false + 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: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/ListMessagesResponse' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + /threads/{thread_id}/messages/{message_id}: + get: + tags: + - Assistants + operationId: getMessage + summary: Retrieve a message. + parameters: + - name: thread_id + in: path + required: true + description: The ID of the [thread](/docs/api-reference/threads) to which this message belongs. + schema: + type: string + - name: message_id + in: path + required: true + description: The ID of the message to retrieve. + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/MessageObject' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + post: + tags: + - Assistants + operationId: modifyMessage + summary: Modifies a message. + parameters: + - name: thread_id + in: path + required: true + description: The ID of the thread to which this message belongs. + schema: + type: string + - name: message_id + in: path + required: true + description: The ID of the message to modify. + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/MessageObject' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ModifyMessageRequest' + /threads/{thread_id}/messages/{message_id}/files: + get: + tags: + - Assistants + operationId: listMessageFiles + summary: Returns a list of message files. + parameters: + - name: thread_id + in: path + required: true + description: The ID of the thread that the message and files belong to. + schema: + type: string + - name: message_id + in: path + required: true + description: The ID of the message that the files belongs to. + schema: + type: string + - name: limit + in: query + required: false + description: |- + A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + default is 20. + schema: + type: integer + format: int32 + default: 20 + - name: order + in: query + required: false + description: |- + Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc` + for descending order. + schema: + type: string + enum: + - asc + - desc + - desc + - desc + - desc + - desc + - desc + default: desc + - name: after + in: query + required: false + 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 + required: false + 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: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/ListMessageFilesResponse' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + /threads/{thread_id}/messages/{message_id}/files/{file_id}: + get: + tags: + - Assistants + operationId: getMessageFile + summary: Retrieves a message file. + parameters: + - name: thread_id + in: path + required: true + description: The ID of the thread to which the message and File belong. + schema: + type: string + - name: message_id + in: path + required: true + description: The ID of the message the file belongs to. + schema: + type: string + - name: file_id + in: path + required: true + description: The ID of the file being retrieved. + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/MessageFileObject' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + /threads/{thread_id}/runs: + post: + tags: + - Assistants + operationId: createRun + summary: Create a run. + parameters: + - name: thread_id + in: path + required: true + description: The ID of the thread to run. + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/RunObject' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/CreateRunRequest' + get: + tags: + - Assistants + operationId: listRuns + summary: Returns a list of runs belonging to a thread. + parameters: + - name: thread_id + in: path + required: true + description: The ID of the thread the run belongs to. + schema: + type: string + - name: limit + in: query + required: false + description: |- + A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + default is 20. + schema: + type: integer + format: int32 + default: 20 + - name: order + in: query + required: false + description: |- + Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc` + for descending order. + schema: + type: string + enum: + - asc + - desc + - desc + - desc + - desc + - desc + - desc + default: desc + - name: after + in: query + required: false + 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 + required: false + 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: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/ListRunsResponse' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + /threads/{thread_id}/runs/{run_id}: + get: + tags: + - Assistants + operationId: getRun + summary: Retrieves a run. + parameters: + - name: thread_id + in: path + required: true + description: The ID of the [thread](/docs/api-reference/threads) that was run. + schema: + type: string + - name: run_id + in: path + required: true + description: The ID of the run to retrieve. + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/RunObject' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + post: + tags: + - Assistants + operationId: modifyRun + summary: Modifies a run. + parameters: + - name: thread_id + in: path + required: true + description: The ID of the [thread](/docs/api-reference/threads) that was run. + schema: + type: string + - name: run_id + in: path + required: true + description: The ID of the run to modify. + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/RunObject' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ModifyRunRequest' + /threads/{thread_id}/runs/{run_id}/cancel: + post: + tags: + - Assistants + operationId: cancelRun + summary: Cancels a run that is `in_progress`. + parameters: + - name: thread_id + in: path + required: true + description: The ID of the thread to which this run belongs. + schema: + type: string + - name: run_id + in: path + required: true + description: The ID of the run to cancel. + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/RunObject' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + /threads/{thread_id}/runs/{run_id}/steps: + get: + tags: + - Assistants + operationId: listRunSteps + summary: Returns a list of run steps belonging to a run. + parameters: + - name: thread_id + in: path + required: true + description: The ID of the thread the run and run steps belong to. + schema: + type: string + - name: run_id + in: path + required: true + description: The ID of the run the run steps belong to. + schema: + type: string + - name: limit + in: query + required: false + description: |- + A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + default is 20. + schema: + type: integer + format: int32 + default: 20 + - name: order + in: query + required: false + description: |- + Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc` + for descending order. + schema: + type: string + enum: + - asc + - desc + - desc + - desc + - desc + - desc + - desc + default: desc + - name: after + in: query + required: false + 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 + required: false + 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: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/ListRunStepsResponse' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + /threads/{thread_id}/runs/{run_id}/steps/{step_id}: + get: + tags: + - Assistants + operationId: getRunStep + summary: Retrieves a run step. + parameters: + - name: thread_id + in: path + required: true + description: The ID of the thread to which the run and run step belongs. + schema: + type: string + - name: run_id + in: path + required: true + description: The ID of the run to which the run step belongs. + schema: + type: string + - name: step_id + in: path + required: true + description: The ID of the run step to retrieve. + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/RunStepObject' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + /threads/{thread_id}/runs/{run_id}/submit_tool_outputs: + post: + tags: + - Assistants + operationId: submitToolOuputsToRun + 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: + - name: thread_id + in: path + required: true + description: The ID of the [thread](/docs/api-reference/threads) to which this run belongs. + schema: + type: string + - name: run_id + in: path + required: true + description: The ID of the run that requires the tool output submission. + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/RunObject' + default: + description: An unexpected error response. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/SubmitToolOutputsRunRequest' +security: + - BearerAuth: [] +components: + schemas: + AssistantFileObject: + type: object + required: + - id + - object + - created_at + - assistant_id + properties: + id: + type: string + description: The identifier, which can be referenced in API endpoints. + object: + type: string + enum: + - assistant.file + description: The object type, which is always `assistant.file`. + created_at: + type: integer + format: unixtime + description: The Unix timestamp (in seconds) for when the assistant file was created. + assistant_id: + type: string + description: The assistant ID that the file is attached to. + description: A list of [Files](/docs/api-reference/files) attached to an `assistant`. + AssistantObject: + type: object + required: + - id + - object + - created_at + - name + - description + - model + - instructions + - tools + - file_ids + - metadata + properties: + id: + type: string + description: The identifier, which can be referenced in API endpoints. + object: + type: string + enum: + - assistant + description: The object type, which is always `assistant`. + created_at: + type: integer + format: unixtime + description: The Unix timestamp (in seconds) for when the assistant was created. + name: + type: string + nullable: true + maxLength: 256 + description: The name of the assistant. The maximum length is 256 characters. + description: + type: string + nullable: true + maxLength: 512 + description: The description of the assistant. The maximum length is 512 characters. + 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. + instructions: + type: string + nullable: true + maxLength: 32768 + description: The system instructions that the assistant uses. The maximum length is 32768 characters. + tools: + allOf: + - $ref: '#/components/schemas/CreateAssistantRequestToolsItem' + 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`, `retrieval`, or `function`. + default: [] + file_ids: + type: array + items: + type: string + maxItems: 20 + description: |- + A list of [file](/docs/api-reference/files) IDs attached to this assistant. There can be a + maximum of 20 files attached to the assistant. Files are ordered by their creation date in + ascending order. + default: [] + metadata: + type: object + additionalProperties: + type: string + nullable: true + 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. + x-oaiTypeLabel: map + description: Represents an `assistant` that can call the model and use tools. + AssistantToolsCode: + type: object + required: + - type + properties: + type: + type: string + enum: + - code_interpreter + description: 'The type of tool being defined: `code_interpreter`' + AssistantToolsFunction: + type: object + required: + - type + - function + properties: + type: + type: string + enum: + - function + description: 'The type of tool being defined: `function`' + function: + $ref: '#/components/schemas/FunctionObject' + AssistantToolsRetrieval: + type: object + required: + - type + properties: + type: + type: string + enum: + - retrieval + description: 'The type of tool being defined: `retrieval`' + AudioSegment: + type: object + required: + - id + - seek + - start + - end + - text + - tokens + - temperature + - avg_logprob + - compression_ratio + - no_speech_prob + properties: + id: + type: integer + format: int64 + description: The zero-based index of this segment. + seek: + type: integer + format: int64 + description: |- + The seek position associated with the processing of this audio segment. Seek positions are + expressed as hundredths of seconds. The model may process several segments from a single seek + position, so while the seek position will never represent a later time than the segment's + start, the segment's start may represent a significantly later time than the segment's + associated seek position. + start: + type: number + format: double + description: The time at which this segment started relative to the beginning of the audio. + end: + type: number + format: double + description: The time at which this segment ended relative to the beginning of the audio. + text: + type: string + description: The text that was part of this audio segment. + tokens: + allOf: + - $ref: '#/components/schemas/TokenArrayItem' + description: The token IDs matching the text in this audio segment. + temperature: + type: number + format: double + minimum: 0 + maximum: 1 + description: The temperature score associated with this audio segment. + avg_logprob: + type: number + format: double + description: The average log probability associated with this audio segment. + compression_ratio: + type: number + format: double + description: The compression ratio of this audio segment. + no_speech_prob: + type: number + format: double + description: The probability of no speech detection within this audio segment. + ChatCompletionFunctionCallOption: + type: object + required: + - name + 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. + ChatCompletionFunctions: + type: object + required: + - name + 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' + deprecated: true + ChatCompletionMessageToolCall: + type: object + required: + - id + - type + - function + properties: + 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: + - name + - arguments + description: The function that the model called. + ChatCompletionMessageToolCallsItem: + type: array + items: + $ref: '#/components/schemas/ChatCompletionMessageToolCall' + description: The tool calls generated by the model, such as function calls. + ChatCompletionNamedToolChoice: + type: object + required: + - type + - 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 + description: Specifies a tool the model should use. Use to force the model to call a specific function. + ChatCompletionRequestAssistantMessage: + type: object + required: + - role + properties: + content: + type: string + nullable: true + 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/ChatCompletionMessageToolCallsItem' + function_call: + type: object + 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 + 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 + ChatCompletionRequestFunctionMessage: + type: object + required: + - role + - content + - name + properties: + role: + type: string + enum: + - function + description: The role of the messages author, in this case `function`. + content: + type: string + nullable: true + description: The contents of the function message. + name: + type: string + description: The name of the function to call. + 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 + ChatCompletionRequestMessageContentPart: + oneOf: + - $ref: '#/components/schemas/ChatCompletionRequestMessageContentPartText' + - $ref: '#/components/schemas/ChatCompletionRequestMessageContentPartImage' + x-oaiExpandable: true + ChatCompletionRequestMessageContentPartImage: + type: object + required: + - type + - image_url + properties: + type: + type: string + enum: + - image_url + description: The type of the content part. + image_url: + type: object + properties: + url: + anyOf: + - type: string + format: uri + - type: string + description: Either a URL of the image or the base64 encoded image data. + detail: + type: string + enum: + - auto + - low + - high + 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 + required: + - url + ChatCompletionRequestMessageContentPartText: + type: object + required: + - type + - text + properties: + type: + type: string + enum: + - text + - json_object + description: The type of the content part. + text: + type: string + description: The text content. + ChatCompletionRequestMessageContentParts: + type: array + items: + $ref: '#/components/schemas/ChatCompletionRequestMessageContentPart' + minItems: 1 + ChatCompletionRequestSystemMessage: + type: object + required: + - content + - role + properties: + content: + type: string + description: The contents of the system message. + x-oaiExpandable: true + 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. + ChatCompletionRequestToolMessage: + type: object + required: + - role + - content + - tool_call_id + 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. + ChatCompletionRequestUserMessage: + type: object + required: + - content + - role + properties: + content: + allOf: + - $ref: '#/components/schemas/ChatCompletionRequestUserMessageContent' + description: The contents of the system message. + x-oaiExpandable: true + role: + type: string + enum: + - user + - assistant + 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. + ChatCompletionRequestUserMessageContent: + oneOf: + - type: string + - $ref: '#/components/schemas/ChatCompletionRequestMessageContentParts' + ChatCompletionResponseMessage: + type: object + required: + - content + - role + properties: + content: + type: string + nullable: true + description: The contents of the message. + tool_calls: + $ref: '#/components/schemas/ChatCompletionMessageToolCallsItem' + role: + type: string + enum: + - assistant + description: The role of the author of this message. + function_call: + type: object + 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 + 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 + ChatCompletionTokenLogprob: + type: object + required: + - token + - logprob + - bytes + - top_logprobs + properties: + token: + type: string + description: The token. + logprob: + type: number + format: double + description: The log probability of this token. + bytes: + type: array + items: + type: integer + format: int64 + nullable: true + 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. + top_logprobs: + type: array + items: + type: object + properties: + token: + type: string + description: The token. + logprob: + type: number + format: double + description: The log probability of this token. + bytes: + type: array + items: + type: integer + format: int64 + nullable: true + 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. + required: + - token + - logprob + - bytes + 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. + ChatCompletionTool: + type: object + required: + - type + - function + properties: + type: + type: string + enum: + - function + description: The type of the tool. Currently, only `function` is supported. + function: + $ref: '#/components/schemas/FunctionObject' + ChatCompletionToolChoiceOption: + oneOf: + - type: string + enum: + - none + - auto + - auto + - $ref: '#/components/schemas/ChatCompletionNamedToolChoice' + description: |- + 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 + `{"type": "function", "function": {"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. + x-oaiExpandable: true + CompletionUsage: + type: object + required: + - prompt_tokens + - completion_tokens + - total_tokens + properties: + prompt_tokens: + type: integer + format: int64 + description: Number of tokens in the prompt. + completion_tokens: + type: integer + format: int64 + description: Number of tokens in the generated completion + total_tokens: + type: integer + format: int64 + description: Total number of tokens used in the request (prompt + completion). + description: Usage statistics for the completion request. + CreateAssistantFileRequest: + type: object + required: + - file_id + properties: + file_id: + type: string + description: |- + A [File](/docs/api-reference/files) ID (with `purpose="assistants"`) that the assistant should + use. Useful for tools like `retrieval` and `code_interpreter` that can access files. + CreateAssistantRequest: + type: object + required: + - model + properties: + 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. + name: + type: string + nullable: true + maxLength: 256 + description: The name of the assistant. The maximum length is 256 characters. + description: + type: string + nullable: true + maxLength: 512 + description: The description of the assistant. The maximum length is 512 characters. + instructions: + type: string + nullable: true + maxLength: 32768 + description: The system instructions that the assistant uses. The maximum length is 32768 characters. + tools: + allOf: + - $ref: '#/components/schemas/CreateAssistantRequestToolsItem' + 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`, `retrieval`, or `function`. + default: [] + file_ids: + type: array + items: + type: string + maxItems: 20 + description: |- + A list of [file](/docs/api-reference/files) IDs attached to this assistant. There can be a + maximum of 20 files attached to the assistant. Files are ordered by their creation date in + ascending order. + default: [] + metadata: + type: object + additionalProperties: + type: string + nullable: true + 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. + x-oaiTypeLabel: map + CreateAssistantRequestTool: + oneOf: + - $ref: '#/components/schemas/AssistantToolsCode' + - $ref: '#/components/schemas/AssistantToolsRetrieval' + - $ref: '#/components/schemas/AssistantToolsFunction' + x-oaiExpandable: true + CreateAssistantRequestToolsItem: + type: array + items: + $ref: '#/components/schemas/CreateAssistantRequestTool' + maxItems: 128 + CreateChatCompletionRequest: + type: object + required: + - messages + - model + properties: + messages: + type: array + items: + $ref: '#/components/schemas/ChatCompletionRequestMessage' + minItems: 1 + description: |- + A list of messages comprising the conversation so far. + [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb). + model: + anyOf: + - type: string + - type: string + enum: + - 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-16k-0613 + 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. + x-oaiTypeLabel: string + frequency_penalty: + type: number + format: double + nullable: true + minimum: -2 + maximum: 2 + 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/gpt/parameter-details) + default: 0 + logit_bias: + type: object + additionalProperties: + type: integer + format: int64 + nullable: true + 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. + x-oaiTypeLabel: map + default: null + logprobs: + type: boolean + nullable: true + 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`. This option is + currently not available on the `gpt-4-vision-preview` model. + default: false + top_logprobs: + type: integer + format: int64 + nullable: true + minimum: 0 + maximum: 5 + description: |- + An integer between 0 and 5 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. + max_tokens: + type: integer + format: int64 + nullable: true + minimum: 0 + 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. + default: 16 + n: + type: integer + format: int64 + nullable: true + minimum: 1 + maximum: 128 + 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. + default: 1 + presence_penalty: + type: number + format: double + nullable: true + minimum: -2 + maximum: 2 + 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/gpt/parameter-details) + default: 0 + response_format: + type: object + properties: + type: + type: string + enum: + - text + - json_object + description: Must be one of `text` or `json_object`. + default: text + 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 `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. + seed: + type: integer + format: int64 + nullable: true + minimum: -9223372036854776000 + maximum: 9223372036854776000 + 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 + stop: + oneOf: + - $ref: '#/components/schemas/Stop' + nullable: true + description: Up to 4 sequences where the API will stop generating further tokens. + default: null + stream: + type: boolean + nullable: true + 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). + default: false + temperature: + type: number + format: double + nullable: true + minimum: 0 + maximum: 2 + 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. + default: 1 + top_p: + type: number + format: double + nullable: true + minimum: 0 + maximum: 1 + 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. + default: 1 + tools: + type: array + items: + $ref: '#/components/schemas/ChatCompletionTool' + 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. + tool_choice: + $ref: '#/components/schemas/ChatCompletionToolChoiceOption' + user: + allOf: + - $ref: '#/components/schemas/User' + 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). + function_call: + anyOf: + - type: string + enum: + - none + - auto + - auto + - $ref: '#/components/schemas/ChatCompletionFunctionCallOption' + 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. + deprecated: true + x-oaiExpandable: true + functions: + type: array + items: + $ref: '#/components/schemas/ChatCompletionFunctions' + minItems: 1 + maxItems: 128 + description: |- + Deprecated in favor of `tools`. + + A list of functions the model may generate JSON inputs for. + deprecated: true + CreateChatCompletionResponse: + type: object + required: + - id + - choices + - created + - model + - object + properties: + id: + type: string + description: A unique identifier for the chat completion. + choices: + type: array + items: + type: object + properties: + finish_reason: + type: string + enum: + - stop + - length + - tool_calls + - content_filter + - function_call + - length + - content_filter + 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. + index: + type: integer + format: int64 + description: The index of the choice in the list of choices. + message: + $ref: '#/components/schemas/ChatCompletionResponseMessage' + logprobs: + type: object + properties: + content: + type: array + items: + $ref: '#/components/schemas/ChatCompletionTokenLogprob' + nullable: true + required: + - content + nullable: true + description: Log probability information for the choice. + required: + - finish_reason + - index + - message + - logprobs + description: A list of chat completion choices. Can be more than one if `n` is greater than 1. + created: + type: integer + format: unixtime + 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 + enum: + - chat.completion + description: The object type, which is always `chat.completion`. + usage: + $ref: '#/components/schemas/CompletionUsage' + description: Represents a chat completion response returned by model, based on the provided input. + CreateCompletionRequest: + type: object + required: + - model + - prompt + properties: + model: + anyOf: + - type: string + - type: string + enum: + - gpt-3.5-turbo-instruct + - davinci-002 + - babbage-002 + 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. + x-oaiTypeLabel: string + prompt: + oneOf: + - $ref: '#/components/schemas/Prompt' + nullable: true + 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|> + best_of: + type: integer + format: int64 + nullable: true + minimum: 0 + maximum: 20 + 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`. + default: 1 + echo: + type: boolean + nullable: true + description: Echo back the prompt in addition to the completion + default: false + frequency_penalty: + type: number + format: double + nullable: true + minimum: -2 + maximum: 2 + 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/gpt/parameter-details) + default: 0 + logit_bias: + type: object + additionalProperties: + type: integer + format: int64 + nullable: true + 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. + x-oaiTypeLabel: map + default: null + logprobs: + type: integer + format: int64 + nullable: true + minimum: 0 + maximum: 5 + description: |- + Include the log probabilities on the `logprobs` most likely 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. + default: null + max_tokens: + type: integer + format: int64 + nullable: true + minimum: 0 + description: |- + The maximum number of [tokens](/tokenizer) to generate in the completion. + + The token count of your prompt plus `max_tokens` cannot exceed the model's context length. + [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) + for counting tokens. + default: 16 + n: + type: integer + format: int64 + nullable: true + minimum: 1 + maximum: 128 + 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`. + default: 1 + presence_penalty: + type: number + format: double + nullable: true + minimum: -2 + maximum: 2 + 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/gpt/parameter-details) + default: 0 + seed: + type: integer + format: int64 + nullable: true + minimum: -9223372036854776000 + maximum: 9223372036854776000 + 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. + x-oaiMeta: + beta: true + stop: + oneOf: + - $ref: '#/components/schemas/Stop' + nullable: true + description: Up to 4 sequences where the API will stop generating further tokens. + default: null + stream: + type: boolean + nullable: true + 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://github.com/openai/openai-cookbook/blob/main/examples/How_to_stream_completions.ipynb). + default: false + suffix: + type: string + nullable: true + description: The suffix that comes after a completion of inserted text. + default: null + temperature: + type: number + format: double + nullable: true + minimum: 0 + maximum: 2 + 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. + default: 1 + top_p: + type: number + format: double + nullable: true + minimum: 0 + maximum: 1 + 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. + default: 1 + user: + allOf: + - $ref: '#/components/schemas/User' + 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). + CreateCompletionResponse: + type: object + required: + - id + - choices + - created + - model + - object + properties: + id: + type: string + description: A unique identifier for the completion. + choices: + type: array + items: + type: object + properties: + index: + type: integer + format: int64 + text: + type: string + logprobs: + type: object + properties: + tokens: + type: array + items: + type: string + token_logprobs: + type: array + items: + type: number + format: double + top_logprobs: + type: array + items: + type: object + additionalProperties: + type: integer + format: int64 + text_offset: + type: array + items: + type: integer + format: int64 + required: + - tokens + - token_logprobs + - top_logprobs + - text_offset + nullable: true + finish_reason: + type: string + enum: + - stop + - length + - tool_calls + - content_filter + - function_call + - length + - content_filter + 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, or `content_filter` if content was omitted + due to a flag from our content filters, `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. + required: + - index + - text + - logprobs + - finish_reason + description: The list of completion choices the model generated for the input. + created: + type: integer + format: unixtime + description: The Unix timestamp (in seconds) of when the completion was created. + model: + type: string + description: The model used for the 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 + enum: + - text_completion + description: The object type, which is always `text_completion`. + usage: + allOf: + - $ref: '#/components/schemas/CompletionUsage' + description: Usage statistics for the completion request. + 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). + CreateEmbeddingRequest: + type: object + required: + - input + - model + properties: + input: + allOf: + - $ref: '#/components/schemas/CreateEmbeddingRequestInput' + 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. Each input must not exceed + the max input tokens for the model (8191 tokens for `text-embedding-ada-002`) and cannot be an + empty string. + [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) + for counting tokens. + x-oaiExpandable: true + model: + anyOf: + - type: string + - type: string + enum: + - text-embedding-ada-002 + - text-embedding-3-small + - text-embedding-3-large + 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. + x-oaiTypeLabel: string + encoding_format: + type: string + enum: + - float + - base64 + description: |- + The format to return the embeddings in. Can be either `float` or + [`base64`](https://pypi.org/project/pybase64/). + default: float + dimensions: + type: integer + format: int64 + minimum: 1 + description: |- + The number of dimensions the resulting output embeddings should have. Only supported in + `text-embedding-3` and later models. + user: + allOf: + - $ref: '#/components/schemas/User' + 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). + CreateEmbeddingRequestInput: + oneOf: + - type: string + - type: array + items: + type: string + - $ref: '#/components/schemas/TokenArrayItem' + - $ref: '#/components/schemas/TokenArrayArray' + CreateEmbeddingResponse: + type: object + required: + - data + - model + - object + - usage + properties: + data: + type: array + items: + $ref: '#/components/schemas/Embedding' + description: The list of embeddings generated by the model. + model: + type: string + description: The name of the model used to generate the embedding. + object: + type: string + enum: + - list + description: The object type, which is always "list". + usage: + type: object + properties: + prompt_tokens: + type: integer + format: int64 + description: The number of tokens used by the prompt. + total_tokens: + type: integer + format: int64 + description: The total number of tokens used by the request. + required: + - prompt_tokens + - total_tokens + description: The usage information for the request. + CreateFileRequestMultiPart: + type: object + required: + - file + - purpose + properties: + file: + type: string + format: binary + description: The file object (not file name) to be uploaded. + purpose: + type: string + enum: + - fine-tune + - assistants + description: |- + The intended purpose of the uploaded file. Use "fine-tune" for + [Fine-tuning](/docs/api-reference/fine-tuning) and "assistants" for + [Assistants](/docs/api-reference/assistants) and [Messages](/docs/api-reference/messages). This + allows us to validate the format of the uploaded file is correct for fine-tuning. + CreateFineTuneRequest: + type: object + required: + - training_file + properties: + training_file: + type: string + description: |- + The ID of an uploaded file that contains training data. + + See [upload file](/docs/api-reference/files/upload) for how to upload a file. + + Your dataset must be formatted as a JSONL file, where each training example is a JSON object + with the keys "prompt" and "completion". Additionally, you must upload your file with the + purpose `fine-tune`. + + See the [fine-tuning guide](/docs/guides/legacy-fine-tuning/creating-training-data) for more + details. + validation_file: + type: string + nullable: true + 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](/docs/guides/legacy-fine-tuning/analyzing-your-fine-tuned-model). + Your train and validation data should be mutually exclusive. + + Your dataset must be formatted as a JSONL file, where each validation example is a JSON object + with the keys "prompt" and "completion". Additionally, you must upload your file with the + purpose `fine-tune`. + + See the [fine-tuning guide](/docs/guides/legacy-fine-tuning/creating-training-data) for more + details. + model: + anyOf: + - type: string + - type: string + enum: + - ada + - babbage + - curie + - davinci + nullable: true + description: |- + The name of the base model to fine-tune. You can select one of "ada", "babbage", "curie", + "davinci", or a fine-tuned model created after 2022-04-21 and before 2023-08-22. To learn more + about these models, see the [Models](/docs/models) documentation. + x-oaiTypeLabel: string + n_epochs: + type: integer + format: int64 + nullable: true + description: |- + The number of epochs to train the model for. An epoch refers to one full cycle through the + training dataset. + default: 4 + batch_size: + type: integer + format: int64 + nullable: true + description: |- + The batch size to use for training. The batch size is the number of training examples used to + train a single forward and backward pass. + + By default, the batch size will be dynamically configured to be ~0.2% of the number of examples + in the training set, capped at 256 - in general, we've found that larger batch sizes tend to + work better for larger datasets. + default: null + learning_rate_multiplier: + type: number + format: double + nullable: true + description: |- + The learning rate multiplier to use for training. The fine-tuning learning rate is the original + learning rate used for pretraining multiplied by this value. + + By default, the learning rate multiplier is the 0.05, 0.1, or 0.2 depending on final + `batch_size` (larger learning rates tend to perform better with larger batch sizes). We + recommend experimenting with values in the range 0.02 to 0.2 to see what produces the best + results. + default: null + prompt_loss_rate: + type: number + format: double + nullable: true + description: |- + The weight to use for loss on the prompt tokens. This controls how much the model tries to + learn to generate the prompt (as compared to the completion which always has a weight of 1.0), + and can add a stabilizing effect to training when completions are short. + + If prompts are extremely long (relative to completions), it may make sense to reduce this + weight so as to avoid over-prioritizing learning the prompt. + default: 0.01 + compute_classification_metrics: + type: boolean + nullable: true + description: |- + If set, we calculate classification-specific metrics such as accuracy and F-1 score using the + validation set at the end of every epoch. These metrics can be viewed in the + [results file](/docs/guides/legacy-fine-tuning/analyzing-your-fine-tuned-model). + + In order to compute classification metrics, you must provide a `validation_file`. Additionally, + you must specify `classification_n_classes` for multiclass classification or + `classification_positive_class` for binary classification. + default: false + classification_n_classes: + type: integer + format: int64 + nullable: true + description: |- + The number of classes in a classification task. + + This parameter is required for multiclass classification. + default: null + classification_positive_class: + type: string + nullable: true + description: |- + The positive class in binary classification. + + This parameter is needed to generate precision, recall, and F1 metrics when doing binary + classification. + default: null + classification_betas: + type: array + items: + type: number + format: double + nullable: true + description: |- + If this is provided, we calculate F-beta scores at the specified beta values. The F-beta score + is a generalization of F-1 score. This is only used for binary classification. + + With a beta of 1 (i.e. the F-1 score), precision and recall are given the same weight. A larger + beta score puts more weight on recall and less on precision. A smaller beta score puts more + weight on precision and less on recall. + default: null + suffix: + oneOf: + - $ref: '#/components/schemas/SuffixString' + nullable: true + 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 + `ada:ft-your-org:custom-model-name-2022-02-15-04-21-04`. + default: null + CreateFineTuningJobRequest: + type: object + required: + - training_file + - model + properties: + training_file: + type: string + description: |- + The ID of an uploaded file that contains training data. + + See [upload file](/docs/api-reference/files/upload) 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`. + + See the [fine-tuning guide](/docs/guides/fine-tuning) for more details. + validation_file: + type: string + nullable: true + 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. + model: + anyOf: + - type: string + - type: string + enum: + - babbage-002 + - davinci-002 + - gpt-3.5-turbo + 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). + x-oaiTypeLabel: string + hyperparameters: + type: object properties: - name: - type: string - description: The name of the function to call. - arguments: - type: string + n_epochs: + anyOf: + - type: string + enum: + - auto + - low + - high + - $ref: '#/components/schemas/NEpochs' 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. - ChatCompletionResponseMessage: + The number of epochs to train the model for. An epoch refers to one full cycle through the + training dataset. + default: auto + description: The hyperparameters used for the fine-tuning job. + suffix: + oneOf: + - $ref: '#/components/schemas/SuffixString' + nullable: true + 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`. + default: null + CreateImageEditRequestMultiPart: + type: object + required: + - image + - prompt + properties: + image: + type: string + format: binary + 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. + prompt: + type: string + maxLength: 1000 + description: A text description of the desired image(s). The maximum length is 1000 characters. + mask: + type: string + format: binary + 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`. + model: + anyOf: + - type: string + - type: string + enum: + - dall-e-2 + description: The model to use for image generation. Only `dall-e-2` is supported at this time. + x-oaiTypeLabel: string + default: dall-e-2 + n: + oneOf: + - $ref: '#/components/schemas/ImagesN' + nullable: true + description: The number of images to generate. Must be between 1 and 10. + default: 1 + size: + type: string + enum: + - 256x256 + - 512x512 + - 1024x1024 + - 512x512 + - 1024x1024 + nullable: true + description: The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. + default: 1024x1024 + response_format: + type: string + enum: + - url + - b64_json + - b64_json + nullable: true + description: The format in which the generated images are returned. Must be one of `url` or `b64_json`. + default: url + user: + allOf: + - $ref: '#/components/schemas/User' + 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). + CreateImageRequest: + type: object + required: + - prompt + properties: + 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`. + model: + anyOf: + - type: string + - type: string + enum: + - dall-e-2 + - dall-e-3 + description: The model to use for image generation. + x-oaiTypeLabel: string + default: dall-e-2 + n: + oneOf: + - $ref: '#/components/schemas/ImagesN' + nullable: true + description: |- + The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only `n=1` is + supported. + default: 1 + quality: + type: string + enum: + - standard + - hd + nullable: true + 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`. + default: standard + response_format: + type: string + enum: + - url + - b64_json + nullable: true + description: The format in which the generated images are returned. Must be one of `url` or `b64_json`. + default: url + size: + type: string + enum: + - 256x256 + - 512x512 + - 1024x1024 + - 1792x1024 + - 1024x1792 + 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. + default: 1024x1024 + style: + type: string + enum: + - vivid + - natural + 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`. + default: vivid + user: + allOf: + - $ref: '#/components/schemas/User' + 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). + CreateImageVariationRequestMultiPart: + type: object + required: + - image + properties: + image: + type: string + format: binary + description: |- + The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, + and square. + model: + anyOf: + - type: string + - type: string + enum: + - dall-e-2 + description: The model to use for image generation. Only `dall-e-2` is supported at this time. + x-oaiTypeLabel: string + default: dall-e-2 + n: + oneOf: + - $ref: '#/components/schemas/ImagesN' + nullable: true + description: The number of images to generate. Must be between 1 and 10. + default: 1 + response_format: + type: string + enum: + - url + - b64_json + - b64_json + nullable: true + description: The format in which the generated images are returned. Must be one of `url` or `b64_json`. + default: url + size: + type: string + enum: + - 256x256 + - 512x512 + - 1024x1024 + - 512x512 + - 1024x1024 + nullable: true + description: The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. + default: 1024x1024 + user: + allOf: + - $ref: '#/components/schemas/User' + 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). + CreateMessageRequest: type: object required: - role @@ -1007,1950 +3768,2293 @@ components: role: type: string enum: - - system - user - assistant - - function - description: The role of the author of this message. + description: The role of the entity that is creating the message. Currently only `user` is supported. content: type: string - nullable: true - description: The contents of the message. - function_call: + minLength: 1 + maxLength: 32768 + description: The content of the message. + file_ids: + type: array + items: + type: string + minItems: 1 + maxItems: 10 + description: |- + A list of [File](/docs/api-reference/files) IDs that the message should use. There can be a + maximum of 10 files attached to a message. Useful for tools like `retrieval` and + `code_interpreter` that can access and use files. + default: [] + metadata: type: object - description: The name and arguments of a function that should be called, as generated by the model. - required: - - name - - arguments - 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. - CompletionUsage: + additionalProperties: + type: string + nullable: true + 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. + x-oaiTypeLabel: map + CreateModerationRequest: + type: object + required: + - input + properties: + input: + allOf: + - $ref: '#/components/schemas/CreateModerationRequestInput' + description: The input text to classify + model: + anyOf: + - type: string + - type: string + enum: + - text-moderation-latest + - text-moderation-stable + 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`. + x-oaiTypeLabel: string + default: text-moderation-latest + CreateModerationRequestInput: + oneOf: + - type: string + - type: array + items: + type: string + CreateModerationResponse: + type: object + required: + - id + - model + - results + 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 + items: + type: object + properties: + flagged: + type: boolean + description: Whether the content violates [OpenAI's usage policies](/policies/usage-policies). + categories: + type: object + 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 harrassment. + 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 + description: A list of the categories, and whether they are flagged or not. + category_scores: + type: object + properties: + hate: + type: number + format: double + description: The score for the category 'hate'. + hate/threatening: + type: number + format: double + description: The score for the category 'hate/threatening'. + harassment: + type: number + format: double + description: The score for the category 'harassment'. + harassment/threatening: + type: number + format: double + description: The score for the category 'harassment/threatening'. + self-harm: + type: number + format: double + description: The score for the category 'self-harm'. + self-harm/intent: + type: number + format: double + description: The score for the category 'self-harm/intent'. + self-harm/instructions: + type: number + format: double + description: The score for the category 'self-harm/instructive'. + sexual: + type: number + format: double + description: The score for the category 'sexual'. + sexual/minors: + type: number + format: double + description: The score for the category 'sexual/minors'. + violence: + type: number + format: double + description: The score for the category 'violence'. + violence/graphic: + type: number + format: double + 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 + description: A list of the categories along with their scores as predicted by model. + required: + - flagged + - categories + - category_scores + description: A list of moderation objects. + description: Represents policy compliance report by OpenAI's content moderation model against a given input. + CreateRunRequest: type: object - description: Usage statistics for the completion request. required: - - prompt_tokens - - completion_tokens - - total_tokens + - assistant_id properties: - prompt_tokens: - type: integer - format: int64 - description: Number of tokens in the prompt. - completion_tokens: - type: integer - format: int64 - description: Number of tokens in the generated completion - total_tokens: - type: integer - format: int64 - description: Total number of tokens used in the request (prompt + completion). - CreateChatCompletionRequest: + assistant_id: + type: string + description: The ID of the [assistant](/docs/api-reference/assistants) to use to execute this run. + model: + type: string + nullable: true + 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. + instructions: + type: string + nullable: true + description: |- + Overrides the [instructions](/docs/api-reference/assistants/createAssistant) of the assistant. + This is useful for modifying the behavior on a per-run basis. + additional_instructions: + type: string + nullable: true + 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. + tools: + type: object + allOf: + - $ref: '#/components/schemas/CreateRunRequestToolsItem' + nullable: true + description: |- + Override the tools the assistant can use for this run. This is useful for modifying the + behavior on a per-run basis. + metadata: + type: object + additionalProperties: + type: string + nullable: true + 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. + x-oaiTypeLabel: map + CreateRunRequestTool: + oneOf: + - $ref: '#/components/schemas/AssistantToolsCode' + - $ref: '#/components/schemas/AssistantToolsRetrieval' + - $ref: '#/components/schemas/AssistantToolsFunction' + x-oaiExpandable: true + CreateRunRequestToolsItem: + type: array + items: + $ref: '#/components/schemas/CreateRunRequestTool' + maxItems: 20 + CreateSpeechRequest: type: object required: - model - - messages + - input + - voice properties: model: anyOf: - type: string - type: string enum: - - gpt4 - - 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-16k-0613 - 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. + - tts-1 + - tts-1-hd + description: 'One of the available [TTS models](/docs/models/tts): `tts-1` or `tts-1-hd`' x-oaiTypeLabel: string - messages: - type: array - items: - $ref: '#/components/schemas/ChatCompletionRequestMessage' - description: |- - A list of messages comprising the conversation so far. - [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb). - minItems: 1 - functions: - type: array - items: - $ref: '#/components/schemas/ChatCompletionFunctions' - description: A list of functions the model may generate JSON inputs for. - minItems: 1 - maxItems: 128 - function_call: - anyOf: - - type: string - enum: - - none - - auto - - $ref: '#/components/schemas/ChatCompletionFunctionCallOption' - description: |- - Controls how the model responds to function calls. `none` means the model does not call a - function, and responds to the end-user. `auto` means the model can pick between an end-user 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. - temperature: - oneOf: - - $ref: '#/components/schemas/Temperature' - nullable: true - 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. - default: 1 - top_p: - oneOf: - - $ref: '#/components/schemas/TopP' - nullable: true + input: + type: string + maxLength: 4096 + description: The text to generate audio for. The maximum length is 4096 characters. + voice: + type: string + enum: + - alloy + - echo + - fable + - onyx + - nova + - shimmer 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. + 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). + response_format: + type: string + enum: + - mp3 + - opus + - aac + - flac + description: The format to audio in. Supported formats are `mp3`, `opus`, `aac`, and `flac`. + default: mp3 + speed: + type: number + format: double + minimum: 0.25 + maximum: 4 + description: The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is the default. default: 1 - n: - oneOf: - - $ref: '#/components/schemas/N' + CreateThreadAndRunRequest: + type: object + required: + - assistant_id + properties: + assistant_id: + type: string + description: The ID of the [assistant](/docs/api-reference/assistants) to use to execute this run. + thread: + allOf: + - $ref: '#/components/schemas/CreateThreadRequest' + description: If no thread is provided, an empty thread will be created. + model: + type: string nullable: true 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`. - default: 1 - max_tokens: - oneOf: - - $ref: '#/components/schemas/MaxTokens' + 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. + instructions: + type: string nullable: true description: |- - The maximum number of [tokens](/tokenizer) to generate in the completion. - - The token count of your prompt plus `max_tokens` cannot exceed the model's context length. - [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) - for counting tokens. - default: 16 - stop: + Override the default system message of the assistant. This is useful for modifying the behavior + on a per-run basis. + tools: + type: object allOf: - - $ref: '#/components/schemas/Stop' - description: Up to 4 sequences where the API will stop generating further tokens. - default: null - presence_penalty: - oneOf: - - $ref: '#/components/schemas/Penalty' - nullable: true - 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/gpt/parameter-details) - frequency_penalty: - oneOf: - - $ref: '#/components/schemas/Penalty' + - $ref: '#/components/schemas/CreateRunRequestToolsItem' nullable: true 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/gpt/parameter-details) - logit_bias: + Override the tools the assistant can use for this run. This is useful for modifying the + behavior on a per-run basis. + metadata: type: object - 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. additionalProperties: - type: integer - format: int64 + type: string nullable: true - x-oaiTypeLabel: map - user: - allOf: - - $ref: '#/components/schemas/User' 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). - stream: - type: boolean + 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. + x-oaiTypeLabel: map + CreateThreadRequest: + type: object + properties: + messages: + type: array + items: + $ref: '#/components/schemas/CreateMessageRequest' + description: A list of [messages](/docs/api-reference/messages) to start the thread with. + metadata: + type: object + additionalProperties: + type: string nullable: true 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://github.com/openai/openai-cookbook/blob/main/examples/How_to_stream_completions.ipynb). - default: true - CreateChatCompletionResponse: + 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. + CreateTranscriptionRequestMultiPart: type: object - description: Represents a chat completion response returned by model, based on the provided input. required: - - id - - object - - created + - file - model - - choices properties: - id: + file: + type: string + format: binary + 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. + x-oaiTypeLabel: file + model: + anyOf: + - type: string + - type: string + enum: + - whisper-1 + description: ID of the model to use. Only `whisper-1` is currently available. + 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. + response_format: + type: string + enum: + - json + - text + - srt + - verbose_json + - vtt + - text + - srt + - verbose_json + - vtt + description: |- + The format of the transcript output, in one of these options: json, text, srt, verbose_json, or + vtt. + default: json + temperature: + type: number + format: double + minimum: 0 + maximum: 1 + 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 + CreateTranscriptionResponse: + type: object + required: + - text + properties: + text: type: string - description: A unique identifier for the chat completion. - object: + description: The transcribed text for the provided audio data. + task: type: string - description: The object type, which is always `chat.completion`. - created: - type: integer - format: unixtime - description: The Unix timestamp (in seconds) of when the chat completion was created. - model: + enum: + - transcribe + description: The label that describes which operation type generated the accompanying response data. + language: type: string - description: The model used for the chat completion. - choices: + description: The spoken language that was detected in the audio data. + duration: + type: number + format: double + description: The total duration of the audio processed to produce accompanying transcription information. + segments: type: array items: - type: object - required: - - index - - message - - finish_reason - properties: - index: - type: integer - format: int64 - description: The index of the choice in the list of choices. - message: - $ref: '#/components/schemas/ChatCompletionResponseMessage' - finish_reason: - type: string - enum: - - stop - - length - - function_call - - content_filter - 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 the content was omitted due to - a flag from our content filters, or `function_call` if the model called a function. - description: A list of chat completion choices. Can be more than one if `n` is greater than 1. - usage: - $ref: '#/components/schemas/CompletionUsage' - x-oaiMeta: - name: The chat completion object - group: chat - example: '' - CreateCompletionRequest: + $ref: '#/components/schemas/AudioSegment' + description: |- + A collection of information about the timing, probabilities, and other detail of each processed + audio segment. + CreateTranslationRequestMultiPart: type: object required: + - file - model - - prompt properties: + file: + type: string + format: binary + description: |- + The audio file object (not file name) to translate, in one of these formats: flac, mp3, mp4, + mpeg, mpga, m4a, ogg, wav, or webm. + x-oaiTypeLabel: file model: anyOf: - type: string - type: string enum: - - babbage-002 - - davinci-002 - - text-davinci-003 - - text-davinci-002 - - text-davinci-001 - - code-davinci-002 - - text-curie-001 - - text-babbage-001 - - text-ada-001 - 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. + - whisper-1 + description: ID of the model to use. Only `whisper-1` is currently available. x-oaiTypeLabel: string prompt: - allOf: - - $ref: '#/components/schemas/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|> - suffix: type: string - nullable: true - description: The suffix that comes after a completion of inserted text. - default: null - temperature: - oneOf: - - $ref: '#/components/schemas/Temperature' - nullable: true - 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. - default: 1 - top_p: - oneOf: - - $ref: '#/components/schemas/TopP' - nullable: true - 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. - default: 1 - n: - oneOf: - - $ref: '#/components/schemas/N' - nullable: true - 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`. - default: 1 - max_tokens: - oneOf: - - $ref: '#/components/schemas/MaxTokens' - nullable: true - description: |- - The maximum number of [tokens](/tokenizer) to generate in the completion. - - The token count of your prompt plus `max_tokens` cannot exceed the model's context length. - [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) - for counting tokens. - default: 16 - stop: - allOf: - - $ref: '#/components/schemas/Stop' - description: Up to 4 sequences where the API will stop generating further tokens. - default: null - presence_penalty: - oneOf: - - $ref: '#/components/schemas/Penalty' - nullable: true - 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/gpt/parameter-details) - frequency_penalty: - oneOf: - - $ref: '#/components/schemas/Penalty' - nullable: true - 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/gpt/parameter-details) - logit_bias: - type: object - 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. - additionalProperties: - type: integer - format: int64 - nullable: true - x-oaiTypeLabel: map - user: - allOf: - - $ref: '#/components/schemas/User' 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). - stream: - type: boolean - nullable: true + 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. + response_format: + type: string + enum: + - json + - text + - srt + - verbose_json + - vtt + - text + - srt + - verbose_json + - vtt 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://github.com/openai/openai-cookbook/blob/main/examples/How_to_stream_completions.ipynb). - default: true - logprobs: - type: integer - format: int64 - nullable: true + The format of the transcript output, in one of these options: json, text, srt, verbose_json, or + vtt. + default: json + temperature: + type: number + format: double + minimum: 0 + maximum: 1 description: |- - Include the log probabilities on the `logprobs` most likely 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. - default: null - echo: - type: boolean - nullable: true - description: Echo back the prompt in addition to the completion - default: false - best_of: - type: integer - format: int64 - nullable: true + 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 + CreateTranslationResponse: + type: object + required: + - text + properties: + text: + type: string + description: The translated text for the provided audio data. + task: + type: string + enum: + - translate + description: The label that describes which operation type generated the accompanying response data. + language: + type: string + description: The spoken language that was detected in the audio data. + duration: + type: number + format: double + description: The total duration of the audio processed to produce accompanying translation information. + segments: + type: array + items: + $ref: '#/components/schemas/AudioSegment' 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`. - default: 1 - CreateCompletionResponse: + A collection of information about the timing, probabilities, and other detail of each processed + audio segment. + DeleteAssistantFileResponse: type: object + required: + - id + - deleted + - object + properties: + id: + type: string + deleted: + type: boolean + object: + type: string + enum: + - assistant.file.deleted 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). + Deletes the association between the assistant and the file, but does not delete the + [File](/docs/api-reference/files) object itself. + DeleteAssistantResponse: + type: object + required: + - id + - deleted + - object + properties: + id: + type: string + deleted: + type: boolean + object: + type: string + enum: + - assistant.deleted + DeleteFileResponse: + type: object required: - id - object - - created - - model - - choices + - deleted properties: id: type: string - description: A unique identifier for the completion. object: type: string - description: The object type, which is always `text_completion`. - created: - type: integer - format: unixtime - description: The Unix timestamp (in seconds) of when the completion was created. - model: - type: string - description: The model used for the completion. - choices: - type: array - items: - type: object - required: - - index - - text - - logprobs - - finish_reason - properties: - index: - type: integer - format: int64 - text: - type: string - logprobs: - type: object - required: - - tokens - - token_logprobs - - top_logprobs - - text_offset - properties: - tokens: - type: array - items: - type: string - token_logprobs: - type: array - items: - type: number - format: double - top_logprobs: - type: array - items: - type: object - additionalProperties: - type: integer - format: int64 - text_offset: - type: array - items: - type: integer - format: int64 - nullable: true - finish_reason: - type: string - enum: - - stop - - length - - content_filter - 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, or `content_filter` if content was omitted - due to a flag from our content filters, `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. - description: The list of completion choices the model generated for the input. - usage: - $ref: '#/components/schemas/CompletionUsage' - x-oaiMeta: - name: The completion object - legacy: true - example: '' - CreateEditRequest: + enum: + - file + deleted: + type: boolean + DeleteModelResponse: type: object required: - - model - - instruction + - id + - deleted + - object properties: - model: - anyOf: - - type: string - - type: string - enum: - - text-davinci-edit-001 - - code-davinci-edit-001 - description: |- - ID of the model to use. You can use the `text-davinci-edit-001` or `code-davinci-edit-001` - model with this endpoint. - x-oaiTypeLabel: string - input: + id: type: string - nullable: true - description: The input text to use as a starting point for the edit. - default: '' - instruction: + deleted: + type: boolean + object: type: string - description: The instruction that tells the model how to edit the prompt. - n: - oneOf: - - $ref: '#/components/schemas/EditN' - nullable: true - description: How many edits to generate for the input and instruction. - default: 1 - temperature: - oneOf: - - $ref: '#/components/schemas/Temperature' - nullable: true - 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. - default: 1 - top_p: - oneOf: - - $ref: '#/components/schemas/TopP' - nullable: true - 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. - default: 1 - CreateEditResponse: + enum: + - model + DeleteThreadResponse: type: object required: + - id + - deleted - object - - created - - choices - - usage properties: + id: + type: string + deleted: + type: boolean object: type: string enum: - - edit - description: The object type, which is always `edit`. - created: - type: integer - format: unixtime - description: The Unix timestamp (in seconds) of when the edit was created. - choices: - type: array - items: - type: object - required: - - text - - index - - finish_reason - properties: - text: - type: string - description: The edited result. - index: - type: integer - format: int64 - description: The index of the choice in the list of choices. - finish_reason: - type: string - enum: - - stop - - length - 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, or `length` if the maximum number of tokens - specified in the request was reached. - description: 'description: A list of edit choices. Can be more than one if `n` is greater than 1.' - usage: - $ref: '#/components/schemas/CompletionUsage' - CreateEmbeddingRequest: + - thread.deleted + Embedding: type: object required: - - model - - input + - index + - embedding + - object properties: - model: - anyOf: - - type: string - - type: string - enum: - - text-embedding-ada-002 - 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. - x-oaiTypeLabel: string - input: + index: + type: integer + format: int64 + description: The index of the embedding in the list of embeddings. + embedding: anyOf: - - type: string - type: array items: - type: string - - $ref: '#/components/schemas/TokenArray' - - $ref: '#/components/schemas/TokenArrayArray' + type: number + format: double + - type: string 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. Each input must not exceed - the max input tokens for the model (8191 tokens for `text-embedding-ada-002`) and cannot be an empty string. - [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) - for counting tokens. - user: - $ref: '#/components/schemas/User' - CreateEmbeddingResponse: + 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). + object: + type: string + enum: + - embedding + description: The object type, which is always "embedding". + description: Represents an embedding vector returned by embedding endpoint. + Error: + type: object + required: + - type + - message + - param + - code + properties: + type: + type: string + message: + type: string + param: + type: string + nullable: true + code: + type: string + nullable: true + ErrorResponse: + type: object + required: + - error + properties: + error: + $ref: '#/components/schemas/Error' + FineTune: type: object required: + - id - object + - created_at + - updated_at - model - - data - - usage + - fine_tuned_model + - organization_id + - status + - hyperparams + - training_files + - validation_files + - result_files properties: + id: + type: string + description: The object identifier, which can be referenced in the API endpoints. object: type: string enum: - - embedding - description: The object type, which is always "embedding". - model: - type: string - description: The name of the model used to generate the embedding. - data: - type: array - items: - $ref: '#/components/schemas/Embedding' - description: The list of embeddings generated by the model. - usage: + - fine-tune + - fine-tune-results + - assistants + - assistants_output + description: The object type, which is always "fine-tune". + created_at: + type: integer + format: unixtime + description: The Unix timestamp (in seconds) for when the fine-tuning job was created. + updated_at: + type: integer + format: unixtime + description: The Unix timestamp (in seconds) for when the fine-tuning job was last updated. + model: + type: string + description: The base model that is being fine-tuned. + fine_tuned_model: + type: string + nullable: true + description: The name of the fine-tuned model that is being created. + organization_id: + type: string + description: The organization that owns the fine-tuning job. + status: + type: string + enum: + - created + - pending + - running + - succeeded + - failed + - cancelled + - running + - succeeded + - failed + - cancelled + description: |- + The current status of the fine-tuning job, which can be either `created`, `running`, + `succeeded`, `failed`, or `cancelled`. + hyperparams: type: object - description: The usage information for the request. - required: - - prompt_tokens - - total_tokens properties: - prompt_tokens: + n_epochs: type: integer format: int64 - description: The number of tokens used by the prompt. - total_tokens: + description: |- + The number of epochs to train the model for. An epoch refers to one full cycle through the + training dataset. + batch_size: type: integer format: int64 - description: The total number of tokens used by the request. - CreateFileRequest: + description: |- + The batch size to use for training. The batch size is the number of training examples used to + train a single forward and backward pass. + prompt_loss_weight: + type: number + format: double + description: The weight to use for loss on the prompt tokens. + learning_rate_multiplier: + type: number + format: double + description: The learning rate multiplier to use for training. + compute_classification_metrics: + type: boolean + description: The classification metrics to compute using the validation dataset at the end of every epoch. + classification_positive_class: + type: string + description: The positive class to use for computing classification metrics. + classification_n_classes: + type: integer + format: int64 + description: The number of classes to use for computing classification metrics. + required: + - n_epochs + - batch_size + - prompt_loss_weight + - learning_rate_multiplier + description: |- + The hyperparameters used for the fine-tuning job. See the + [fine-tuning guide](/docs/guides/legacy-fine-tuning/hyperparameters) for more details. + training_files: + type: array + items: + $ref: '#/components/schemas/OpenAIFile' + description: The list of files used for training. + validation_files: + type: array + items: + $ref: '#/components/schemas/OpenAIFile' + description: The list of files used for validation. + result_files: + type: array + items: + $ref: '#/components/schemas/OpenAIFile' + description: The compiled results files for the fine-tuning job. + events: + type: array + items: + $ref: '#/components/schemas/FineTuneEvent' + description: The list of events that have been observed in the lifecycle of the FineTune job. + description: The `FineTune` object represents a legacy fine-tune job that has been created through the API. + deprecated: true + FineTuneEvent: type: object required: - - file - - purpose + - object + - created_at + - level + - message properties: - file: + object: type: string - format: binary - description: |- - Name of the [JSON Lines](https://jsonlines.readthedocs.io/en/latest/) file to be uploaded. - - If the `purpose` is set to "fine-tune", the file will be used for fine-tuning. - purpose: + created_at: + type: integer + format: unixtime + level: type: string - description: |- - The intended purpose of the uploaded documents. Use "fine-tune" for - [fine-tuning](/docs/api-reference/fine-tuning). This allows us to validate the format of the - uploaded file. - CreateFineTuneRequest: + message: + type: string + FineTuningEvent: type: object required: - - training_file + - object + - created_at + - level + - message properties: - training_file: - type: string - description: |- - The ID of an uploaded file that contains training data. - - See [upload file](/docs/api-reference/files/upload) for how to upload a file. - - Your dataset must be formatted as a JSONL file, where each training example is a JSON object - with the keys "prompt" and "completion". Additionally, you must upload your file with the - purpose `fine-tune`. - - See the [fine-tuning guide](/docs/guides/legacy-fine-tuning/creating-training-data) for more - details. - validation_file: + object: type: string - nullable: true - 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](/docs/guides/legacy-fine-tuning/analyzing-your-fine-tuned-model). - Your train and validation data should be mutually exclusive. - - Your dataset must be formatted as a JSONL file, where each validation example is a JSON object - with the keys "prompt" and "completion". Additionally, you must upload your file with the - purpose `fine-tune`. - - See the [fine-tuning guide](/docs/guides/legacy-fine-tuning/creating-training-data) for more - details. - model: - anyOf: - - type: string - - type: string - enum: - - ada - - babbage - - curie - - davinci - nullable: true - description: |- - The name of the base model to fine-tune. You can select one of "ada", "babbage", "curie", - "davinci", or a fine-tuned model created after 2022-04-21 and before 2023-08-22. To learn more - about these models, see the [Models](/docs/models) documentation. - x-oaiTypeLabel: string - n_epochs: - type: integer - format: int64 - nullable: true - description: |- - The number of epochs to train the model for. An epoch refers to one full cycle through the - training dataset. - default: 4 - batch_size: - type: integer - format: int64 - nullable: true - description: |- - The batch size to use for training. The batch size is the number of training examples used to - train a single forward and backward pass. - - By default, the batch size will be dynamically configured to be ~0.2% of the number of examples - in the training set, capped at 256 - in general, we've found that larger batch sizes tend to - work better for larger datasets. - default: null - learning_rate_multiplier: - type: number - format: double - nullable: true - description: |- - The learning rate multiplier to use for training. The fine-tuning learning rate is the original - learning rate used for pretraining multiplied by this value. - - By default, the learning rate multiplier is the 0.05, 0.1, or 0.2 depending on final - `batch_size` (larger learning rates tend to perform better with larger batch sizes). We - recommend experimenting with values in the range 0.02 to 0.2 to see what produces the best - results. - default: null - prompt_loss_rate: - type: number - format: double - nullable: true - description: |- - The weight to use for loss on the prompt tokens. This controls how much the model tries to - learn to generate the prompt (as compared to the completion which always has a weight of 1.0), - and can add a stabilizing effect to training when completions are short. - - If prompts are extremely long (relative to completions), it may make sense to reduce this - weight so as to avoid over-prioritizing learning the prompt. - default: 0.01 - compute_classification_metrics: - type: boolean - nullable: true - description: |- - If set, we calculate classification-specific metrics such as accuracy and F-1 score using the - validation set at the end of every epoch. These metrics can be viewed in the - [results file](/docs/guides/legacy-fine-tuning/analyzing-your-fine-tuned-model). - - In order to compute classification metrics, you must provide a `validation_file`. Additionally, - you must specify `classification_n_classes` for multiclass classification or - `classification_positive_class` for binary classification. - default: false - classification_n_classes: + created_at: type: integer - format: int64 - nullable: true - description: |- - The number of classes in a classification task. - - This parameter is required for multiclass classification. - default: null - classification_positive_class: + format: unixtime + level: type: string + message: + type: string + data: + type: object + additionalProperties: {} nullable: true - description: |- - The positive class in binary classification. - - This parameter is needed to generate precision, recall, and F1 metrics when doing binary - classification. - default: null - classification_betas: - type: array - items: - type: number - format: double - nullable: true - description: |- - If this is provided, we calculate F-beta scores at the specified beta values. The F-beta score - is a generalization of F-1 score. This is only used for binary classification. - - With a beta of 1 (i.e. the F-1 score), precision and recall are given the same weight. A larger - beta score puts more weight on recall and less on precision. A smaller beta score puts more - weight on precision and less on recall. - default: null - suffix: - oneOf: - - $ref: '#/components/schemas/SuffixString' - nullable: true - 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 - `ada:ft-your-org:custom-model-name-2022-02-15-04-21-04`. - default: null - CreateFineTuningJobRequest: + type: + type: string + enum: + - message + - metrics + FineTuningJob: type: object required: - - training_file + - id + - object + - created_at + - finished_at - model + - fine_tuned_model + - organization_id + - status + - hyperparameters + - training_file + - validation_file + - result_files + - trained_tokens + - error properties: - training_file: + id: type: string - description: |- - The ID of an uploaded file that contains training data. - - See [upload file](/docs/api-reference/files/upload) 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`. - - See the [fine-tuning guide](/docs/guides/fine-tuning) for more details. - validation_file: + description: The object identifier, which can be referenced in the API endpoints. + object: + type: string + enum: + - fine_tuning.job + description: The object type, which is always "fine_tuning.job". + created_at: + type: integer + format: unixtime + description: The Unix timestamp (in seconds) for when the fine-tuning job was created. + finished_at: type: string + format: date-time nullable: true 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. + 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. model: - anyOf: - - type: string - - type: string - enum: - - babbage-002 - - davinci-002 - - gpt-3.5-turbo + type: string + description: The base model that is being fine-tuned. + fine_tuned_model: + type: string + nullable: true 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). - x-oaiTypeLabel: string + The name of the fine-tuned model that is being created. The value will be null if the + fine-tuning job is still running. + organization_id: + type: string + description: The organization that owns the fine-tuning job. + status: + type: string + enum: + - created + - pending + - running + - succeeded + - failed + - cancelled + - running + - succeeded + - failed + - cancelled + description: |- + The current status of the fine-tuning job, which can be either `created`, `pending`, `running`, + `succeeded`, `failed`, or `cancelled`. hyperparameters: type: object - description: The hyperparameters used for the fine-tuning job. properties: n_epochs: anyOf: - type: string enum: - auto + - low + - high - $ref: '#/components/schemas/NEpochs' 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. default: auto - suffix: - oneOf: - - $ref: '#/components/schemas/SuffixString' + description: |- + The hyperparameters used for the fine-tuning job. See the + [fine-tuning guide](/docs/guides/fine-tuning) for more details. + 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: |- - 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`. - default: null - CreateImageEditRequest: + The file ID used for validation. You can retrieve the validation results with the + [Files API](/docs/api-reference/files/retrieve-contents). + result_files: + type: array + items: + type: string + 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). + trained_tokens: + type: integer + format: int64 + 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. + error: + type: object + properties: + message: + type: string + description: A human-readable error message. + code: + type: string + description: A machine-readable error code. + param: + type: string + nullable: true + 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 + description: |- + For fine-tuning jobs that have `failed`, this will contain more information on the cause of the + failure. + FineTuningJobEvent: type: object required: - - prompt - - image + - id + - object + - created_at + - level + - message properties: - prompt: + id: type: string - description: A text description of the desired image(s). The maximum length is 1000 characters. - image: + object: + type: string + created_at: + type: integer + format: unixtime + level: + type: string + enum: + - info + - warn + - error + message: + type: string + FunctionObject: + type: object + required: + - name + properties: + description: type: string - format: binary 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. - mask: + A description of what the function does, used by the model to choose when and how to call the + function. + name: type: string - format: binary 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`. - n: - oneOf: - - $ref: '#/components/schemas/ImagesN' - nullable: true - description: The number of images to generate. Must be between 1 and 10. - default: 1 - size: + 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' + FunctionParameters: + type: object + additionalProperties: {} + description: |- + The parameters the functions accepts, described as a JSON Schema object. See the + [guide](/docs/guides/gpt/function-calling) for examples, and the + [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation + about the format.\n\nTo describe a function that accepts no parameters, provide the value + `{\"type\": \"object\", \"properties\": {}}`. + Image: + type: object + properties: + b64_json: type: string - enum: - - 256x256 - - 512x512 - - 1024x1024 - nullable: true - description: The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. - default: 1024x1024 - response_format: + format: base64 + description: The base64-encoded JSON of the generated image, if `response_format` is `b64_json`. + url: type: string - enum: - - url - - b64_json - nullable: true - description: The format in which the generated images are returned. Must be one of `url` or `b64_json`. - default: url - user: - $ref: '#/components/schemas/User' - CreateImageRequest: + format: uri + 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. + description: Represents the url or the content of an image generated by the OpenAI API. + ImagesN: + type: integer + format: int64 + minimum: 1 + maximum: 10 + ImagesResponse: + type: object + required: + - created + - data + properties: + created: + type: integer + format: unixtime + data: + type: array + items: + $ref: '#/components/schemas/Image' + ListAssistantFilesResponse: type: object required: - - prompt + - object + - data + - first_id + - last_id + - has_more properties: - prompt: - type: string - description: A text description of the desired image(s). The maximum length is 1000 characters. - n: - oneOf: - - $ref: '#/components/schemas/ImagesN' - nullable: true - description: The number of images to generate. Must be between 1 and 10. - default: 1 - size: + object: type: string enum: - - 256x256 - - 512x512 - - 1024x1024 - nullable: true - description: The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. - default: 1024x1024 - response_format: + - list + data: + type: array + items: + $ref: '#/components/schemas/AssistantFileObject' + first_id: type: string - enum: - - url - - b64_json - nullable: true - description: The format in which the generated images are returned. Must be one of `url` or `b64_json`. - default: url - user: - $ref: '#/components/schemas/User' - CreateImageVariationRequest: + last_id: + type: string + has_more: + type: boolean + ListAssistantsResponse: type: object required: - - image + - object + - data + - first_id + - last_id + - has_more properties: - image: - type: string - format: binary - description: |- - The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, - and square. - n: - oneOf: - - $ref: '#/components/schemas/ImagesN' - nullable: true - description: The number of images to generate. Must be between 1 and 10. - default: 1 - size: + object: type: string enum: - - 256x256 - - 512x512 - - 1024x1024 - nullable: true - description: The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. - default: 1024x1024 - response_format: + - list + data: + type: array + items: + $ref: '#/components/schemas/AssistantObject' + first_id: type: string - enum: - - url - - b64_json - nullable: true - description: The format in which the generated images are returned. Must be one of `url` or `b64_json`. - default: url - user: - $ref: '#/components/schemas/User' - CreateModerationRequest: + last_id: + type: string + has_more: + type: boolean + ListFilesResponse: type: object required: - - input + - data + - object properties: - input: - anyOf: - - type: string - - type: array - items: - type: string - description: The input text to classify - model: - anyOf: - - type: string - - type: string - enum: - - text-moderation-latest - - text-moderation-stable - 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`. - x-oaiTypeLabel: string - default: text-moderation-latest - CreateModerationResponse: + data: + type: array + items: + $ref: '#/components/schemas/OpenAIFile' + object: + type: string + enum: + - list + ListFineTuneEventsResponse: type: object required: - - id - - model - - results + - object + - data properties: - id: - type: string - description: The unique identifier for the moderation request. - model: + object: type: string - description: The model used to generate the moderation results. - results: + data: type: array items: - type: object - required: - - flagged - - categories - - category_scores - properties: - flagged: - type: boolean - description: Whether the content violates [OpenAI's usage policies](/policies/usage-policies). - categories: - type: object - description: A list of the categories, and whether they are flagged or not. - required: - - hate - - hate/threatening - - harassment - - harassment/threatening - - self-harm - - self-harm/intent - - self-harm/instructive - - sexual - - sexual/minors - - violence - - violence/graphic - 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 harrassment. - 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/instructive: - 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. - category_scores: - type: object - description: A list of the categories along with their scores as predicted by model. - required: - - hate - - hate/threatening - - harassment - - harassment/threatening - - self-harm - - self-harm/intent - - self-harm/instructive - - sexual - - sexual/minors - - violence - - violence/graphic - properties: - hate: - type: number - format: double - description: The score for the category 'hate'. - hate/threatening: - type: number - format: double - description: The score for the category 'hate/threatening'. - harassment: - type: number - format: double - description: The score for the category 'harassment'. - harassment/threatening: - type: number - format: double - description: The score for the category 'harassment/threatening'. - self-harm: - type: number - format: double - description: The score for the category 'self-harm'. - self-harm/intent: - type: number - format: double - description: The score for the category 'self-harm/intent'. - self-harm/instructive: - type: number - format: double - description: The score for the category 'self-harm/instructive'. - sexual: - type: number - format: double - description: The score for the category 'sexual'. - sexual/minors: - type: number - format: double - description: The score for the category 'sexual/minors'. - violence: - type: number - format: double - description: The score for the category 'violence'. - violence/graphic: - type: number - format: double - description: The score for the category 'violence/graphic'. - description: A list of moderation objects. - CreateTranscriptionRequest: + $ref: '#/components/schemas/FineTuneEvent' + ListFineTunesResponse: type: object required: - - file - - model + - object + - data properties: - file: + object: type: string - format: binary - 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. - x-oaiTypeLabel: file - model: - anyOf: - - type: string - - type: string - enum: - - whisper-1 - description: ID of the model to use. Only `whisper-1` is currently available. - x-oaiTypeLabel: string - prompt: + data: + type: array + items: + $ref: '#/components/schemas/FineTune' + ListFineTuningJobEventsResponse: + type: object + required: + - object + - data + properties: + object: 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. - response_format: + data: + type: array + items: + $ref: '#/components/schemas/FineTuningJobEvent' + ListMessageFilesResponse: + type: object + required: + - object + - data + - first_id + - last_id + - has_more + properties: + object: type: string enum: - - json - - text - - srt - - verbose_json - - vtt - description: |- - The format of the transcript output, in one of these options: json, text, srt, verbose_json, or - vtt. - default: json - temperature: - type: number - format: double - 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. - minimum: 0 - maximum: 1 - default: 0 - language: + - list + data: + type: array + items: + $ref: '#/components/schemas/MessageFileObject' + first_id: 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. - CreateTranscriptionResponse: + last_id: + type: string + has_more: + type: boolean + ListMessagesResponse: type: object required: - - text + - object + - data + - first_id + - last_id + - has_more properties: - text: + object: + type: string + enum: + - list + data: + type: array + items: + $ref: '#/components/schemas/MessageObject' + first_id: type: string - CreateTranslationRequest: + last_id: + type: string + has_more: + type: boolean + ListModelsResponse: type: object required: - - file - - model + - object + - data properties: - file: + object: type: string - format: binary - description: |- - The audio file object (not file name) to translate, in one of these formats: flac, mp3, mp4, - mpeg, mpga, m4a, ogg, wav, or webm. - x-oaiTypeLabel: file - model: - anyOf: - - type: string - - type: string - enum: - - whisper-1 - description: ID of the model to use. Only `whisper-1` is currently available. - x-oaiTypeLabel: string - prompt: + enum: + - list + data: + type: array + items: + $ref: '#/components/schemas/Model' + ListPaginatedFineTuningJobsResponse: + type: object + required: + - object + - data + - has_more + properties: + object: 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. - response_format: + data: + type: array + items: + $ref: '#/components/schemas/FineTuningJob' + has_more: + type: boolean + ListRunStepsResponse: + type: object + required: + - object + - data + - first_id + - last_id + - has_more + properties: + object: type: string enum: - - json - - text - - srt - - verbose_json - - vtt - description: |- - The format of the transcript output, in one of these options: json, text, srt, verbose_json, or - vtt. - default: json - temperature: - type: number - format: double - 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. - minimum: 0 - maximum: 1 - default: 0 - CreateTranslationResponse: + - list + data: + type: array + items: + $ref: '#/components/schemas/RunStepObject' + first_id: + type: string + last_id: + type: string + has_more: + type: boolean + ListRunsResponse: + type: object + required: + - object + - data + - first_id + - last_id + - has_more + properties: + object: + type: string + enum: + - list + data: + type: array + items: + $ref: '#/components/schemas/RunObject' + first_id: + type: string + last_id: + type: string + has_more: + type: boolean + MessageContentImageFileObject: + type: object + required: + - type + - image_file + properties: + type: + type: string + enum: + - image_file + description: Always `image_file`. + image_file: + type: object + properties: + file_id: + type: string + description: The [File](/docs/api-reference/files) ID of the image in the message content. + required: + - file_id + description: References an image [File](/docs/api-reference/files) in the content of a message. + MessageContentTextAnnotationsFileCitationObject: type: object required: + - type - text + - file_citation + - start_index + - end_index properties: + type: + type: string + enum: + - file_citation + description: Always `file_citation`. text: type: string - DeleteFileResponse: + description: The text in the message content that needs to be replaced. + file_citation: + type: object + properties: + file_id: + type: string + description: The ID of the specific File the citation is from. + quote: + type: string + description: The specific quote in the file. + required: + - file_id + - quote + start_index: + type: integer + format: int64 + minimum: 0 + end_index: + type: integer + format: int64 + minimum: 0 + 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 "retrieval" tool to + search files. + MessageContentTextAnnotationsFilePathObject: type: object required: - - id - - object - - deleted + - type + - text + - file_path + - start_index + - end_index properties: - id: + type: type: string - object: + enum: + - file_path + description: Always `file_path`. + text: type: string - deleted: - type: boolean - DeleteModelResponse: + description: The text in the message content that needs to be replaced. + file_path: + type: object + properties: + file_id: + type: string + description: The ID of the file that was generated. + required: + - file_id + start_index: + type: integer + format: int64 + minimum: 0 + end_index: + type: integer + format: int64 + minimum: 0 + description: |- + A URL for the file that's generated when the assistant used the `code_interpreter` tool to + generate a file. + MessageContentTextObject: + type: object + required: + - type + - text + properties: + type: + type: string + enum: + - text + - json_object + description: Always `text`. + text: + type: object + properties: + value: + type: string + description: The data that makes up the text. + annotations: + type: array + items: + $ref: '#/components/schemas/MessageContentTextObjectAnnotations' + required: + - value + - annotations + description: The text content that is part of a message. + MessageContentTextObjectAnnotations: + oneOf: + - $ref: '#/components/schemas/MessageContentTextAnnotationsFileCitationObject' + - $ref: '#/components/schemas/MessageContentTextAnnotationsFilePathObject' + x-oaiExpandable: true + MessageFileObject: type: object required: - id - object - - deleted + - created_at + - message_id properties: id: type: string + description: TThe identifier, which can be referenced in API endpoints. object: type: string - deleted: - type: boolean - EditN: - type: integer - format: int64 - minimum: 0 - maximum: 20 - Embedding: + enum: + - thread.message.file + description: The object type, which is always `thread.message.file`. + created_at: + type: integer + format: unixtime + description: The Unix timestamp (in seconds) for when the message file was created. + message_id: + type: string + description: The ID of the [message](/docs/api-reference/messages) that the [File](/docs/api-reference/files) is attached to. + description: A list of files attached to a `message`. + MessageObject: type: object - description: Represents an embedding vector returned by embedding endpoint. required: - - index + - id - object - - embedding + - created_at + - thread_id + - role + - content + - assistant_id + - run_id + - file_ids + - metadata properties: - index: - type: integer - format: int64 - description: The index of the embedding in the list of embeddings. + id: + type: string + description: The identifier, which can be referenced in API endpoints. object: type: string enum: - - embedding - description: The object type, which is always "embedding". - embedding: - type: array - items: - type: number - format: double - 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). - Error: - type: object - required: - - type - - message - - param - - code - properties: - type: + - thread.message + description: The object type, which is always `thread.message`. + created_at: + type: integer + format: unixtime + description: The Unix timestamp (in seconds) for when the message was created. + thread_id: type: string - message: + description: The [thread](/docs/api-reference/threads) ID that this message belongs to. + role: type: string - param: + enum: + - user + - assistant + description: The entity that produced the message. One of `user` or `assistant`. + content: + type: array + items: + $ref: '#/components/schemas/MessageObjectContent' + description: The content of the message in array of text and/or images. + assistant_id: type: string nullable: true - code: + description: |- + If applicable, the ID of the [assistant](/docs/api-reference/assistants) that authored this + message. + run_id: type: string nullable: true - ErrorResponse: - type: object - required: - - error - properties: - error: - $ref: '#/components/schemas/Error' - FineTune: + description: |- + If applicable, the ID of the [run](/docs/api-reference/runs) associated with the authoring of + this message. + file_ids: + type: array + items: + type: string + maxItems: 10 + description: |- + A list of [file](/docs/api-reference/files) IDs that the assistant should use. Useful for + tools like retrieval and code_interpreter that can access files. A maximum of 10 files can be + attached to a message. + default: [] + metadata: + type: object + additionalProperties: + type: string + nullable: true + 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. + x-oaiTypeLabel: map + MessageObjectContent: + oneOf: + - $ref: '#/components/schemas/MessageContentImageFileObject' + - $ref: '#/components/schemas/MessageContentTextObject' + x-oaiExpandable: true + Model: type: object - description: The `FineTune` object represents a legacy fine-tune job that has been created through the API. required: - id + - created - object - - created_at - - updated_at - - model - - fine_tuned_model - - organization_id - - status - - hyperparams - - training_files - - validation_files - - result_files + - owned_by properties: id: type: string - description: The object identifier, which can be referenced in the API endpoints. + description: The model identifier, which can be referenced in the API endpoints. + created: + type: integer + format: unixtime + description: The Unix timestamp (in seconds) when the model was created. object: type: string enum: - - fine-tune - description: The object type, which is always "fine-tune". - created_at: - type: integer - format: unixtime - description: The Unix timestamp (in seconds) for when the fine-tuning job was created. - updated_at: - type: integer - format: unixtime - description: The Unix timestamp (in seconds) for when the fine-tuning job was last updated. + - model + description: The object type, which is always "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. + ModifyAssistantRequest: + type: object + properties: model: type: string - description: The base model that is being fine-tuned. - fine_tuned_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. + name: type: string nullable: true - description: The name of the fine-tuned model that is being created. - organization_id: + maxLength: 256 + description: The name of the assistant. The maximum length is 256 characters. + description: type: string - description: The organization that owns the fine-tuning job. - status: + nullable: true + maxLength: 512 + description: The description of the assistant. The maximum length is 512 characters. + instructions: type: string - enum: - - created - - running - - succeeded - - failed - - cancelled - description: |- - The current status of the fine-tuning job, which can be either `created`, `running`, - `succeeded`, `failed`, or `cancelled`. - hyperparams: - type: object + nullable: true + maxLength: 32768 + description: The system instructions that the assistant uses. The maximum length is 32768 characters. + tools: + allOf: + - $ref: '#/components/schemas/CreateAssistantRequestToolsItem' description: |- - The hyperparameters used for the fine-tuning job. See the - [fine-tuning guide](/docs/guides/legacy-fine-tuning/hyperparameters) for more details. - required: - - n_epochs - - batch_size - - prompt_loss_weight - - learning_rate_multiplier - properties: - n_epochs: - type: integer - format: int64 - description: |- - The number of epochs to train the model for. An epoch refers to one full cycle through the - training dataset. - batch_size: - type: integer - format: int64 - description: |- - The batch size to use for training. The batch size is the number of training examples used to - train a single forward and backward pass. - prompt_loss_weight: - type: number - format: double - description: The weight to use for loss on the prompt tokens. - learning_rate_multiplier: - type: number - format: double - description: The learning rate multiplier to use for training. - compute_classification_metrics: - type: boolean - description: The classification metrics to compute using the validation dataset at the end of every epoch. - classification_positive_class: - type: string - description: The positive class to use for computing classification metrics. - classification_n_classes: - type: integer - format: int64 - description: The number of classes to use for computing classification metrics. - training_files: - type: array - items: - $ref: '#/components/schemas/OpenAIFile' - description: The list of files used for training. - validation_files: - type: array - items: - $ref: '#/components/schemas/OpenAIFile' - description: The list of files used for validation. - result_files: - type: array - items: - $ref: '#/components/schemas/OpenAIFile' - description: The compiled results files for the fine-tuning job. - events: + 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`, `retrieval`, or `function`. + default: [] + file_ids: type: array items: - $ref: '#/components/schemas/FineTuneEvent' - description: The list of events that have been observed in the lifecycle of the FineTune job. - FineTuneEvent: + type: string + maxItems: 20 + description: |- + A list of [file](/docs/api-reference/files) IDs attached to this assistant. There can be a + maximum of 20 files attached to the assistant. Files are ordered by their creation date in + ascending order. + default: [] + metadata: + type: object + additionalProperties: + type: string + nullable: true + 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. + x-oaiTypeLabel: map + ModifyMessageRequest: type: object - required: - - object - - created_at - - level - - message properties: - object: - type: string - created_at: - type: integer - format: unixtime - level: - type: string - message: - type: string - FineTuningEvent: + metadata: + type: object + additionalProperties: + type: string + nullable: true + 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. + x-oaiTypeLabel: map + ModifyRunRequest: + type: object + properties: + metadata: + type: object + additionalProperties: + type: string + nullable: true + 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. + x-oaiTypeLabel: map + ModifyThreadRequest: + type: object + properties: + metadata: + type: object + additionalProperties: + type: string + nullable: true + 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. + NEpochs: + type: integer + format: int64 + minimum: 1 + maximum: 50 + OpenAIFile: type: object required: - - object + - id + - bytes - created_at - - level - - message + - filename + - object + - purpose + - status properties: - object: + id: type: string + description: The file identifier, which can be referenced in the API endpoints. + bytes: + type: integer + format: int64 + description: The size of the file, in bytes. created_at: type: integer format: unixtime - level: + description: The Unix timestamp (in seconds) for when the file was created. + filename: type: string - message: + description: The name of the file. + object: type: string - data: - type: object - additionalProperties: {} - nullable: true - type: + enum: + - file + description: The object type, which is always "file". + purpose: type: string enum: - - message - - metrics - FineTuningJob: + - fine-tune + - fine-tune-results + - assistants + - assistants_output + description: |- + The intended purpose of the file. Supported values are `fine-tune`, `fine-tune-results`, + `assistants`, and `assistants_output`. + status: + type: string + enum: + - uploaded + - processed + - error + description: |- + Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or + `error`. + deprecated: true + 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`. + deprecated: true + description: The `File` object represents a document that has been uploaded to OpenAI. + Prompt: + oneOf: + - type: string + - type: array + items: + type: string + - $ref: '#/components/schemas/TokenArrayItem' + - $ref: '#/components/schemas/TokenArrayArray' + RunCompletionUsage: + type: object + required: + - completion_tokens + - prompt_tokens + - total_tokens + properties: + completion_tokens: + type: integer + format: int64 + description: Number of completion tokens used over the course of the run. + prompt_tokens: + type: integer + format: int64 + description: Number of prompt tokens used over the course of the run. + total_tokens: + type: integer + format: int64 + description: Total number of tokens used (prompt + completion). + 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.). + RunObject: type: object required: - id - object - created_at - - finished_at - - model - - fine_tuned_model - - organization_id + - thread_id + - assistant_id - status - - hyperparameters - - training_file - - validation_file - - result_files - - trained_tokens - - error + - required_action + - last_error + - expires_at + - started_at + - cancelled_at + - failed_at + - completed_at + - model + - instructions + - tools + - file_ids + - metadata + - usage properties: id: type: string - description: The object identifier, which can be referenced in the API endpoints. + description: The identifier, which can be referenced in API endpoints. object: type: string enum: - - fine_tuning.job - description: The object type, which is always "fine_tuning.job". + - thread.run + description: The object type, which is always `thread.run`. created_at: type: integer format: unixtime - description: The Unix timestamp (in seconds) for when the fine-tuning job was created. - finished_at: - type: string - format: date-time - 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. - model: - type: string - description: The base model that is being fine-tuned. - fine_tuned_model: + description: The Unix timestamp (in seconds) for when the run was created. + thread_id: 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. - organization_id: + The ID of the [thread](/docs/api-reference/threads) that was executed on as a part of this + run. + assistant_id: type: string - description: The organization that owns the fine-tuning job. + description: The ID of the [assistant](/docs/api-reference/assistants) used for execution of this run. status: type: string enum: - - created - - pending - - running - - succeeded - - failed + - queued + - in_progress + - requires_action + - cancelling - cancelled + - failed + - completed + - expired description: |- - The current status of the fine-tuning job, which can be either `created`, `pending`, `running`, - `succeeded`, `failed`, or `cancelled`. - hyperparameters: + The status of the run, which can be either `queued`, `in_progress`, `requires_action`, + `cancelling`, `cancelled`, `failed`, `completed`, or `expired`. + required_action: 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: - anyOf: - - type: string - enum: - - auto - - $ref: '#/components/schemas/NEpochs' - 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. - default: auto - 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). - result_files: - type: array - items: - type: string - 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). - trained_tokens: - type: integer - format: int64 + type: + type: string + enum: + - submit_tool_outputs + description: For now, this is always `submit_tool_outputs`. + submit_tool_outputs: + type: object + properties: + tool_calls: + type: array + items: + $ref: '#/components/schemas/RunToolCallObject' + description: A list of the relevant tool calls. + required: + - tool_calls + description: Details on the tool outputs needed for this run to continue. + required: + - type + - submit_tool_outputs 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. - error: + Details on the action required to continue the run. Will be `null` if no action is + required. + last_error: type: object - description: |- - For fine-tuning jobs that have `failed`, this will contain more information on the cause of the - failure. properties: - message: - type: string - description: A human-readable error message. code: type: string - description: A machine-readable error code. - param: + enum: + - server_error + - rate_limit_exceeded + description: One of `server_error` or `rate_limit_exceeded`. + message: type: string - nullable: true - description: |- - The parameter that was invalid, usually `training_file` or `validation_file`. This field - will be null if the failure was not parameter-specific. + description: A human-readable description of the error. + required: + - code + - message nullable: true - FineTuningJobEvent: - type: object - required: - - id - - object - - created_at - - level - - message - properties: - id: - type: string - object: - type: string - created_at: + description: The last error associated with this run. Will be `null` if there are no errors. + expires_at: type: integer format: unixtime - level: + description: The Unix timestamp (in seconds) for when the run will expire. + started_at: type: string - enum: - - info - - warn - - error - message: + format: date-time + nullable: true + description: The Unix timestamp (in seconds) for when the run was started. + cancelled_at: type: string - Image: - type: object - description: Represents the url or the content of an image generated by the OpenAI API. - properties: - url: + format: date-time + nullable: true + description: The Unix timestamp (in seconds) for when the run was cancelled. + failed_at: type: string - format: uri - description: The URL of the generated image, if `response_format` is `url` (default). - b64_json: + format: date-time + nullable: true + description: The Unix timestamp (in seconds) for when the run failed. + completed_at: type: string - format: base64 - description: The base64-encoded JSON of the generated image, if `response_format` is `b64_json`. - ImagesN: - type: integer - format: int64 - minimum: 1 - maximum: 10 - ImagesResponse: + format: date-time + nullable: true + description: The Unix timestamp (in seconds) for when the run was completed. + model: + type: string + description: The model that the [assistant](/docs/api-reference/assistants) used for this run. + instructions: + type: string + description: The instructions that the [assistant](/docs/api-reference/assistants) used for this run. + tools: + allOf: + - $ref: '#/components/schemas/CreateRunRequestToolsItem' + description: The list of tools that the [assistant](/docs/api-reference/assistants) used for this run. + file_ids: + type: array + items: + type: string + description: |- + The list of [File](/docs/api-reference/files) IDs the + [assistant](/docs/api-reference/assistants) used for this run. + default: [] + metadata: + type: object + additionalProperties: + type: string + nullable: true + 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. + x-oaiTypeLabel: map + usage: + type: object + allOf: + - $ref: '#/components/schemas/RunCompletionUsage' + nullable: true + description: Represents an execution run on a [thread](/docs/api-reference/threads). + RunStepCompletionUsage: type: object required: - - created - - data + - completion_tokens + - prompt_tokens + - total_tokens properties: - created: + completion_tokens: type: integer - format: unixtime - data: - type: array - items: - $ref: '#/components/schemas/Image' - ListFilesResponse: + format: int64 + description: Number of completion tokens used over the course of the run step. + prompt_tokens: + type: integer + format: int64 + description: Number of prompt tokens used over the course of the run step. + total_tokens: + type: integer + format: int64 + description: Total number of tokens used (prompt + completion). + description: |- + Usage statistics related to the run step. This value will be `null` while the run step's status + is `in_progress`. + RunStepDetails: + oneOf: + - $ref: '#/components/schemas/RunStepDetailsMessageCreationObject' + - $ref: '#/components/schemas/RunStepDetailsToolCallsObject' + x-oaiExpandable: true + RunStepDetailsMessageCreationObject: type: object required: - - object - - data - properties: - object: - type: string - data: - type: array - items: - $ref: '#/components/schemas/OpenAIFile' - ListFineTuneEventsResponse: + - type + - message_creation + properties: + type: + type: string + enum: + - message_creation + description: Details of the message creation by the run step. + 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 + description: Details of the message creation by the run step. + RunStepDetailsToolCallsCodeObject: type: object required: - - object - - data + - id + - type + - code_interpreter properties: - object: + id: type: string - data: - type: array - items: - $ref: '#/components/schemas/FineTuneEvent' - ListFineTunesResponse: + description: The ID of the tool call. + type: + type: string + enum: + - code_interpreter + description: |- + The type of tool call. This is always going to be `code_interpreter` for this type of tool + call. + code_interpreter: + type: object + properties: + input: + type: string + description: The input to the Code Interpreter tool call. + outputs: + allOf: + - $ref: '#/components/schemas/RunStepDetailsToolCallsCodeOutputs' + 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. + required: + - input + - outputs + description: The Code Interpreter tool call definition. + description: Details of the Code Interpreter tool call the run step was involved in. + RunStepDetailsToolCallsCodeOutput: + oneOf: + - $ref: '#/components/schemas/RunStepDetailsToolCallsCodeOutputLogsObject' + - $ref: '#/components/schemas/RunStepDetailsToolCallsCodeOutputImageObject' + x-oaiExpandable: true + RunStepDetailsToolCallsCodeOutputImageObject: type: object required: - - object - - data + - type + - image properties: - object: + type: type: string - data: - type: array - items: - $ref: '#/components/schemas/FineTune' - ListFineTuningJobEventsResponse: + enum: + - image + description: Always `image`. + image: + type: object + properties: + file_id: + type: string + description: The [file](/docs/api-reference/files) ID of the image. + required: + - file_id + RunStepDetailsToolCallsCodeOutputLogsObject: type: object required: - - object - - data + - type + - logs properties: - object: + type: type: string - data: - type: array - items: - $ref: '#/components/schemas/FineTuningJobEvent' - ListModelsResponse: + enum: + - logs + description: Always `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. + RunStepDetailsToolCallsCodeOutputs: + type: array + items: + $ref: '#/components/schemas/RunStepDetailsToolCallsCodeOutput' + RunStepDetailsToolCallsFunctionObject: type: object required: - - object - - data + - id + - type + - function properties: - object: + id: type: string - data: - type: array - items: - $ref: '#/components/schemas/Model' - ListPaginatedFineTuningJobsResponse: + description: The ID of the tool call object. + type: + type: string + enum: + - function + description: The type of tool call. This is always going to be `function` for this type of tool call. + function: + type: object + properties: + name: + type: string + description: The name of the function. + arguments: + type: string + description: The arguments passed to the function. + output: + type: string + nullable: true + description: |- + The output of the function. This will be `null` if the outputs have not been + [submitted](/docs/api-reference/runs/submitToolOutputs) yet. + required: + - name + - arguments + - output + description: The definition of the function that was called. + RunStepDetailsToolCallsObject: type: object required: - - object - - data - - has_more + - type + - tool_calls properties: - object: + type: type: string - data: - type: array - items: - $ref: '#/components/schemas/FineTuningJob' - has_more: - type: boolean - MaxTokens: - type: integer - format: int64 - minimum: 0 - Model: + enum: + - tool_calls + description: Always `tool_calls`. + tool_calls: + allOf: + - $ref: '#/components/schemas/RunStepDetailsToolCallsObjectToolCallsItem' + 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`, `retrieval`, or `function`. + description: Details of the tool call. + RunStepDetailsToolCallsObjectToolCall: + oneOf: + - $ref: '#/components/schemas/RunStepDetailsToolCallsCodeObject' + - $ref: '#/components/schemas/RunStepDetailsToolCallsRetrievalObject' + - $ref: '#/components/schemas/RunStepDetailsToolCallsFunctionObject' + x-oaiExpandable: true + RunStepDetailsToolCallsObjectToolCallsItem: + type: array + items: + $ref: '#/components/schemas/RunStepDetailsToolCallsObjectToolCall' + RunStepDetailsToolCallsRetrievalObject: type: object - description: Describes an OpenAI model offering that can be used with the API. required: - id - - object - - created - - owned_by + - type + - retrieval properties: id: type: string - description: The model identifier, which can be referenced in the API endpoints. - object: + description: The ID of the tool call object. + type: type: string enum: - - model - description: The object type, which is always "model". - created: - type: integer - format: unixtime - description: The Unix timestamp (in seconds) when the model was created. - owned_by: - type: string - description: The organization that owns the model. - N: - type: integer - format: int64 - minimum: 1 - maximum: 128 - NEpochs: - type: integer - format: int64 - minimum: 1 - maximum: 50 - OpenAIFile: + - retrieval + description: The type of tool call. This is always going to be `retrieval` for this type of tool call. + retrieval: + type: object + description: For now, this is always going to be an empty object. + x-oaiTypeLabel: map + RunStepObject: type: object - description: The `File` object represents a document that has been uploaded to OpenAI. required: - id - object - - bytes - - createdAt - - filename - - purpose + - created_at + - assistant_id + - thread_id + - run_id + - type - status + - step_details + - last_error + - expires_at + - cancelled_at + - failed_at + - completed_at + - metadata + - usage properties: id: type: string - description: The file identifier, which can be referenced in the API endpoints. + description: The identifier of the run step, which can be referenced in API endpoints. object: type: string enum: - - file - description: The object type, which is always "file". - bytes: - type: integer - format: int64 - description: The size of the file in bytes. - createdAt: + - thread.run.step + description: The object type, which is always `thread.run.step`. + created_at: type: integer format: unixtime - description: The Unix timestamp (in seconds) for when the file was created. - filename: + description: The Unix timestamp (in seconds) for when the run step was created. + assistant_id: type: string - description: The name of the file. - purpose: + description: The ID of the [assistant](/docs/api-reference/assistants) associated with the run step. + thread_id: + type: string + description: The ID of the [thread](/docs/api-reference/threads) that was run. + run_id: + type: string + description: The ID of the [run](/docs/api-reference/runs) that this run step is a part of. + type: type: string - description: The intended purpose of the file. Currently, only "fine-tune" is supported. + enum: + - message_creation + - tool_calls + description: The type of run step, which can be either `message_creation` or `tool_calls`. status: type: string enum: - - uploaded - - processed - - pending - - error - - deleting - - deleted + - in_progress + - cancelled + - failed + - completed + - expired description: |- - The current status of the file, which can be either `uploaded`, `processed`, `pending`, - `error`, `deleting` or `deleted`. - status_details: + The status of the run step, which can be either `in_progress`, `cancelled`, `failed`, + `completed`, or `expired`. + step_details: + allOf: + - $ref: '#/components/schemas/RunStepDetails' + description: The details of the run step. + last_error: + type: object + properties: + code: + type: string + enum: + - server_error + - rate_limit_exceeded + description: One of `server_error` or `rate_limit_exceeded`. + message: + type: string + description: A human-readable description of the error. + required: + - code + - message + nullable: true + description: The last error associated with this run step. Will be `null` if there are no errors. + expires_at: type: string + format: date-time nullable: true description: |- - Additional details about the status of the file. If the file is in the `error` state, this will - include a message describing the error. - Penalty: - type: number - format: double - minimum: -2 - maximum: 2 - Prompt: - oneOf: - - type: string - - type: array - items: + The Unix timestamp (in seconds) for when the run step expired. A step is considered expired + if the parent run is expired. + cancelled_at: + type: string + format: date-time + nullable: true + description: The Unix timestamp (in seconds) for when the run step was cancelled. + failed_at: + type: string + format: date-time + nullable: true + description: The Unix timestamp (in seconds) for when the run step failed. + completed_at: + type: string + format: date-time + nullable: true + description: T The Unix timestamp (in seconds) for when the run step completed.. + metadata: + type: object + additionalProperties: type: string - - $ref: '#/components/schemas/TokenArray' - - $ref: '#/components/schemas/TokenArrayArray' - nullable: true + nullable: true + 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. + x-oaiTypeLabel: map + usage: + type: object + allOf: + - $ref: '#/components/schemas/RunCompletionUsage' + nullable: true + description: Represents a step in execution of a run. + RunToolCallObject: + type: object + required: + - id + - type + - function + 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 + enum: + - function + description: The type of tool call the output is required for. For now, this is always `function`. + function: + 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. + required: + - name + - arguments + description: The function definition. + description: Tool call objects Stop: oneOf: - type: string - $ref: '#/components/schemas/StopSequences' - nullable: true StopSequences: type: array items: type: string minItems: 1 maxItems: 4 + SubmitToolOutputsRunRequest: + type: object + required: + - tool_outputs + properties: + tool_outputs: + 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. + description: A list of tools for which the outputs are being submitted. SuffixString: type: string minLength: 1 maxLength: 40 - Temperature: - type: number - format: double - minimum: 0 - maximum: 2 - TokenArray: + ThreadObject: + type: object + required: + - id + - object + - created_at + - metadata + properties: + id: + type: string + description: The identifier, which can be referenced in API endpoints. + object: + type: string + enum: + - thread + description: The object type, which is always `thread`. + created_at: + type: integer + format: unixtime + description: The Unix timestamp (in seconds) for when the thread was created. + metadata: + type: object + additionalProperties: + type: string + nullable: true + 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. + x-oaiTypeLabel: map + description: Represents a thread that contains [messages](/docs/api-reference/messages). + TokenArrayArray: type: array items: - type: integer - format: int64 + $ref: '#/components/schemas/TokenArrayItem' minItems: 1 - TokenArrayArray: + TokenArrayItem: type: array items: - $ref: '#/components/schemas/TokenArray' + type: integer + format: int64 minItems: 1 - TopP: - type: number - format: double - minimum: 0 - maximum: 1 User: type: string securitySchemes: