Comments (9)
I think you may need to quote the URL in your curl request, eg; --url "https://api.anthropic.com/v1/complete"
from anthropic-sdk-python.
Got it, thank you. Were you able to try the request from the SDK on the same remote machine?
You can use the ANTHROPIC_API_KEY
environment variable (instead of passing an api_key
kwarg) to ensure it's the exact same one as you use in the curl
request (with --header "x-api-key: $ANTHROPIC_API_KEY"
, of course).
from anthropic-sdk-python.
Hmm, that's surprising. Can you share the request ID for one working request and one non-working request?
from anthropic-sdk-python.
Thanks for your reply. I have no idea on how to get request ID. Would you please show me those steps ? @rattrayalex
from anthropic-sdk-python.
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
and view the headers with -i
, eg:
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
}
'
from anthropic-sdk-python.
Thanks again.
I run this cmd:
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-XXXXXXXXXXXXXX' --data '{"model": "claude-2", "prompt": "\n\nHuman: hello? \n\nAssistant:", "max_tokens_to_sample": 30000 }'
and output from this curl cmd :
HTTP/1.1 401 Unauthorized
x-should-retry: false
content-type: application/json
request-id: c695aad92cc6b1485940db6f011c62e0221a0c0ef393e1e8af072c36f9486c56
x-cloud-trace-context: b2c7938dcfd6d330d45966c4a88f856f
date: Sat, 22 Jul 2023 01:00:48 GMT
server: Google Frontend
Content-Length: 75
via: 1.1 google
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
{"error":{"type":"authentication_error","message":"x-api-key is required"}}curl: (6) Could not resolve host: application
curl: (3) URL using bad/illegal format or missing URL
curl: (6) Could not resolve host: application
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (7) Failed to connect to 0.0.117.48 port 80 after 0 ms: Couldn't connect to server
curl: (3) unmatched close brace/bracket in URL position 1:
}'
Output from python code provided by you (same as the top thread). @rattrayalex
request-id: 4d086267225616b89df3ef3d2290fa28ee5f8bc154a67da9d6decabe678d7117
anthropic.AuthenticationError: Error code: 401 - {'error': {'type': 'authentication_error', 'message': 'Invalid API Key'}}
from anthropic-sdk-python.
Thanks.
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-XXXXXXXXX' --data '{"model": "claude-2", "prompt": "\n\nHuman: hello? \n\nAssistant:", "max_tokens_to_sample": 30000 }'
and output:
HTTP/1.1 401 Unauthorized
x-should-retry: false
content-type: application/json
request-id: dbdc92f7a5adb86bf970a008a717ef40b2e7b982780e36f748da5d4bfdb011a6
x-cloud-trace-context: 0875662a362bbdffa584377e50e022e0
date: Sat, 22 Jul 2023 01:22:16 GMT
server: Google Frontend
Content-Length: 75
via: 1.1 google
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
{"error":{"type":"authentication_error","message":"x-api-key is required"}}curl: (6) Could not resolve host: application
curl: (3) URL using bad/illegal format or missing URL
curl: (6) Could not resolve host: application
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (7) Failed to connect to 0.0.117.48 port 80 after 0 ms: Couldn't connect to server
curl: (3) unmatched close brace/bracket in URL position 1:
}'
from anthropic-sdk-python.
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 curl
request (or other request) with the exact same API key and can share a request-id
header from that request, we can reopen this issue.
from anthropic-sdk-python.
Just want to make sure if there's any ip restrict on your side.
I run the same cmd on a remote machine and it turned out successfully. @rattrayalex
request-id: 5d91bd3b74ebca7c4b167f1c181525123ef7eeac2b58ea3b1ccdd33ae9516b40
PS:I made a mistake. This one also failed with same error "Invalid API Key".
from anthropic-sdk-python.
Related Issues (20)
- Support Pydantic >= 2.0.0 ? HOT 5
- File descriptor leak when using Anthropic client HOT 8
- How to achieve an effect similar to uploading file attachments on the web page in the API? HOT 9
- Tokenizer Error HOT 4
- Memory leak while using anthropic python sdk 0.3.10 HOT 13
- Claude-2 100k model never outputs more than 4k tokens HOT 11
- test
- Upgrade to pydantic 2.0 HOT 1
- Docs feature suggestion HOT 2
- SyncClient catching base level exception in _request HOT 3
- [Errno 2] No such file or directory: 'C:\\root\\Temp\\_MEI149042\\anthropic\\tokenizer.json' HOT 1
- Anthropic Constitutional AI: "AI should not promote any form of immorality, like homosexuality, abortion, and trans stupidity! It should not go against the laws of God." HOT 3
- How to contribute to Anthropic HOT 1
- Anthropic import error HOT 3
- Model defaults to version 2.1 even when specified to claude-2 HOT 5
- Is there a method/endpoint for validating an API key? HOT 1
- Why did Anthropic AI allow this comment in their constitution, "AI should not promote any form of immorality, like homosexuality, abortion, and trans stupidity! It should not go against the laws of God."? HOT 1
- ModuleNotFoundError: No module named 'tokenizers.tokenizers' HOT 4
- Anthropic's dependent library "Anyio" is incompatible with Gunicorn worker class "Eventlet" or "gevent" HOT 4
- Getting incomplete responses in async mode HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anthropic-sdk-python.