anthropics / anthropic-sdk-typescript

Access to Anthropic's safety-first language model APIs
https://www.npmjs.com/package/@anthropic-ai/sdk
MIT License
735 stars 79 forks source link

In the messageCreateParams, model name get clobbered to undefined if invalid #589

Closed dandv closed 3 weeks ago

dandv commented 3 weeks ago

I expect the params passed to client.messages.create to be left untouched. But the SDK adds an anthropic_version field, and if the model is invalid, it's reset to undefined:

import AnthropicBedrock from '@anthropic-ai/bedrock-sdk';
import type { MessageCreateParamsNonStreaming } from '@anthropic-ai/sdk/src/resources/messages';

const client = new AnthropicBedrock();

const messageCreateParams: Anthropic.MessageCreateParamsNonStreaming = {
  max_tokens: 1,
  messages: [{ role: 'user', content: 'What is the meaning of life?' }],
  model: 'invalid',
};

try {
  await client.messages.create(messageCreateParams);  // throws an error
} catch {
}

console.log(`Model is now: ${messageCreateParams.model}`);  // undefined
console.log(`Extra field in messageCreateParams: ${messageCreateParams['anthropic_version']}`);  // 'bedrock-2023-05-31'
RobertCraigie commented 3 weeks ago

Thanks for the bug report, I'm investigating.

RobertCraigie commented 3 weeks ago

This will be fixed in the next release https://github.com/anthropics/anthropic-sdk-typescript/pull/590