Skip to content

Commit 08cfa8b

Browse files
stainless-app[bot]RobertCraigie
authored andcommitted
feat(api): add message batch delete endpoint
1 parent 1a5a31f commit 08cfa8b

File tree

10 files changed

+138
-2
lines changed

10 files changed

+138
-2
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 19
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-9563716c7b08b8936ba450ad05005d12cf5ca3b9a37fab8126ed372e422d6de6.yml
1+
configured_endpoints: 21
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-fd67aea6883f1ee9e46f31a42d3940f0acb1749e787055bd9b9f278b20fa53ec.yml

api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Methods:
7070

7171
Types:
7272

73+
- <code><a href="./src/resources/messages/batches.ts">DeletedMessageBatch</a></code>
7374
- <code><a href="./src/resources/messages/batches.ts">MessageBatch</a></code>
7475
- <code><a href="./src/resources/messages/batches.ts">MessageBatchCanceledResult</a></code>
7576
- <code><a href="./src/resources/messages/batches.ts">MessageBatchErroredResult</a></code>
@@ -84,6 +85,7 @@ Methods:
8485
- <code title="post /v1/messages/batches">client.messages.batches.<a href="./src/resources/messages/batches.ts">create</a>({ ...params }) -> MessageBatch</code>
8586
- <code title="get /v1/messages/batches/{message_batch_id}">client.messages.batches.<a href="./src/resources/messages/batches.ts">retrieve</a>(messageBatchId) -> MessageBatch</code>
8687
- <code title="get /v1/messages/batches">client.messages.batches.<a href="./src/resources/messages/batches.ts">list</a>({ ...params }) -> MessageBatchesPage</code>
88+
- <code title="delete /v1/messages/batches/{message_batch_id}">client.messages.batches.<a href="./src/resources/messages/batches.ts">delete</a>(messageBatchId) -> DeletedMessageBatch</code>
8789
- <code title="post /v1/messages/batches/{message_batch_id}/cancel">client.messages.batches.<a href="./src/resources/messages/batches.ts">cancel</a>(messageBatchId) -> MessageBatch</code>
8890
- <code title="get /v1/messages/batches/{message_batch_id}/results">client.messages.batches.<a href="./src/resources/messages/batches.ts">results</a>(messageBatchId) -> Response</code>
8991

@@ -175,6 +177,7 @@ Methods:
175177

176178
Types:
177179

180+
- <code><a href="./src/resources/beta/messages/batches.ts">BetaDeletedMessageBatch</a></code>
178181
- <code><a href="./src/resources/beta/messages/batches.ts">BetaMessageBatch</a></code>
179182
- <code><a href="./src/resources/beta/messages/batches.ts">BetaMessageBatchCanceledResult</a></code>
180183
- <code><a href="./src/resources/beta/messages/batches.ts">BetaMessageBatchErroredResult</a></code>
@@ -189,5 +192,6 @@ Methods:
189192
- <code title="post /v1/messages/batches?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">create</a>({ ...params }) -> BetaMessageBatch</code>
190193
- <code title="get /v1/messages/batches/{message_batch_id}?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">retrieve</a>(messageBatchId, { ...params }) -> BetaMessageBatch</code>
191194
- <code title="get /v1/messages/batches?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">list</a>({ ...params }) -> BetaMessageBatchesPage</code>
195+
- <code title="delete /v1/messages/batches/{message_batch_id}?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">delete</a>(messageBatchId, { ...params }) -> BetaDeletedMessageBatch</code>
192196
- <code title="post /v1/messages/batches/{message_batch_id}/cancel?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">cancel</a>(messageBatchId, { ...params }) -> BetaMessageBatch</code>
193197
- <code title="get /v1/messages/batches/{message_batch_id}/results?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">results</a>(messageBatchId, { ...params }) -> Response</code>

src/resources/beta/messages/batches.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,35 @@ export class Batches extends APIResource {
8585
});
8686
}
8787

88+
/**
89+
* This endpoint is idempotent and can be used to poll for Message Batch
90+
* completion. To access the results of a Message Batch, make a request to the
91+
* `results_url` field in the response.
92+
*/
93+
delete(
94+
messageBatchId: string,
95+
params?: BatchDeleteParams,
96+
options?: Core.RequestOptions,
97+
): Core.APIPromise<BetaDeletedMessageBatch>;
98+
delete(messageBatchId: string, options?: Core.RequestOptions): Core.APIPromise<BetaDeletedMessageBatch>;
99+
delete(
100+
messageBatchId: string,
101+
params: BatchDeleteParams | Core.RequestOptions = {},
102+
options?: Core.RequestOptions,
103+
): Core.APIPromise<BetaDeletedMessageBatch> {
104+
if (isRequestOptions(params)) {
105+
return this.delete(messageBatchId, {}, params);
106+
}
107+
const { betas } = params;
108+
return this._client.delete(`/v1/messages/batches/${messageBatchId}?beta=true`, {
109+
...options,
110+
headers: {
111+
'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString(),
112+
...options?.headers,
113+
},
114+
});
115+
}
116+
88117
/**
89118
* Batches may be canceled any time before processing ends. Once cancellation is
90119
* initiated, the batch enters a `canceling` state, at which time the system may
@@ -168,6 +197,20 @@ export class Batches extends APIResource {
168197

169198
export class BetaMessageBatchesPage extends Page<BetaMessageBatch> {}
170199

200+
export interface BetaDeletedMessageBatch {
201+
/**
202+
* ID of the Message Batch.
203+
*/
204+
id: string;
205+
206+
/**
207+
* Deleted object type.
208+
*
209+
* For Message Batches, this is always `"message_batch_deleted"`.
210+
*/
211+
type: 'message_batch_deleted';
212+
}
213+
171214
export interface BetaMessageBatch {
172215
/**
173216
* Unique object identifier.
@@ -374,6 +417,13 @@ export interface BatchListParams extends PageParams {
374417
betas?: Array<BetaAPI.AnthropicBeta>;
375418
}
376419

420+
export interface BatchDeleteParams {
421+
/**
422+
* Optional header to specify the beta version(s) you want to use.
423+
*/
424+
betas?: Array<BetaAPI.AnthropicBeta>;
425+
}
426+
377427
export interface BatchCancelParams {
378428
/**
379429
* Optional header to specify the beta version(s) you want to use.
@@ -392,6 +442,7 @@ Batches.BetaMessageBatchesPage = BetaMessageBatchesPage;
392442

393443
export declare namespace Batches {
394444
export {
445+
type BetaDeletedMessageBatch as BetaDeletedMessageBatch,
395446
type BetaMessageBatch as BetaMessageBatch,
396447
type BetaMessageBatchCanceledResult as BetaMessageBatchCanceledResult,
397448
type BetaMessageBatchErroredResult as BetaMessageBatchErroredResult,
@@ -404,6 +455,7 @@ export declare namespace Batches {
404455
type BatchCreateParams as BatchCreateParams,
405456
type BatchRetrieveParams as BatchRetrieveParams,
406457
type BatchListParams as BatchListParams,
458+
type BatchDeleteParams as BatchDeleteParams,
407459
type BatchCancelParams as BatchCancelParams,
408460
type BatchResultsParams as BatchResultsParams,
409461
};

src/resources/beta/messages/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export {
44
BetaMessageBatchesPage,
55
Batches,
6+
type BetaDeletedMessageBatch,
67
type BetaMessageBatch,
78
type BetaMessageBatchCanceledResult,
89
type BetaMessageBatchErroredResult,
@@ -14,6 +15,7 @@ export {
1415
type BatchCreateParams,
1516
type BatchRetrieveParams,
1617
type BatchListParams,
18+
type BatchDeleteParams,
1719
type BatchCancelParams,
1820
type BatchResultsParams,
1921
} from './batches';

src/resources/beta/messages/messages.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ import * as BatchesAPI from './batches';
1010
import {
1111
BatchCancelParams,
1212
BatchCreateParams,
13+
BatchDeleteParams,
1314
BatchListParams,
1415
BatchResultsParams,
1516
BatchRetrieveParams,
1617
Batches,
18+
BetaDeletedMessageBatch,
1719
BetaMessageBatch,
1820
BetaMessageBatchCanceledResult,
1921
BetaMessageBatchErroredResult,
@@ -1115,6 +1117,7 @@ export declare namespace Messages {
11151117

11161118
export {
11171119
Batches as Batches,
1120+
type BetaDeletedMessageBatch as BetaDeletedMessageBatch,
11181121
type BetaMessageBatch as BetaMessageBatch,
11191122
type BetaMessageBatchCanceledResult as BetaMessageBatchCanceledResult,
11201123
type BetaMessageBatchErroredResult as BetaMessageBatchErroredResult,
@@ -1127,6 +1130,7 @@ export declare namespace Messages {
11271130
type BatchCreateParams as BatchCreateParams,
11281131
type BatchRetrieveParams as BatchRetrieveParams,
11291132
type BatchListParams as BatchListParams,
1133+
type BatchDeleteParams as BatchDeleteParams,
11301134
type BatchCancelParams as BatchCancelParams,
11311135
type BatchResultsParams as BatchResultsParams,
11321136
};

src/resources/messages/batches.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ export class Batches extends APIResource {
4949
return this._client.getAPIList('/v1/messages/batches', MessageBatchesPage, { query, ...options });
5050
}
5151

52+
/**
53+
* This endpoint is idempotent and can be used to poll for Message Batch
54+
* completion. To access the results of a Message Batch, make a request to the
55+
* `results_url` field in the response.
56+
*/
57+
delete(messageBatchId: string, options?: Core.RequestOptions): Core.APIPromise<DeletedMessageBatch> {
58+
return this._client.delete(`/v1/messages/batches/${messageBatchId}`, options);
59+
}
60+
5261
/**
5362
* Batches may be canceled any time before processing ends. Once cancellation is
5463
* initiated, the batch enters a `canceling` state, at which time the system may
@@ -90,6 +99,20 @@ export class Batches extends APIResource {
9099

91100
export class MessageBatchesPage extends Page<MessageBatch> {}
92101

102+
export interface DeletedMessageBatch {
103+
/**
104+
* ID of the Message Batch.
105+
*/
106+
id: string;
107+
108+
/**
109+
* Deleted object type.
110+
*
111+
* For Message Batches, this is always `"message_batch_deleted"`.
112+
*/
113+
type: 'message_batch_deleted';
114+
}
115+
93116
export interface MessageBatch {
94117
/**
95118
* Unique object identifier.
@@ -283,6 +306,7 @@ Batches.MessageBatchesPage = MessageBatchesPage;
283306

284307
export declare namespace Batches {
285308
export {
309+
type DeletedMessageBatch as DeletedMessageBatch,
286310
type MessageBatch as MessageBatch,
287311
type MessageBatchCanceledResult as MessageBatchCanceledResult,
288312
type MessageBatchErroredResult as MessageBatchErroredResult,

src/resources/messages/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export {
44
MessageBatchesPage,
55
Batches,
6+
type DeletedMessageBatch,
67
type MessageBatch,
78
type MessageBatchCanceledResult,
89
type MessageBatchErroredResult,

src/resources/messages/messages.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
BatchCreateParams,
1010
BatchListParams,
1111
Batches,
12+
DeletedMessageBatch,
1213
MessageBatch,
1314
MessageBatchCanceledResult,
1415
MessageBatchErroredResult,
@@ -1114,6 +1115,7 @@ export declare namespace Messages {
11141115

11151116
export {
11161117
Batches as Batches,
1118+
type DeletedMessageBatch as DeletedMessageBatch,
11171119
type MessageBatch as MessageBatch,
11181120
type MessageBatchCanceledResult as MessageBatchCanceledResult,
11191121
type MessageBatchErroredResult as MessageBatchErroredResult,

tests/api-resources/beta/messages/batches.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,35 @@ describe('resource batches', () => {
132132
).rejects.toThrow(Anthropic.NotFoundError);
133133
});
134134

135+
test('delete', async () => {
136+
const responsePromise = client.beta.messages.batches.delete('message_batch_id');
137+
const rawResponse = await responsePromise.asResponse();
138+
expect(rawResponse).toBeInstanceOf(Response);
139+
const response = await responsePromise;
140+
expect(response).not.toBeInstanceOf(Response);
141+
const dataAndResponse = await responsePromise.withResponse();
142+
expect(dataAndResponse.data).toBe(response);
143+
expect(dataAndResponse.response).toBe(rawResponse);
144+
});
145+
146+
test('delete: request options instead of params are passed correctly', async () => {
147+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
148+
await expect(
149+
client.beta.messages.batches.delete('message_batch_id', { path: '/_stainless_unknown_path' }),
150+
).rejects.toThrow(Anthropic.NotFoundError);
151+
});
152+
153+
test('delete: request options and params are passed correctly', async () => {
154+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
155+
await expect(
156+
client.beta.messages.batches.delete(
157+
'message_batch_id',
158+
{ betas: ['string'] },
159+
{ path: '/_stainless_unknown_path' },
160+
),
161+
).rejects.toThrow(Anthropic.NotFoundError);
162+
});
163+
135164
test('cancel', async () => {
136165
const responsePromise = client.beta.messages.batches.cancel('message_batch_id');
137166
const rawResponse = await responsePromise.asResponse();

tests/api-resources/messages/batches.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@ describe('resource batches', () => {
118118
).rejects.toThrow(Anthropic.NotFoundError);
119119
});
120120

121+
test('delete', async () => {
122+
const responsePromise = client.messages.batches.delete('message_batch_id');
123+
const rawResponse = await responsePromise.asResponse();
124+
expect(rawResponse).toBeInstanceOf(Response);
125+
const response = await responsePromise;
126+
expect(response).not.toBeInstanceOf(Response);
127+
const dataAndResponse = await responsePromise.withResponse();
128+
expect(dataAndResponse.data).toBe(response);
129+
expect(dataAndResponse.response).toBe(rawResponse);
130+
});
131+
132+
test('delete: request options instead of params are passed correctly', async () => {
133+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
134+
await expect(
135+
client.messages.batches.delete('message_batch_id', { path: '/_stainless_unknown_path' }),
136+
).rejects.toThrow(Anthropic.NotFoundError);
137+
});
138+
121139
test('cancel', async () => {
122140
const responsePromise = client.messages.batches.cancel('message_batch_id');
123141
const rawResponse = await responsePromise.asResponse();

0 commit comments

Comments
 (0)