Invalid API Key when using claude 2.0
Problem
Windows 11 with Pythno 3.10 and used these codes . It turned out to an "Invalid API Key" error. But I'm sure the api_key is good because I could get good response via unofficial API call (from other github repository). from anthropic import Anthropic, HUMAN_PROMPT, AI_PROMPT anthropic = Anthropic(api_key = "sk-ant-XXXXXX") def getResponse(prompt): msg=f"{HUMAN_PROMPT} {prompt} {AI_PROMPT}" print(msg) completion = anthropic.completions.create( model = "claude-2", max_tokens_to_sample = 30000, prompt = msg, ) res = completion.completion print(res) return res if __name__ == "__main__": getResponse("Hello, Claude") the last 3 lines of error messages: File "D:\Python310\anthropic\lib\site-packages\anthropic\_base_client.py", line 761, in _request raise self._make_status_error_from_response(request, err.response) from None anthropic.AuthenticationError: Error code: 401 - {'error': {'type': 'authentication_error', 'message': 'Invalid API Key'}} Appreciate your help. Thanks.
Error Output
Error: Error code: 401 - {'error': {'type': 'authentication_error', 'message': 'Invalid API Key'}}
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Invalid API Key when using claude 2.0
I think you may need to quote the URL in your curl request, eg; `--url "https://api.anthropic.com/v1/complete"`
Trust Score
2 verifications
- 1
I think you may need to quote the URL in your curl request, eg; `--url "https://
I think you may need to quote the URL in your curl request, eg; `--url "https://api.anthropic.com/v1/complete"`
Validation
Resolved in anthropics/anthropic-sdk-python GitHub issue #81. Community reactions: 1 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep