batches.d.mts 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. import { APIResource } from "../core/resource.mjs";
  2. import * as BatchesAPI from "./batches.mjs";
  3. import * as Shared from "./shared.mjs";
  4. import { APIPromise } from "../core/api-promise.mjs";
  5. import { CursorPage, type CursorPageParams, PagePromise } from "../core/pagination.mjs";
  6. import { RequestOptions } from "../internal/request-options.mjs";
  7. export declare class Batches extends APIResource {
  8. /**
  9. * Creates and executes a batch from an uploaded file of requests
  10. */
  11. create(body: BatchCreateParams, options?: RequestOptions): APIPromise<Batch>;
  12. /**
  13. * Retrieves a batch.
  14. */
  15. retrieve(batchID: string, options?: RequestOptions): APIPromise<Batch>;
  16. /**
  17. * List your organization's batches.
  18. */
  19. list(query?: BatchListParams | null | undefined, options?: RequestOptions): 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?: RequestOptions): APIPromise<Batch>;
  26. }
  27. export type BatchesPage = CursorPage<Batch>;
  28. export interface Batch {
  29. id: string;
  30. /**
  31. * The time frame within which the batch should be processed.
  32. */
  33. completion_window: string;
  34. /**
  35. * The Unix timestamp (in seconds) for when the batch was created.
  36. */
  37. created_at: number;
  38. /**
  39. * The OpenAI API endpoint used by the batch.
  40. */
  41. endpoint: string;
  42. /**
  43. * The ID of the input file for the batch.
  44. */
  45. input_file_id: string;
  46. /**
  47. * The object type, which is always `batch`.
  48. */
  49. object: 'batch';
  50. /**
  51. * The current status of the batch.
  52. */
  53. status: 'validating' | 'failed' | 'in_progress' | 'finalizing' | 'completed' | 'expired' | 'cancelling' | 'cancelled';
  54. /**
  55. * The Unix timestamp (in seconds) for when the batch was cancelled.
  56. */
  57. cancelled_at?: number;
  58. /**
  59. * The Unix timestamp (in seconds) for when the batch started cancelling.
  60. */
  61. cancelling_at?: number;
  62. /**
  63. * The Unix timestamp (in seconds) for when the batch was completed.
  64. */
  65. completed_at?: number;
  66. /**
  67. * The ID of the file containing the outputs of requests with errors.
  68. */
  69. error_file_id?: string;
  70. errors?: Batch.Errors;
  71. /**
  72. * The Unix timestamp (in seconds) for when the batch expired.
  73. */
  74. expired_at?: number;
  75. /**
  76. * The Unix timestamp (in seconds) for when the batch will expire.
  77. */
  78. expires_at?: number;
  79. /**
  80. * The Unix timestamp (in seconds) for when the batch failed.
  81. */
  82. failed_at?: number;
  83. /**
  84. * The Unix timestamp (in seconds) for when the batch started finalizing.
  85. */
  86. finalizing_at?: number;
  87. /**
  88. * The Unix timestamp (in seconds) for when the batch started processing.
  89. */
  90. in_progress_at?: number;
  91. /**
  92. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  93. * for storing additional information about the object in a structured format, and
  94. * querying for objects via API or the dashboard.
  95. *
  96. * Keys are strings with a maximum length of 64 characters. Values are strings with
  97. * a maximum length of 512 characters.
  98. */
  99. metadata?: Shared.Metadata | null;
  100. /**
  101. * Model ID used to process the batch, like `gpt-5-2025-08-07`. OpenAI offers a
  102. * wide range of models with different capabilities, performance characteristics,
  103. * and price points. Refer to the
  104. * [model guide](https://platform.openai.com/docs/models) to browse and compare
  105. * available models.
  106. */
  107. model?: string;
  108. /**
  109. * The ID of the file containing the outputs of successfully executed requests.
  110. */
  111. output_file_id?: string;
  112. /**
  113. * The request counts for different statuses within the batch.
  114. */
  115. request_counts?: BatchRequestCounts;
  116. /**
  117. * Represents token usage details including input tokens, output tokens, a
  118. * breakdown of output tokens, and the total tokens used. Only populated on batches
  119. * created after September 7, 2025.
  120. */
  121. usage?: BatchUsage;
  122. }
  123. export declare namespace Batch {
  124. interface Errors {
  125. data?: Array<BatchesAPI.BatchError>;
  126. /**
  127. * The object type, which is always `list`.
  128. */
  129. object?: string;
  130. }
  131. }
  132. export interface BatchError {
  133. /**
  134. * An error code identifying the error type.
  135. */
  136. code?: string;
  137. /**
  138. * The line number of the input file where the error occurred, if applicable.
  139. */
  140. line?: number | null;
  141. /**
  142. * A human-readable message providing more details about the error.
  143. */
  144. message?: string;
  145. /**
  146. * The name of the parameter that caused the error, if applicable.
  147. */
  148. param?: string | null;
  149. }
  150. /**
  151. * The request counts for different statuses within the batch.
  152. */
  153. export interface BatchRequestCounts {
  154. /**
  155. * Number of requests that have been completed successfully.
  156. */
  157. completed: number;
  158. /**
  159. * Number of requests that have failed.
  160. */
  161. failed: number;
  162. /**
  163. * Total number of requests in the batch.
  164. */
  165. total: number;
  166. }
  167. /**
  168. * Represents token usage details including input tokens, output tokens, a
  169. * breakdown of output tokens, and the total tokens used. Only populated on batches
  170. * created after September 7, 2025.
  171. */
  172. export interface BatchUsage {
  173. /**
  174. * The number of input tokens.
  175. */
  176. input_tokens: number;
  177. /**
  178. * A detailed breakdown of the input tokens.
  179. */
  180. input_tokens_details: BatchUsage.InputTokensDetails;
  181. /**
  182. * The number of output tokens.
  183. */
  184. output_tokens: number;
  185. /**
  186. * A detailed breakdown of the output tokens.
  187. */
  188. output_tokens_details: BatchUsage.OutputTokensDetails;
  189. /**
  190. * The total number of tokens used.
  191. */
  192. total_tokens: number;
  193. }
  194. export declare namespace BatchUsage {
  195. /**
  196. * A detailed breakdown of the input tokens.
  197. */
  198. interface InputTokensDetails {
  199. /**
  200. * The number of tokens that were retrieved from the cache.
  201. * [More on prompt caching](https://platform.openai.com/docs/guides/prompt-caching).
  202. */
  203. cached_tokens: number;
  204. }
  205. /**
  206. * A detailed breakdown of the output tokens.
  207. */
  208. interface OutputTokensDetails {
  209. /**
  210. * The number of reasoning tokens.
  211. */
  212. reasoning_tokens: number;
  213. }
  214. }
  215. export interface BatchCreateParams {
  216. /**
  217. * The time frame within which the batch should be processed. Currently only `24h`
  218. * is supported.
  219. */
  220. completion_window: '24h';
  221. /**
  222. * The endpoint to be used for all requests in the batch. Currently
  223. * `/v1/responses`, `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`,
  224. * and `/v1/moderations` are supported. Note that `/v1/embeddings` batches are also
  225. * restricted to a maximum of 50,000 embedding inputs across all requests in the
  226. * batch.
  227. */
  228. endpoint: '/v1/responses' | '/v1/chat/completions' | '/v1/embeddings' | '/v1/completions' | '/v1/moderations';
  229. /**
  230. * The ID of an uploaded file that contains requests for the new batch.
  231. *
  232. * See [upload file](https://platform.openai.com/docs/api-reference/files/create)
  233. * for how to upload a file.
  234. *
  235. * Your input file must be formatted as a
  236. * [JSONL file](https://platform.openai.com/docs/api-reference/batch/request-input),
  237. * and must be uploaded with the purpose `batch`. The file can contain up to 50,000
  238. * requests, and can be up to 200 MB in size.
  239. */
  240. input_file_id: string;
  241. /**
  242. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  243. * for storing additional information about the object in a structured format, and
  244. * querying for objects via API or the dashboard.
  245. *
  246. * Keys are strings with a maximum length of 64 characters. Values are strings with
  247. * a maximum length of 512 characters.
  248. */
  249. metadata?: Shared.Metadata | null;
  250. /**
  251. * The expiration policy for the output and/or error file that are generated for a
  252. * batch.
  253. */
  254. output_expires_after?: BatchCreateParams.OutputExpiresAfter;
  255. }
  256. export declare namespace BatchCreateParams {
  257. /**
  258. * The expiration policy for the output and/or error file that are generated for a
  259. * batch.
  260. */
  261. interface OutputExpiresAfter {
  262. /**
  263. * Anchor timestamp after which the expiration policy applies. Supported anchors:
  264. * `created_at`. Note that the anchor is the file creation time, not the time the
  265. * batch is created.
  266. */
  267. anchor: 'created_at';
  268. /**
  269. * The number of seconds after the anchor time that the file will expire. Must be
  270. * between 3600 (1 hour) and 2592000 (30 days).
  271. */
  272. seconds: number;
  273. }
  274. }
  275. export interface BatchListParams extends CursorPageParams {
  276. }
  277. export declare namespace Batches {
  278. export { type Batch as Batch, type BatchError as BatchError, type BatchRequestCounts as BatchRequestCounts, type BatchUsage as BatchUsage, type BatchesPage as BatchesPage, type BatchCreateParams as BatchCreateParams, type BatchListParams as BatchListParams, };
  279. }
  280. //# sourceMappingURL=batches.d.mts.map