@@ -64,6 +64,18 @@ func (r *BatchService) List(ctx context.Context, opts ...option.RequestOption) (
6464 return
6565}
6666
67+ // Cancel a batch job by ID
68+ func (r * BatchService ) Cancel (ctx context.Context , id string , opts ... option.RequestOption ) (res * BatchCancelResponse , err error ) {
69+ opts = slices .Concat (r .Options , opts )
70+ if id == "" {
71+ err = errors .New ("missing required id parameter" )
72+ return
73+ }
74+ path := fmt .Sprintf ("batches/%s/cancel" , id )
75+ err = requestconfig .ExecuteNewRequest (ctx , http .MethodPost , path , nil , & res , opts ... )
76+ return
77+ }
78+
6779type BatchNewResponse struct {
6880 Job BatchNewResponseJob `json:"job"`
6981 Warning string `json:"warning"`
@@ -253,6 +265,67 @@ const (
253265 BatchListResponseStatusCancelled BatchListResponseStatus = "CANCELLED"
254266)
255267
268+ type BatchCancelResponse struct {
269+ ID string `json:"id" format:"uuid"`
270+ CompletedAt time.Time `json:"completed_at" format:"date-time"`
271+ CreatedAt time.Time `json:"created_at" format:"date-time"`
272+ Endpoint string `json:"endpoint"`
273+ Error string `json:"error"`
274+ ErrorFileID string `json:"error_file_id"`
275+ // Size of input file in bytes
276+ FileSizeBytes int64 `json:"file_size_bytes"`
277+ InputFileID string `json:"input_file_id"`
278+ JobDeadline time.Time `json:"job_deadline" format:"date-time"`
279+ // Model used for processing requests
280+ ModelID string `json:"model_id"`
281+ OutputFileID string `json:"output_file_id"`
282+ // Completion progress (0.0 to 100)
283+ Progress float64 `json:"progress"`
284+ // Current status of the batch job
285+ //
286+ // Any of "VALIDATING", "IN_PROGRESS", "COMPLETED", "FAILED", "EXPIRED",
287+ // "CANCELLED".
288+ Status BatchCancelResponseStatus `json:"status"`
289+ UserID string `json:"user_id"`
290+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
291+ JSON struct {
292+ ID respjson.Field
293+ CompletedAt respjson.Field
294+ CreatedAt respjson.Field
295+ Endpoint respjson.Field
296+ Error respjson.Field
297+ ErrorFileID respjson.Field
298+ FileSizeBytes respjson.Field
299+ InputFileID respjson.Field
300+ JobDeadline respjson.Field
301+ ModelID respjson.Field
302+ OutputFileID respjson.Field
303+ Progress respjson.Field
304+ Status respjson.Field
305+ UserID respjson.Field
306+ ExtraFields map [string ]respjson.Field
307+ raw string
308+ } `json:"-"`
309+ }
310+
311+ // Returns the unmodified JSON received from the API
312+ func (r BatchCancelResponse ) RawJSON () string { return r .JSON .raw }
313+ func (r * BatchCancelResponse ) UnmarshalJSON (data []byte ) error {
314+ return apijson .UnmarshalRoot (data , r )
315+ }
316+
317+ // Current status of the batch job
318+ type BatchCancelResponseStatus string
319+
320+ const (
321+ BatchCancelResponseStatusValidating BatchCancelResponseStatus = "VALIDATING"
322+ BatchCancelResponseStatusInProgress BatchCancelResponseStatus = "IN_PROGRESS"
323+ BatchCancelResponseStatusCompleted BatchCancelResponseStatus = "COMPLETED"
324+ BatchCancelResponseStatusFailed BatchCancelResponseStatus = "FAILED"
325+ BatchCancelResponseStatusExpired BatchCancelResponseStatus = "EXPIRED"
326+ BatchCancelResponseStatusCancelled BatchCancelResponseStatus = "CANCELLED"
327+ )
328+
256329type BatchNewParams struct {
257330 // The endpoint to use for batch processing
258331 Endpoint string `json:"endpoint,required"`
0 commit comments