form-extractor-prototype icon indicating copy to clipboard operation
form-extractor-prototype copied to clipboard

API Key issue

Open antangible opened this issue 10 months ago • 7 comments

Hi, I added my Anthropic API key in a .env file

ANTHROPIC_API_KEY=my_api_key

but doesn't work.

I get this console error message

Error in Claude API call: Error: Could not resolve authentication method. Expected either apiKey or authToken to be set. Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted

What am I wrong?

antangible avatar Apr 17 '24 07:04 antangible

Hi there,

I'm not actually using .env in the project right now (though I plan to) - you'll need to follow these instructions instead https://docs.anthropic.com/claude/docs/quickstart-guide#step-3-optional-set-up-your-api-key

timpaul avatar Apr 17 '24 12:04 timpaul

should be as simple as changing the line in server.js to this

const anthropic = new Anthropic({
  apiKey: process.env['ANTHROPIC_API_KEY']
});

user24 avatar Apr 17 '24 12:04 user24

PR2 solves this by adding .env

timpaul avatar Apr 17 '24 13:04 timpaul

should be as simple as changing the line in server.js to this

const anthropic = new Anthropic({
  apiKey: process.env['ANTHROPIC_API_KEY']
});

still not working

antangible avatar Apr 17 '24 14:04 antangible

works for me in latest version - or rather, I get a different error complaining that 12345 is an invalid key, because I haven't got a real key yet - but it proves that the env var hooks up correctly at least.

.env

ANTHROPIC_API_KEY=12345

server.js

const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });

you may need to npm start after changing the .env value or code.

What system are you using?

user24 avatar Apr 17 '24 18:04 user24

I added the API key in both .env file and server.js but this is what i get.

> [email protected] start
> node server

(node:71404) ExperimentalWarning: Import assertions are not a stable feature of the JavaScript language. Avoid relying on their current behavior and syntax as those might change in a future version of Node.js.
(Use `node --trace-warnings ...` to show where the warning was created)
(node:71404) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
Server running at http://localhost:3000
Error in Claude API call: BadRequestError: 400 {"type":"error","error":{"type":"invalid_request_error","message":"Your credit balance is too low to access the Claude API. Please go to Plans & Billing to upgrade or purchase credits."}}
    at APIError.generate (file:///Users/antoniomatera/Sites/form-extractor-prototype/node_modules/@anthropic-ai/sdk/error.mjs:36:20)
    at Anthropic.makeStatusError (file:///Users/antoniomatera/Sites/form-extractor-prototype/node_modules/@anthropic-ai/sdk/core.mjs:256:25)
    at Anthropic.makeRequest (file:///Users/antoniomatera/Sites/form-extractor-prototype/node_modules/@anthropic-ai/sdk/core.mjs:299:30)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///Users/antoniomatera/Sites/form-extractor-prototype/server.js:72:21 {
  status: 400,
  headers: {
    'cf-cache-status': 'DYNAMIC',
    'cf-ray': '87631c2339f8a25c-FCO',
    connection: 'keep-alive',
    'content-length': '187',
    'content-type': 'application/json',
    date: 'Thu, 18 Apr 2024 07:58:29 GMT',
    'request-id': 'req_01JqE31kQwKVXVf9dzRsGA17',
    server: 'cloudflare',
    via: '1.1 google',
    'x-cloud-trace-context': '410261d9019d9cd5df32c9f0382f5898',
    'x-should-retry': 'false'
  },
  error: {
    type: 'error',
    error: {
      type: 'invalid_request_error',
      message: 'Your credit balance is too low to access the Claude API. Please go to Plans & Billing to upgrade or purchase credits.'
    }
  }
}

I'm using macOs

antangible avatar Apr 18 '24 08:04 antangible

seems like the issue is with not enough credit on your key, rather than a bug with this code.

user24 avatar Apr 18 '24 09:04 user24

I think this is resolved now, so closing. Thanks @user24 for the support :-)

timpaul avatar Apr 23 '24 09:04 timpaul