anthropics / anthropic-sdk-typescript

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

keep getting 403 'forbidden' 'Request not allowed' when trying demo #457

Closed KolvacS-W closed 2 months ago

KolvacS-W commented 3 months ago

Hello, I am a tier1 user and successfully tried to use model at workbench:

Screen Shot 2024-07-02 at 5 57 31 PM

However, when I try to create a ts server to call Claude API, I keep having forbidden error.

I also tried to use the demo:

#!/usr/bin/env -S npm run tsn -T

import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
    apiKey: 'my_key',
}); 

console.log(client.apiKey)

async function main() {
  const result = await client.messages.create({
    messages: [
      {
        role: 'user',
        content: 'Hey Claude!?',
      },
    ],
    model: 'claude-3-5-sonnet-20240620',
    max_tokens: 1024,
  });
  console.dir(result);
}

main();

But I still get 403 error:

PermissionDeniedError: 403 {"error":{"type":"forbidden","message":"Request not allowed"}}

{status: 403,
  headers: {
    'cf-ray': '89cdc7d74e3e2512-SJC',
    connection: 'keep-alive',
    'content-encoding': 'gzip',
    'content-type': 'application/json',
    date: 'Tue, 02 Jul 2024 09:59:01 GMT',
    server: 'cloudflare',
    'transfer-encoding': 'chunked',
    vary: 'Accept-Encoding'
  },
  error: { error: { type: 'forbidden', message: 'Request not allowed' } }
}

I also printed out checked my API key to check it is correctly placed. I also tried changing IP address from US to Australia but it didn't help too.

Anybody knows why this would happen? Thanks

KC-Zhang commented 2 months ago

please fix. same problem here. Curl and python sdk both work

dgellow commented 2 months ago

Hi, I am not able to reproduce the issue and that feels like a problem on Anthropic side. The demo example does authenticate correctly as far as I can tell.

Could you try the following from the root of the repository:

If you're still facing the same problem, please reach out to Anthropic support with details to help them figure out why requests sent with API Key are rejected.

rattrayalex commented 2 months ago

I'm going to go ahead and close this issue because it seems more likely to be a problem with your API key than the SDK. If you're able to share repro steps of using the same ANTHROPIC_API_KEY environment variable in both the Python & Node SDK, and the request only fails in the Node SDK, we can reopen.