From 84d03f1da4e244e09aa3d38099eb44aabc3f82cd Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Thu, 19 Dec 2024 23:06:31 +0000 Subject: [PATCH] feat(api): add message batch delete endpoint --- .stats.yml | 4 +- api.md | 4 ++ src/resources/beta/messages/batches.ts | 52 +++++++++++++++++++ src/resources/beta/messages/index.ts | 2 + src/resources/beta/messages/messages.ts | 4 ++ src/resources/messages/batches.ts | 24 +++++++++ src/resources/messages/index.ts | 1 + src/resources/messages/messages.ts | 2 + .../beta/messages/batches.test.ts | 29 +++++++++++ tests/api-resources/messages/batches.test.ts | 18 +++++++ 10 files changed, 138 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 14c789bf..239e17b7 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ -configured_endpoints: 19 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-9563716c7b08b8936ba450ad05005d12cf5ca3b9a37fab8126ed372e422d6de6.yml +configured_endpoints: 21 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-fd67aea6883f1ee9e46f31a42d3940f0acb1749e787055bd9b9f278b20fa53ec.yml diff --git a/api.md b/api.md index 093810dc..d4a311ad 100644 --- a/api.md +++ b/api.md @@ -67,6 +67,7 @@ Methods: Types: +- DeletedMessageBatch - MessageBatch - MessageBatchCanceledResult - MessageBatchErroredResult @@ -81,6 +82,7 @@ Methods: - client.messages.batches.create({ ...params }) -> MessageBatch - client.messages.batches.retrieve(messageBatchId) -> MessageBatch - client.messages.batches.list({ ...params }) -> MessageBatchesPage +- client.messages.batches.delete(messageBatchId) -> DeletedMessageBatch - client.messages.batches.cancel(messageBatchId) -> MessageBatch - client.messages.batches.results(messageBatchId) -> Response @@ -172,6 +174,7 @@ Methods: Types: +- BetaDeletedMessageBatch - BetaMessageBatch - BetaMessageBatchCanceledResult - BetaMessageBatchErroredResult @@ -186,5 +189,6 @@ Methods: - client.beta.messages.batches.create({ ...params }) -> BetaMessageBatch - client.beta.messages.batches.retrieve(messageBatchId, { ...params }) -> BetaMessageBatch - client.beta.messages.batches.list({ ...params }) -> BetaMessageBatchesPage +- client.beta.messages.batches.delete(messageBatchId, { ...params }) -> BetaDeletedMessageBatch - client.beta.messages.batches.cancel(messageBatchId, { ...params }) -> BetaMessageBatch - client.beta.messages.batches.results(messageBatchId, { ...params }) -> Response diff --git a/src/resources/beta/messages/batches.ts b/src/resources/beta/messages/batches.ts index 7ed9c634..729b2d03 100644 --- a/src/resources/beta/messages/batches.ts +++ b/src/resources/beta/messages/batches.ts @@ -85,6 +85,35 @@ export class Batches extends APIResource { }); } + /** + * This endpoint is idempotent and can be used to poll for Message Batch + * completion. To access the results of a Message Batch, make a request to the + * `results_url` field in the response. + */ + delete( + messageBatchId: string, + params?: BatchDeleteParams, + options?: Core.RequestOptions, + ): Core.APIPromise; + delete(messageBatchId: string, options?: Core.RequestOptions): Core.APIPromise; + delete( + messageBatchId: string, + params: BatchDeleteParams | Core.RequestOptions = {}, + options?: Core.RequestOptions, + ): Core.APIPromise { + if (isRequestOptions(params)) { + return this.delete(messageBatchId, {}, params); + } + const { betas } = params; + return this._client.delete(`/v1/messages/batches/${messageBatchId}?beta=true`, { + ...options, + headers: { + 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString(), + ...options?.headers, + }, + }); + } + /** * Batches may be canceled any time before processing ends. Once cancellation is * initiated, the batch enters a `canceling` state, at which time the system may @@ -155,6 +184,20 @@ export class Batches extends APIResource { export class BetaMessageBatchesPage extends Page {} +export interface BetaDeletedMessageBatch { + /** + * ID of the Message Batch. + */ + id: string; + + /** + * Deleted object type. + * + * For Message Batches, this is always `"message_batch_deleted"`. + */ + type: 'message_batch_deleted'; +} + export interface BetaMessageBatch { /** * Unique object identifier. @@ -628,6 +671,13 @@ export interface BatchListParams extends PageParams { betas?: Array; } +export interface BatchDeleteParams { + /** + * Optional header to specify the beta version(s) you want to use. + */ + betas?: Array; +} + export interface BatchCancelParams { /** * Optional header to specify the beta version(s) you want to use. @@ -646,6 +696,7 @@ Batches.BetaMessageBatchesPage = BetaMessageBatchesPage; export declare namespace Batches { export { + type BetaDeletedMessageBatch as BetaDeletedMessageBatch, type BetaMessageBatch as BetaMessageBatch, type BetaMessageBatchCanceledResult as BetaMessageBatchCanceledResult, type BetaMessageBatchErroredResult as BetaMessageBatchErroredResult, @@ -658,6 +709,7 @@ export declare namespace Batches { type BatchCreateParams as BatchCreateParams, type BatchRetrieveParams as BatchRetrieveParams, type BatchListParams as BatchListParams, + type BatchDeleteParams as BatchDeleteParams, type BatchCancelParams as BatchCancelParams, type BatchResultsParams as BatchResultsParams, }; diff --git a/src/resources/beta/messages/index.ts b/src/resources/beta/messages/index.ts index 2cf85964..e6b260ab 100644 --- a/src/resources/beta/messages/index.ts +++ b/src/resources/beta/messages/index.ts @@ -3,6 +3,7 @@ export { BetaMessageBatchesPage, Batches, + type BetaDeletedMessageBatch, type BetaMessageBatch, type BetaMessageBatchCanceledResult, type BetaMessageBatchErroredResult, @@ -14,6 +15,7 @@ export { type BatchCreateParams, type BatchRetrieveParams, type BatchListParams, + type BatchDeleteParams, type BatchCancelParams, type BatchResultsParams, } from './batches'; diff --git a/src/resources/beta/messages/messages.ts b/src/resources/beta/messages/messages.ts index 7a038b84..b27b8a4e 100644 --- a/src/resources/beta/messages/messages.ts +++ b/src/resources/beta/messages/messages.ts @@ -10,10 +10,12 @@ import * as BatchesAPI from './batches'; import { BatchCancelParams, BatchCreateParams, + BatchDeleteParams, BatchListParams, BatchResultsParams, BatchRetrieveParams, Batches, + BetaDeletedMessageBatch, BetaMessageBatch, BetaMessageBatchCanceledResult, BetaMessageBatchErroredResult, @@ -1115,6 +1117,7 @@ export declare namespace Messages { export { Batches as Batches, + type BetaDeletedMessageBatch as BetaDeletedMessageBatch, type BetaMessageBatch as BetaMessageBatch, type BetaMessageBatchCanceledResult as BetaMessageBatchCanceledResult, type BetaMessageBatchErroredResult as BetaMessageBatchErroredResult, @@ -1127,6 +1130,7 @@ export declare namespace Messages { type BatchCreateParams as BatchCreateParams, type BatchRetrieveParams as BatchRetrieveParams, type BatchListParams as BatchListParams, + type BatchDeleteParams as BatchDeleteParams, type BatchCancelParams as BatchCancelParams, type BatchResultsParams as BatchResultsParams, }; diff --git a/src/resources/messages/batches.ts b/src/resources/messages/batches.ts index 177bf9b8..bcff9a1d 100644 --- a/src/resources/messages/batches.ts +++ b/src/resources/messages/batches.ts @@ -48,6 +48,15 @@ export class Batches extends APIResource { return this._client.getAPIList('/v1/messages/batches', MessageBatchesPage, { query, ...options }); } + /** + * This endpoint is idempotent and can be used to poll for Message Batch + * completion. To access the results of a Message Batch, make a request to the + * `results_url` field in the response. + */ + delete(messageBatchId: string, options?: Core.RequestOptions): Core.APIPromise { + return this._client.delete(`/v1/messages/batches/${messageBatchId}`, options); + } + /** * Batches may be canceled any time before processing ends. Once cancellation is * initiated, the batch enters a `canceling` state, at which time the system may @@ -80,6 +89,20 @@ export class Batches extends APIResource { export class MessageBatchesPage extends Page {} +export interface DeletedMessageBatch { + /** + * ID of the Message Batch. + */ + id: string; + + /** + * Deleted object type. + * + * For Message Batches, this is always `"message_batch_deleted"`. + */ + type: 'message_batch_deleted'; +} + export interface MessageBatch { /** * Unique object identifier. @@ -540,6 +563,7 @@ Batches.MessageBatchesPage = MessageBatchesPage; export declare namespace Batches { export { + type DeletedMessageBatch as DeletedMessageBatch, type MessageBatch as MessageBatch, type MessageBatchCanceledResult as MessageBatchCanceledResult, type MessageBatchErroredResult as MessageBatchErroredResult, diff --git a/src/resources/messages/index.ts b/src/resources/messages/index.ts index 4e23b650..e03753b6 100644 --- a/src/resources/messages/index.ts +++ b/src/resources/messages/index.ts @@ -3,6 +3,7 @@ export { MessageBatchesPage, Batches, + type DeletedMessageBatch, type MessageBatch, type MessageBatchCanceledResult, type MessageBatchErroredResult, diff --git a/src/resources/messages/messages.ts b/src/resources/messages/messages.ts index 68224db3..cdee9444 100644 --- a/src/resources/messages/messages.ts +++ b/src/resources/messages/messages.ts @@ -9,6 +9,7 @@ import { BatchCreateParams, BatchListParams, Batches, + DeletedMessageBatch, MessageBatch, MessageBatchCanceledResult, MessageBatchErroredResult, @@ -1059,6 +1060,7 @@ export declare namespace Messages { export { Batches as Batches, + type DeletedMessageBatch as DeletedMessageBatch, type MessageBatch as MessageBatch, type MessageBatchCanceledResult as MessageBatchCanceledResult, type MessageBatchErroredResult as MessageBatchErroredResult, diff --git a/tests/api-resources/beta/messages/batches.test.ts b/tests/api-resources/beta/messages/batches.test.ts index d7ee6516..7cf7c769 100644 --- a/tests/api-resources/beta/messages/batches.test.ts +++ b/tests/api-resources/beta/messages/batches.test.ts @@ -132,6 +132,35 @@ describe('resource batches', () => { ).rejects.toThrow(Anthropic.NotFoundError); }); + test('delete', async () => { + const responsePromise = client.beta.messages.batches.delete('message_batch_id'); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + test('delete: request options instead of params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect( + client.beta.messages.batches.delete('message_batch_id', { path: '/_stainless_unknown_path' }), + ).rejects.toThrow(Anthropic.NotFoundError); + }); + + test('delete: request options and params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect( + client.beta.messages.batches.delete( + 'message_batch_id', + { betas: ['string'] }, + { path: '/_stainless_unknown_path' }, + ), + ).rejects.toThrow(Anthropic.NotFoundError); + }); + test('cancel', async () => { const responsePromise = client.beta.messages.batches.cancel('message_batch_id'); const rawResponse = await responsePromise.asResponse(); diff --git a/tests/api-resources/messages/batches.test.ts b/tests/api-resources/messages/batches.test.ts index 2bd94878..1dc01561 100644 --- a/tests/api-resources/messages/batches.test.ts +++ b/tests/api-resources/messages/batches.test.ts @@ -119,6 +119,24 @@ describe('resource batches', () => { ).rejects.toThrow(Anthropic.NotFoundError); }); + test('delete', async () => { + const responsePromise = client.messages.batches.delete('message_batch_id'); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + test('delete: request options instead of params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect( + client.messages.batches.delete('message_batch_id', { path: '/_stainless_unknown_path' }), + ).rejects.toThrow(Anthropic.NotFoundError); + }); + test('cancel', async () => { const responsePromise = client.messages.batches.cancel('message_batch_id'); const rawResponse = await responsePromise.asResponse();