Skip to content

Commit b1133f8

Browse files
feat(api): Add batches.cancel API
1 parent 3df5b97 commit b1133f8

File tree

6 files changed

+75
-2
lines changed

6 files changed

+75
-2
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 45
1+
configured_endpoints: 46
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/togetherai%2Ftogetherai-1afddc630f2b0684aad99bda9d83dc91ee6648a2b5cd7eac5d42fdc9ff46bbfc.yml
33
openapi_spec_hash: a4cab3a8559f632b66ea7aabd40cd8aa
4-
config_hash: 5e9563faf41fd9a91bea97783683bdb2
4+
config_hash: eb8d7493024f64839cec7401a9451c78

api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,14 @@ Types:
253253
- <code><a href="./src/resources/batches.ts">BatchCreateResponse</a></code>
254254
- <code><a href="./src/resources/batches.ts">BatchRetrieveResponse</a></code>
255255
- <code><a href="./src/resources/batches.ts">BatchListResponse</a></code>
256+
- <code><a href="./src/resources/batches.ts">BatchCancelResponse</a></code>
256257

257258
Methods:
258259

259260
- <code title="post /batches">client.batches.<a href="./src/resources/batches.ts">create</a>({ ...params }) -> BatchCreateResponse</code>
260261
- <code title="get /batches/{id}">client.batches.<a href="./src/resources/batches.ts">retrieve</a>(id) -> BatchRetrieveResponse</code>
261262
- <code title="get /batches">client.batches.<a href="./src/resources/batches.ts">list</a>() -> BatchListResponse</code>
263+
- <code title="post /batches/{id}/cancel">client.batches.<a href="./src/resources/batches.ts">cancel</a>(id) -> BatchCancelResponse</code>
262264

263265
# Evals
264266

src/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as TopLevelAPI from './resources/top-level';
1919
import { RerankParams, RerankResponse } from './resources/top-level';
2020
import { APIPromise } from './core/api-promise';
2121
import {
22+
BatchCancelResponse,
2223
BatchCreateParams,
2324
BatchCreateResponse,
2425
BatchListResponse,
@@ -987,6 +988,7 @@ export declare namespace Together {
987988
type BatchCreateResponse as BatchCreateResponse,
988989
type BatchRetrieveResponse as BatchRetrieveResponse,
989990
type BatchListResponse as BatchListResponse,
991+
type BatchCancelResponse as BatchCancelResponse,
990992
type BatchCreateParams as BatchCreateParams,
991993
};
992994

src/resources/batches.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ export class Batches extends APIResource {
4646
list(options?: RequestOptions): APIPromise<BatchListResponse> {
4747
return this._client.get('/batches', options);
4848
}
49+
50+
/**
51+
* Cancel a batch job by ID
52+
*
53+
* @example
54+
* ```ts
55+
* const response = await client.batches.cancel(
56+
* 'batch_job_abc123def456',
57+
* );
58+
* ```
59+
*/
60+
cancel(id: string, options?: RequestOptions): APIPromise<BatchCancelResponse> {
61+
return this._client.post(path`/batches/${id}/cancel`, options);
62+
}
4963
}
5064

5165
export interface BatchCreateResponse {
@@ -186,6 +200,48 @@ export namespace BatchListResponse {
186200
}
187201
}
188202

203+
export interface BatchCancelResponse {
204+
id?: string;
205+
206+
completed_at?: string;
207+
208+
created_at?: string;
209+
210+
endpoint?: string;
211+
212+
error?: string;
213+
214+
error_file_id?: string;
215+
216+
/**
217+
* Size of input file in bytes
218+
*/
219+
file_size_bytes?: number;
220+
221+
input_file_id?: string;
222+
223+
job_deadline?: string;
224+
225+
/**
226+
* Model used for processing requests
227+
*/
228+
model_id?: string;
229+
230+
output_file_id?: string;
231+
232+
/**
233+
* Completion progress (0.0 to 100)
234+
*/
235+
progress?: number;
236+
237+
/**
238+
* Current status of the batch job
239+
*/
240+
status?: 'VALIDATING' | 'IN_PROGRESS' | 'COMPLETED' | 'FAILED' | 'EXPIRED' | 'CANCELLED';
241+
242+
user_id?: string;
243+
}
244+
189245
export interface BatchCreateParams {
190246
/**
191247
* The endpoint to use for batch processing
@@ -218,6 +274,7 @@ export declare namespace Batches {
218274
type BatchCreateResponse as BatchCreateResponse,
219275
type BatchRetrieveResponse as BatchRetrieveResponse,
220276
type BatchListResponse as BatchListResponse,
277+
type BatchCancelResponse as BatchCancelResponse,
221278
type BatchCreateParams as BatchCreateParams,
222279
};
223280
}

src/resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export {
1313
type BatchCreateResponse,
1414
type BatchRetrieveResponse,
1515
type BatchListResponse,
16+
type BatchCancelResponse,
1617
type BatchCreateParams,
1718
} from './batches';
1819
export { Chat } from './chat/chat';

tests/api-resources/batches.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,15 @@ describe('resource batches', () => {
5353
expect(dataAndResponse.data).toBe(response);
5454
expect(dataAndResponse.response).toBe(rawResponse);
5555
});
56+
57+
test('cancel', async () => {
58+
const responsePromise = client.batches.cancel('batch_job_abc123def456');
59+
const rawResponse = await responsePromise.asResponse();
60+
expect(rawResponse).toBeInstanceOf(Response);
61+
const response = await responsePromise;
62+
expect(response).not.toBeInstanceOf(Response);
63+
const dataAndResponse = await responsePromise.withResponse();
64+
expect(dataAndResponse.data).toBe(response);
65+
expect(dataAndResponse.response).toBe(rawResponse);
66+
});
5667
});

0 commit comments

Comments
 (0)