Skip to content

Commit c7557f1

Browse files
RobertCraigiestainless-app[bot]
authored andcommitted
chore(api): deprecate claude-1 models
1 parent 40ebb5f commit c7557f1

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/resources/messages.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ export class Messages extends APIResource {
3232
body: MessageCreateParams,
3333
options?: Core.RequestOptions,
3434
): APIPromise<Message> | APIPromise<Stream<RawMessageStreamEvent>> {
35+
if (body.model in DEPRECATED_MODELS) {
36+
console.warn(
37+
`The model '${body.model}' is deprecated and will reach end-of-life on ${
38+
DEPRECATED_MODELS[body.model]
39+
}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`,
40+
);
41+
}
3542
return this._client.post('/v1/messages', {
3643
body,
3744
timeout: (this._client as any)._options.timeout ?? 600000,
@@ -221,6 +228,18 @@ export type Model =
221228
| 'claude-2.0'
222229
| 'claude-instant-1.2';
223230

231+
type DeprecatedModelsType = {
232+
[K in Model]?: string;
233+
};
234+
235+
const DEPRECATED_MODELS: DeprecatedModelsType = {
236+
'claude-1.3': 'November 6th, 2024',
237+
'claude-1.3-100k': 'November 6th, 2024',
238+
'claude-instant-1.1': 'November 6th, 2024',
239+
'claude-instant-1.1-100k': 'November 6th, 2024',
240+
'claude-instant-1.2': 'November 6th, 2024',
241+
};
242+
224243
export interface RawContentBlockDeltaEvent {
225244
delta: TextDelta | InputJSONDelta;
226245

tests/api-resources/messages.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,34 @@ describe('resource messages', () => {
7575
});
7676
});
7777
});
78+
79+
test('create: warns when using a deprecated model', async () => {
80+
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation();
81+
82+
await client.messages.create({
83+
max_tokens: 1024,
84+
messages: [{ content: 'Hello, world', role: 'user' }],
85+
model: 'claude-instant-1.2',
86+
});
87+
88+
expect(consoleSpy).toHaveBeenCalledWith(
89+
"The model 'claude-instant-1.2' is deprecated and will reach end-of-life on November 6th, 2024\n" +
90+
'Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.',
91+
);
92+
93+
consoleSpy.mockRestore();
94+
});
95+
96+
test('create: does not warn for non-deprecated models', async () => {
97+
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation();
98+
99+
await client.messages.create({
100+
max_tokens: 1024,
101+
messages: [{ content: 'Hello, world', role: 'user' }],
102+
model: 'claude-3-5-sonnet-20240620',
103+
});
104+
105+
expect(consoleSpy).not.toHaveBeenCalled();
106+
107+
consoleSpy.mockRestore();
108+
});

0 commit comments

Comments
 (0)