diff --git a/src/resources/messages.ts b/src/resources/messages.ts index 84d2f6bd..2bcd89a1 100644 --- a/src/resources/messages.ts +++ b/src/resources/messages.ts @@ -32,6 +32,13 @@ export class Messages extends APIResource { body: MessageCreateParams, options?: Core.RequestOptions, ): APIPromise | APIPromise> { + if (body.model in DEPRECATED_MODELS) { + console.warn( + `The model '${body.model}' is deprecated and will reach end-of-life on ${ + DEPRECATED_MODELS[body.model] + }\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`, + ); + } return this._client.post('/v1/messages', { body, timeout: (this._client as any)._options.timeout ?? 600000, @@ -221,6 +228,18 @@ export type Model = | 'claude-2.0' | 'claude-instant-1.2'; +type DeprecatedModelsType = { + [K in Model]?: string; +}; + +const DEPRECATED_MODELS: DeprecatedModelsType = { + 'claude-1.3': 'November 6th, 2024', + 'claude-1.3-100k': 'November 6th, 2024', + 'claude-instant-1.1': 'November 6th, 2024', + 'claude-instant-1.1-100k': 'November 6th, 2024', + 'claude-instant-1.2': 'November 6th, 2024', +}; + export interface RawContentBlockDeltaEvent { delta: TextDelta | InputJSONDelta; diff --git a/tests/api-resources/messages.test.ts b/tests/api-resources/messages.test.ts index 99a74f80..5592a7c4 100644 --- a/tests/api-resources/messages.test.ts +++ b/tests/api-resources/messages.test.ts @@ -75,3 +75,34 @@ describe('resource messages', () => { }); }); }); + +test('create: warns when using a deprecated model', async () => { + const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(); + + await client.messages.create({ + max_tokens: 1024, + messages: [{ content: 'Hello, world', role: 'user' }], + model: 'claude-instant-1.2', + }); + + expect(consoleSpy).toHaveBeenCalledWith( + "The model 'claude-instant-1.2' is deprecated and will reach end-of-life on November 6th, 2024\n" + + 'Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.', + ); + + consoleSpy.mockRestore(); +}); + +test('create: does not warn for non-deprecated models', async () => { + const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(); + + await client.messages.create({ + max_tokens: 1024, + messages: [{ content: 'Hello, world', role: 'user' }], + model: 'claude-3-5-sonnet-20240620', + }); + + expect(consoleSpy).not.toHaveBeenCalled(); + + consoleSpy.mockRestore(); +});