-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid API Key when using claude 2.0 #81
Comments
Hmm, that's surprising. Can you share the request ID for one working request and one non-working request? |
Thanks for your reply. I have no idea on how to get request ID. Would you please show me those steps ? @rattrayalex |
In this library, it's like this: from anthropic import Anthropic, HUMAN_PROMPT, AI_PROMPT, APIStatusError
anthropic = Anthropic(api_key="sk-ant-XXXXXX")
def getResponse(prompt):
msg=f"{HUMAN_PROMPT} {prompt} {AI_PROMPT}"
print(msg)
try:
completion = anthropic.completions.create(
model="claude-2",
max_tokens_to_sample=30000,
prompt=msg,
)
except APIStatusError as e:
print('request-id:', e.response.headers['request-id'])
raise e
res = completion.completion
print(res)
return res Outside of this library, you can make a request with curl -i --request POST \
--url https://api.anthropic.com/v1/complete \
--header 'accept: application/json' \
--header 'anthropic-version: 2023-06-01' \
--header 'content-type: application/json' \
--header 'x-api-key: sk-ant-XXXXXX' \
--data '
{
"model": "claude-2",
"prompt": "\n\nHuman: hello? \n\nAssistant:"
"max_tokens_to_sample": 30000
}
' |
Thanks again. and output from this curl cmd : {"error":{"type":"authentication_error","message":"x-api-key is required"}}curl: (6) Could not resolve host: application Output from python code provided by you (same as the top thread). @rattrayalex |
I think you may need to quote the URL in your curl request, eg; |
Thanks. and output: {"error":{"type":"authentication_error","message":"x-api-key is required"}}curl: (6) Could not resolve host: application |
It looks like you're having some trouble sending a valid curl request. Once you're able to show that you can make a successful |
Just want to make sure if there's any ip restrict on your side. request-id: 5d91bd3b74ebca7c4b167f1c181525123ef7eeac2b58ea3b1ccdd33ae9516b40 PS:I made a mistake. This one also failed with same error "Invalid API Key". |
Got it, thank you. Were you able to try the request from the SDK on the same remote machine? You can use the |
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.
The text was updated successfully, but these errors were encountered: