uploads.d.mts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import { APIResource } from "../../core/resource.mjs";
  2. import * as FilesAPI from "../files.mjs";
  3. import * as PartsAPI from "./parts.mjs";
  4. import { PartCreateParams, Parts, UploadPart } from "./parts.mjs";
  5. import { APIPromise } from "../../core/api-promise.mjs";
  6. import { RequestOptions } from "../../internal/request-options.mjs";
  7. export declare class Uploads extends APIResource {
  8. parts: PartsAPI.Parts;
  9. /**
  10. * Creates an intermediate
  11. * [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object
  12. * that you can add
  13. * [Parts](https://platform.openai.com/docs/api-reference/uploads/part-object) to.
  14. * Currently, an Upload can accept at most 8 GB in total and expires after an hour
  15. * after you create it.
  16. *
  17. * Once you complete the Upload, we will create a
  18. * [File](https://platform.openai.com/docs/api-reference/files/object) object that
  19. * contains all the parts you uploaded. This File is usable in the rest of our
  20. * platform as a regular File object.
  21. *
  22. * For certain `purpose` values, the correct `mime_type` must be specified. Please
  23. * refer to documentation for the
  24. * [supported MIME types for your use case](https://platform.openai.com/docs/assistants/tools/file-search#supported-files).
  25. *
  26. * For guidance on the proper filename extensions for each purpose, please follow
  27. * the documentation on
  28. * [creating a File](https://platform.openai.com/docs/api-reference/files/create).
  29. */
  30. create(body: UploadCreateParams, options?: RequestOptions): APIPromise<Upload>;
  31. /**
  32. * Cancels the Upload. No Parts may be added after an Upload is cancelled.
  33. */
  34. cancel(uploadID: string, options?: RequestOptions): APIPromise<Upload>;
  35. /**
  36. * Completes the
  37. * [Upload](https://platform.openai.com/docs/api-reference/uploads/object).
  38. *
  39. * Within the returned Upload object, there is a nested
  40. * [File](https://platform.openai.com/docs/api-reference/files/object) object that
  41. * is ready to use in the rest of the platform.
  42. *
  43. * You can specify the order of the Parts by passing in an ordered list of the Part
  44. * IDs.
  45. *
  46. * The number of bytes uploaded upon completion must match the number of bytes
  47. * initially specified when creating the Upload object. No Parts may be added after
  48. * an Upload is completed.
  49. */
  50. complete(uploadID: string, body: UploadCompleteParams, options?: RequestOptions): APIPromise<Upload>;
  51. }
  52. /**
  53. * The Upload object can accept byte chunks in the form of Parts.
  54. */
  55. export interface Upload {
  56. /**
  57. * The Upload unique identifier, which can be referenced in API endpoints.
  58. */
  59. id: string;
  60. /**
  61. * The intended number of bytes to be uploaded.
  62. */
  63. bytes: number;
  64. /**
  65. * The Unix timestamp (in seconds) for when the Upload was created.
  66. */
  67. created_at: number;
  68. /**
  69. * The Unix timestamp (in seconds) for when the Upload will expire.
  70. */
  71. expires_at: number;
  72. /**
  73. * The name of the file to be uploaded.
  74. */
  75. filename: string;
  76. /**
  77. * The object type, which is always "upload".
  78. */
  79. object: 'upload';
  80. /**
  81. * The intended purpose of the file.
  82. * [Please refer here](https://platform.openai.com/docs/api-reference/files/object#files/object-purpose)
  83. * for acceptable values.
  84. */
  85. purpose: string;
  86. /**
  87. * The status of the Upload.
  88. */
  89. status: 'pending' | 'completed' | 'cancelled' | 'expired';
  90. /**
  91. * The `File` object represents a document that has been uploaded to OpenAI.
  92. */
  93. file?: FilesAPI.FileObject | null;
  94. }
  95. export interface UploadCreateParams {
  96. /**
  97. * The number of bytes in the file you are uploading.
  98. */
  99. bytes: number;
  100. /**
  101. * The name of the file to upload.
  102. */
  103. filename: string;
  104. /**
  105. * The MIME type of the file.
  106. *
  107. * This must fall within the supported MIME types for your file purpose. See the
  108. * supported MIME types for assistants and vision.
  109. */
  110. mime_type: string;
  111. /**
  112. * The intended purpose of the uploaded file.
  113. *
  114. * See the
  115. * [documentation on File purposes](https://platform.openai.com/docs/api-reference/files/create#files-create-purpose).
  116. */
  117. purpose: FilesAPI.FilePurpose;
  118. /**
  119. * The expiration policy for a file. By default, files with `purpose=batch` expire
  120. * after 30 days and all other files are persisted until they are manually deleted.
  121. */
  122. expires_after?: UploadCreateParams.ExpiresAfter;
  123. }
  124. export declare namespace UploadCreateParams {
  125. /**
  126. * The expiration policy for a file. By default, files with `purpose=batch` expire
  127. * after 30 days and all other files are persisted until they are manually deleted.
  128. */
  129. interface ExpiresAfter {
  130. /**
  131. * Anchor timestamp after which the expiration policy applies. Supported anchors:
  132. * `created_at`.
  133. */
  134. anchor: 'created_at';
  135. /**
  136. * The number of seconds after the anchor time that the file will expire. Must be
  137. * between 3600 (1 hour) and 2592000 (30 days).
  138. */
  139. seconds: number;
  140. }
  141. }
  142. export interface UploadCompleteParams {
  143. /**
  144. * The ordered list of Part IDs.
  145. */
  146. part_ids: Array<string>;
  147. /**
  148. * The optional md5 checksum for the file contents to verify if the bytes uploaded
  149. * matches what you expect.
  150. */
  151. md5?: string;
  152. }
  153. export declare namespace Uploads {
  154. export { type Upload as Upload, type UploadCreateParams as UploadCreateParams, type UploadCompleteParams as UploadCompleteParams, };
  155. export { Parts as Parts, type UploadPart as UploadPart, type PartCreateParams as PartCreateParams };
  156. }
  157. //# sourceMappingURL=uploads.d.mts.map