#ERROR - Anthropic API error: Error code: 401 - {'error': {'type': 'authentication_error', 'message':

3 messages · Page 1 of 1 (latest)

night fulcrum
#

Hi, I try to add anthropic to my app,
def call_anthropic(user_message, max_tokens=1000, temperature=0):
model = "anthropic/claude-2"
client = Anthropic()
client.api_key = ANTHROPIC_API_KEY_ROUTER

max_retries = 5
for attempt in range(max_retries):
    try:
        results = client.completions.create(
            prompt=f"{anthropic.HUMAN_PROMPT}{user_message}{anthropic.AI_PROMPT}",
            model=model,
            max_tokens_to_sample=max_tokens,
            temperature=temperature,
        )
        result = results["completion"]
        stop_reason = results["stop_reason"]

    except Exception as e:
        logging.error("Anthropic API error: " + str(e) + "\n")
        if attempt < max_retries - 1:
            time.sleep(2)
            continue
        else:
            raise e
    
return result, stop_reason

but I keep getting anthropic.AuthenticationError: Error code: 401 - {'error': {'type': 'authentication_error', 'message': 'Invalid API Key'}}
could u help? i generated a new key from OR

#

@tepid phoenix

broken sentinel
#

How are you passing your key into the client?