Skip to content

Commit 062b189

Browse files
feat(api): add message batch delete endpoint (#640)
1 parent 8fe82b8 commit 062b189

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
@@ -67,6 +67,7 @@ Methods:
6767

6868
Types:
6969

70+
- <code><a href="./src/resources/messages/batches.ts">DeletedMessageBatch</a></code>
7071
- <code><a href="./src/resources/messages/batches.ts">MessageBatch</a></code>
7172
- <code><a href="./src/resources/messages/batches.ts">MessageBatchCanceledResult</a></code>
7273
- <code><a href="./src/resources/messages/batches.ts">MessageBatchErroredResult</a></code>
@@ -81,6 +82,7 @@ Methods:
8182
- <code title="post /v1/messages/batches">client.messages.batches.<a href="./src/resources/messages/batches.ts">create</a>({ ...params }) -> MessageBatch</code>
8283
- <code title="get /v1/messages/batches/{message_batch_id}">client.messages.batches.<a href="./src/resources/messages/batches.ts">retrieve</a>(messageBatchId) -> MessageBatch</code>
8384
- <code title="get /v1/messages/batches">client.messages.batches.<a href="./src/resources/messages/batches.ts">list</a>({ ...params }) -> MessageBatchesPage</code>
85+
- <code title="delete /v1/messages/batches/{message_batch_id}">client.messages.batches.<a href="./src/resources/messages/batches.ts">delete</a>(messageBatchId) -> DeletedMessageBatch</code>
8486
- <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>
8587
- <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>
8688

@@ -172,6 +174,7 @@ Methods:
172174

173175
Types:
174176

177+
- <code><a href="./src/resources/beta/messages/batches.ts">BetaDeletedMessageBatch</a></code>
175178
- <code><a href="./src/resources/beta/messages/batches.ts">BetaMessageBatch</a></code>
176179
- <code><a href="./src/resources/beta/messages/batches.ts">BetaMessageBatchCanceledResult</a></code>
177180
- <code><a href="./src/resources/beta/messages/batches.ts">BetaMessageBatchErroredResult</a></code>
@@ -186,5 +189,6 @@ Methods:
186189
- <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>
187190
- <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>
188191
- <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>
192+
- <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>
189193
- <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>
190194
- <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
@@ -155,6 +184,20 @@ export class Batches extends APIResource {
155184

156185
export class BetaMessageBatchesPage extends Page<BetaMessageBatch> {}
157186

187+
export interface BetaDeletedMessageBatch {
188+
/**
189+
* ID of the Message Batch.
190+
*/
191+
id: string;
192+
193+
/**
194+
* Deleted object type.
195+
*
196+
* For Message Batches, this is always `"message_batch_deleted"`.
197+
*/
198+
type: 'message_batch_deleted';
199+
}
200+
158201
export interface BetaMessageBatch {
159202
/**
160203
* Unique object identifier.
@@ -628,6 +671,13 @@ export interface BatchListParams extends PageParams {
628671
betas?: Array<BetaAPI.AnthropicBeta>;
629672
}
630673

674+
export interface BatchDeleteParams {
675+
/**
676+
* Optional header to specify the beta version(s) you want to use.
677+
*/
678+
betas?: Array<BetaAPI.AnthropicBeta>;
679+
}
680+
631681
export interface BatchCancelParams {
632682
/**
633683
* Optional header to specify the beta version(s) you want to use.
@@ -646,6 +696,7 @@ Batches.BetaMessageBatchesPage = BetaMessageBatchesPage;
646696

647697
export declare namespace Batches {
648698
export {
699+
type BetaDeletedMessageBatch as BetaDeletedMessageBatch,
649700
type BetaMessageBatch as BetaMessageBatch,
650701
type BetaMessageBatchCanceledResult as BetaMessageBatchCanceledResult,
651702
type BetaMessageBatchErroredResult as BetaMessageBatchErroredResult,
@@ -658,6 +709,7 @@ export declare namespace Batches {
658709
type BatchCreateParams as BatchCreateParams,
659710
type BatchRetrieveParams as BatchRetrieveParams,
660711
type BatchListParams as BatchListParams,
712+
type BatchDeleteParams as BatchDeleteParams,
661713
type BatchCancelParams as BatchCancelParams,
662714
type BatchResultsParams as BatchResultsParams,
663715
};

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
@@ -48,6 +48,15 @@ export class Batches extends APIResource {
4848
return this._client.getAPIList('/v1/messages/batches', MessageBatchesPage, { query, ...options });
4949
}
5050

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

8190
export class MessageBatchesPage extends Page<MessageBatch> {}
8291

92+
export interface DeletedMessageBatch {
93+
/**
94+
* ID of the Message Batch.
95+
*/
96+
id: string;
97+
98+
/**
99+
* Deleted object type.
100+
*
101+
* For Message Batches, this is always `"message_batch_deleted"`.
102+
*/
103+
type: 'message_batch_deleted';
104+
}
105+
83106
export interface MessageBatch {
84107
/**
85108
* Unique object identifier.
@@ -540,6 +563,7 @@ Batches.MessageBatchesPage = MessageBatchesPage;
540563

541564
export declare namespace Batches {
542565
export {
566+
type DeletedMessageBatch as DeletedMessageBatch,
543567
type MessageBatch as MessageBatch,
544568
type MessageBatchCanceledResult as MessageBatchCanceledResult,
545569
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,
@@ -1059,6 +1060,7 @@ export declare namespace Messages {
10591060

10601061
export {
10611062
Batches as Batches,
1063+
type DeletedMessageBatch as DeletedMessageBatch,
10621064
type MessageBatch as MessageBatch,
10631065
type MessageBatchCanceledResult as MessageBatchCanceledResult,
10641066
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
@@ -119,6 +119,24 @@ describe('resource batches', () => {
119119
).rejects.toThrow(Anthropic.NotFoundError);
120120
});
121121

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

0 commit comments

Comments
 (0)