form-extractor-prototype
form-extractor-prototype copied to clipboard
API Key issue
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?
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
should be as simple as changing the line in server.js to this
const anthropic = new Anthropic({
apiKey: process.env['ANTHROPIC_API_KEY']
});
PR2 solves this by adding .env
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
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?
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
seems like the issue is with not enough credit on your key, rather than a bug with this code.
I think this is resolved now, so closing. Thanks @user24 for the support :-)