Description
Long story short:
Before trying out the Anthropic python sdk, I was using the OpenAI SDK.
The openai sdk requires
client = OpenAI(
api_key="ANTHROPIC_API_KEY", # Your Anthropic API key
base_url="https://api.anthropic.com/v1/" # Anthropic's API endpoint
)
So for ease of use, I've added a environmental variable
export ANTHROPIC_BASE_URL='https://api.anthropic.com/v1/'
Little did I know, the name I chose would cause issues down the line.
Today, I tried using the anthropic sdk, using the default setup
from anthropic import Anthropic
client = Anthropic()
but kept getting an extremely vague error
NotFoundError: Error code: 404 - {'type': 'error', 'error': {'type': 'not_found_error', 'message': 'Not Found'}}
I knew the API key was valid because:
- It worked with openai sdk
- curl commands didn't return any errors
After multiple back and forth messages with Claude embedded in the docs, he suggested to explicitly set the base_url parameter to "https://api.anthropic.com"
and voila, it works perfectly.
Going through the python sdk code, I noticed the following if-statement
if base_url is None:
base_url = os.environ.get("ANTHROPIC_BASE_URL")
if base_url is None:
base_url = f"https://api.anthropic.com"
So the issue was that the client, by default, read a variable with an incorrect value (for this particular use case).
My question is:
Is loading base_url, by default, from environment variables necessary?
Especially if the correct value is then hard coded and passed as an argument.