anthropics / anthropic-sdk-typescript

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

How to use Anthropic API with OpenAI SDK? #620

Closed punkpeye closed 6 hours ago

punkpeye commented 6 hours ago

I have tried:

if (llmProviderNid === 'anthropic') {
  return new OpenAI({
    apiKey: config.ANTHROPIC_API_KEY,
    baseURL: 'https://api.anthropic.com/v1',
    dangerouslyAllowBrowser: config.VITEST,
  });
}

but I am getting:

AuthenticationError: 401 Invalid bearer token

The token itself is correct, so I suspect the error is elsewhere.

RobertCraigie commented 6 hours ago

sorry I'm confused, why are you trying to use the OpenAI SDK with the Anthropic API? this repo is for the Anthropic SDK

punkpeye commented 6 hours ago

sorry I'm confused, why are you trying to use the OpenAI SDK with the Anthropic API? this repo is for the Anthropic SDK

Because they are supposed to be compatible APIs.

RobertCraigie commented 6 hours ago

Where did you see that claim? The APIs are not compatible.

punkpeye commented 6 hours ago

yikes. looks like it is indeed incompatible. well that sucks