|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +import * as Core from 'openai/core'; |
| 4 | +import { APIResource } from 'openai/resource'; |
| 5 | +import * as BatchesAPI from 'openai/resources/batches'; |
| 6 | + |
| 7 | +export class Batches extends APIResource { |
| 8 | + /** |
| 9 | + * Creates and executes a batch from an uploaded file of requests |
| 10 | + */ |
| 11 | + create(body: BatchCreateParams, options?: Core.RequestOptions): Core.APIPromise<Batch> { |
| 12 | + return this._client.post('/batches', { body, ...options }); |
| 13 | + } |
| 14 | + |
| 15 | + /** |
| 16 | + * Retrieves a batch. |
| 17 | + */ |
| 18 | + retrieve(batchId: string, options?: Core.RequestOptions): Core.APIPromise<Batch> { |
| 19 | + return this._client.get(`/batches/${batchId}`, options); |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * Cancels an in-progress batch. |
| 24 | + */ |
| 25 | + cancel(batchId: string, options?: Core.RequestOptions): Core.APIPromise<Batch> { |
| 26 | + return this._client.post(`/batches/${batchId}/cancel`, options); |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +export interface Batch { |
| 31 | + id: string; |
| 32 | + |
| 33 | + /** |
| 34 | + * The time frame within which the batch should be processed. |
| 35 | + */ |
| 36 | + completion_window: string; |
| 37 | + |
| 38 | + /** |
| 39 | + * The Unix timestamp (in seconds) for when the batch was created. |
| 40 | + */ |
| 41 | + created_at: string; |
| 42 | + |
| 43 | + /** |
| 44 | + * The OpenAI API endpoint used by the batch. |
| 45 | + */ |
| 46 | + endpoint: string; |
| 47 | + |
| 48 | + /** |
| 49 | + * The ID of the input file for the batch. |
| 50 | + */ |
| 51 | + input_file_id: string; |
| 52 | + |
| 53 | + /** |
| 54 | + * The object type, which is always `batch`. |
| 55 | + */ |
| 56 | + object: 'batch'; |
| 57 | + |
| 58 | + /** |
| 59 | + * The current status of the batch. |
| 60 | + */ |
| 61 | + status: |
| 62 | + | 'validating' |
| 63 | + | 'failed' |
| 64 | + | 'in_progress' |
| 65 | + | 'finalizing' |
| 66 | + | 'completed' |
| 67 | + | 'expired' |
| 68 | + | 'cancelling' |
| 69 | + | 'cancelled'; |
| 70 | + |
| 71 | + /** |
| 72 | + * The Unix timestamp (in seconds) for when the batch was cancelled. |
| 73 | + */ |
| 74 | + cancelled_at?: string; |
| 75 | + |
| 76 | + /** |
| 77 | + * The Unix timestamp (in seconds) for when the batch started cancelling. |
| 78 | + */ |
| 79 | + cancelling_at?: string; |
| 80 | + |
| 81 | + /** |
| 82 | + * The Unix timestamp (in seconds) for when the batch was completed. |
| 83 | + */ |
| 84 | + completed_at?: string; |
| 85 | + |
| 86 | + /** |
| 87 | + * The ID of the file containing the outputs of requests with errors. |
| 88 | + */ |
| 89 | + error_file_id?: string; |
| 90 | + |
| 91 | + errors?: Batch.Errors; |
| 92 | + |
| 93 | + /** |
| 94 | + * The Unix timestamp (in seconds) for when the batch expired. |
| 95 | + */ |
| 96 | + expired_at?: string; |
| 97 | + |
| 98 | + /** |
| 99 | + * The Unix timestamp (in seconds) for when the batch will expire. |
| 100 | + */ |
| 101 | + expires_at?: string; |
| 102 | + |
| 103 | + /** |
| 104 | + * The Unix timestamp (in seconds) for when the batch failed. |
| 105 | + */ |
| 106 | + failed_at?: string; |
| 107 | + |
| 108 | + /** |
| 109 | + * The Unix timestamp (in seconds) for when the batch started finalizing. |
| 110 | + */ |
| 111 | + finalizing_at?: string; |
| 112 | + |
| 113 | + /** |
| 114 | + * The Unix timestamp (in seconds) for when the batch started processing. |
| 115 | + */ |
| 116 | + in_progress_at?: string; |
| 117 | + |
| 118 | + /** |
| 119 | + * Set of 16 key-value pairs that can be attached to an object. This can be useful |
| 120 | + * for storing additional information about the object in a structured format. Keys |
| 121 | + * can be a maximum of 64 characters long and values can be a maxium of 512 |
| 122 | + * characters long. |
| 123 | + */ |
| 124 | + metadata?: unknown | null; |
| 125 | + |
| 126 | + /** |
| 127 | + * The ID of the file containing the outputs of successfully executed requests. |
| 128 | + */ |
| 129 | + output_file_id?: string; |
| 130 | + |
| 131 | + /** |
| 132 | + * The request counts for different statuses within the batch. |
| 133 | + */ |
| 134 | + request_counts?: BatchRequestCounts; |
| 135 | +} |
| 136 | + |
| 137 | +export namespace Batch { |
| 138 | + export interface Errors { |
| 139 | + data?: Array<BatchesAPI.BatchError>; |
| 140 | + |
| 141 | + /** |
| 142 | + * The object type, which is always `list`. |
| 143 | + */ |
| 144 | + object?: string; |
| 145 | + } |
| 146 | +} |
| 147 | + |
| 148 | +export interface BatchError { |
| 149 | + /** |
| 150 | + * An error code identifying the error type. |
| 151 | + */ |
| 152 | + code?: string; |
| 153 | + |
| 154 | + /** |
| 155 | + * The line number of the input file where the error occurred, if applicable. |
| 156 | + */ |
| 157 | + line?: number | null; |
| 158 | + |
| 159 | + /** |
| 160 | + * A human-readable message providing more details about the error. |
| 161 | + */ |
| 162 | + message?: string; |
| 163 | + |
| 164 | + /** |
| 165 | + * The name of the parameter that caused the error, if applicable. |
| 166 | + */ |
| 167 | + param?: string | null; |
| 168 | +} |
| 169 | + |
| 170 | +/** |
| 171 | + * The request counts for different statuses within the batch. |
| 172 | + */ |
| 173 | +export interface BatchRequestCounts { |
| 174 | + /** |
| 175 | + * Number of requests that have been completed successfully. |
| 176 | + */ |
| 177 | + completed: number; |
| 178 | + |
| 179 | + /** |
| 180 | + * Number of requests that have failed. |
| 181 | + */ |
| 182 | + failed: number; |
| 183 | + |
| 184 | + /** |
| 185 | + * Total number of requests in the batch. |
| 186 | + */ |
| 187 | + total: number; |
| 188 | +} |
| 189 | + |
| 190 | +export interface BatchCreateParams { |
| 191 | + /** |
| 192 | + * The time frame within which the batch should be processed. Currently only `24h` |
| 193 | + * is supported. |
| 194 | + */ |
| 195 | + completion_window: '24h'; |
| 196 | + |
| 197 | + /** |
| 198 | + * The endpoint to be used for all requests in the batch. Currently only |
| 199 | + * `/v1/chat/completions` is supported. |
| 200 | + */ |
| 201 | + endpoint: '/v1/chat/completions'; |
| 202 | + |
| 203 | + /** |
| 204 | + * The ID of an uploaded file that contains requests for the new batch. |
| 205 | + * |
| 206 | + * See [upload file](https://platform.openai.com/docs/api-reference/files/create) |
| 207 | + * for how to upload a file. |
| 208 | + * |
| 209 | + * Your input file must be formatted as a JSONL file, and must be uploaded with the |
| 210 | + * purpose `batch`. |
| 211 | + */ |
| 212 | + input_file_id: string; |
| 213 | + |
| 214 | + /** |
| 215 | + * Optional custom metadata for the batch. |
| 216 | + */ |
| 217 | + metadata?: Record<string, string> | null; |
| 218 | +} |
| 219 | + |
| 220 | +export namespace Batches { |
| 221 | + export import Batch = BatchesAPI.Batch; |
| 222 | + export import BatchError = BatchesAPI.BatchError; |
| 223 | + export import BatchRequestCounts = BatchesAPI.BatchRequestCounts; |
| 224 | + export import BatchCreateParams = BatchesAPI.BatchCreateParams; |
| 225 | +} |
0 commit comments