batches.d.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import { APIResource } from "../resource.js";
  2. import * as Core from "../core.js";
  3. import * as BatchesAPI from "./batches.js";
  4. import * as Shared from "./shared.js";
  5. import { CursorPage, type CursorPageParams } from "../pagination.js";
  6. export declare class Batches extends APIResource {
  7. /**
  8. * Creates and executes a batch from an uploaded file of requests
  9. */
  10. create(body: BatchCreateParams, options?: Core.RequestOptions): Core.APIPromise<Batch>;
  11. /**
  12. * Retrieves a batch.
  13. */
  14. retrieve(batchId: string, options?: Core.RequestOptions): Core.APIPromise<Batch>;
  15. /**
  16. * List your organization's batches.
  17. */
  18. list(query?: BatchListParams, options?: Core.RequestOptions): Core.PagePromise<BatchesPage, Batch>;
  19. list(options?: Core.RequestOptions): Core.PagePromise<BatchesPage, Batch>;
  20. /**
  21. * Cancels an in-progress batch. The batch will be in status `cancelling` for up to
  22. * 10 minutes, before changing to `cancelled`, where it will have partial results
  23. * (if any) available in the output file.
  24. */
  25. cancel(batchId: string, options?: Core.RequestOptions): Core.APIPromise<Batch>;
  26. }
  27. export declare class BatchesPage extends CursorPage<Batch> {
  28. }
  29. export interface Batch {
  30. id: string;
  31. /**
  32. * The time frame within which the batch should be processed.
  33. */
  34. completion_window: string;
  35. /**
  36. * The Unix timestamp (in seconds) for when the batch was created.
  37. */
  38. created_at: number;
  39. /**
  40. * The OpenAI API endpoint used by the batch.
  41. */
  42. endpoint: string;
  43. /**
  44. * The ID of the input file for the batch.
  45. */
  46. input_file_id: string;
  47. /**
  48. * The object type, which is always `batch`.
  49. */
  50. object: 'batch';
  51. /**
  52. * The current status of the batch.
  53. */
  54. status: 'validating' | 'failed' | 'in_progress' | 'finalizing' | 'completed' | 'expired' | 'cancelling' | 'cancelled';
  55. /**
  56. * The Unix timestamp (in seconds) for when the batch was cancelled.
  57. */
  58. cancelled_at?: number;
  59. /**
  60. * The Unix timestamp (in seconds) for when the batch started cancelling.
  61. */
  62. cancelling_at?: number;
  63. /**
  64. * The Unix timestamp (in seconds) for when the batch was completed.
  65. */
  66. completed_at?: number;
  67. /**
  68. * The ID of the file containing the outputs of requests with errors.
  69. */
  70. error_file_id?: string;
  71. errors?: Batch.Errors;
  72. /**
  73. * The Unix timestamp (in seconds) for when the batch expired.
  74. */
  75. expired_at?: number;
  76. /**
  77. * The Unix timestamp (in seconds) for when the batch will expire.
  78. */
  79. expires_at?: number;
  80. /**
  81. * The Unix timestamp (in seconds) for when the batch failed.
  82. */
  83. failed_at?: number;
  84. /**
  85. * The Unix timestamp (in seconds) for when the batch started finalizing.
  86. */
  87. finalizing_at?: number;
  88. /**
  89. * The Unix timestamp (in seconds) for when the batch started processing.
  90. */
  91. in_progress_at?: number;
  92. /**
  93. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  94. * for storing additional information about the object in a structured format, and
  95. * querying for objects via API or the dashboard.
  96. *
  97. * Keys are strings with a maximum length of 64 characters. Values are strings with
  98. * a maximum length of 512 characters.
  99. */
  100. metadata?: Shared.Metadata | null;
  101. /**
  102. * The ID of the file containing the outputs of successfully executed requests.
  103. */
  104. output_file_id?: string;
  105. /**
  106. * The request counts for different statuses within the batch.
  107. */
  108. request_counts?: BatchRequestCounts;
  109. }
  110. export declare namespace Batch {
  111. interface Errors {
  112. data?: Array<BatchesAPI.BatchError>;
  113. /**
  114. * The object type, which is always `list`.
  115. */
  116. object?: string;
  117. }
  118. }
  119. export interface BatchError {
  120. /**
  121. * An error code identifying the error type.
  122. */
  123. code?: string;
  124. /**
  125. * The line number of the input file where the error occurred, if applicable.
  126. */
  127. line?: number | null;
  128. /**
  129. * A human-readable message providing more details about the error.
  130. */
  131. message?: string;
  132. /**
  133. * The name of the parameter that caused the error, if applicable.
  134. */
  135. param?: string | null;
  136. }
  137. /**
  138. * The request counts for different statuses within the batch.
  139. */
  140. export interface BatchRequestCounts {
  141. /**
  142. * Number of requests that have been completed successfully.
  143. */
  144. completed: number;
  145. /**
  146. * Number of requests that have failed.
  147. */
  148. failed: number;
  149. /**
  150. * Total number of requests in the batch.
  151. */
  152. total: number;
  153. }
  154. export interface BatchCreateParams {
  155. /**
  156. * The time frame within which the batch should be processed. Currently only `24h`
  157. * is supported.
  158. */
  159. completion_window: '24h';
  160. /**
  161. * The endpoint to be used for all requests in the batch. Currently
  162. * `/v1/responses`, `/v1/chat/completions`, `/v1/embeddings`, and `/v1/completions`
  163. * are supported. Note that `/v1/embeddings` batches are also restricted to a
  164. * maximum of 50,000 embedding inputs across all requests in the batch.
  165. */
  166. endpoint: '/v1/responses' | '/v1/chat/completions' | '/v1/embeddings' | '/v1/completions';
  167. /**
  168. * The ID of an uploaded file that contains requests for the new batch.
  169. *
  170. * See [upload file](https://platform.openai.com/docs/api-reference/files/create)
  171. * for how to upload a file.
  172. *
  173. * Your input file must be formatted as a
  174. * [JSONL file](https://platform.openai.com/docs/api-reference/batch/request-input),
  175. * and must be uploaded with the purpose `batch`. The file can contain up to 50,000
  176. * requests, and can be up to 200 MB in size.
  177. */
  178. input_file_id: string;
  179. /**
  180. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  181. * for storing additional information about the object in a structured format, and
  182. * querying for objects via API or the dashboard.
  183. *
  184. * Keys are strings with a maximum length of 64 characters. Values are strings with
  185. * a maximum length of 512 characters.
  186. */
  187. metadata?: Shared.Metadata | null;
  188. }
  189. export interface BatchListParams extends CursorPageParams {
  190. }
  191. export declare namespace Batches {
  192. export { type Batch as Batch, type BatchError as BatchError, type BatchRequestCounts as BatchRequestCounts, BatchesPage as BatchesPage, type BatchCreateParams as BatchCreateParams, type BatchListParams as BatchListParams, };
  193. }
  194. //# sourceMappingURL=batches.d.ts.map