FG
🤖 AI & LLMsAnthropic

Invalid API Key when using claude 2.0

Freshover 2 years ago
Mar 14, 20260 views
Confidence Score89%
89%

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

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate2 verificationsLast verified Mar 14, 2026

Solution: Invalid API Key when using claude 2.0

Low Risk

I think you may need to quote the URL in your curl request, eg; `--url "https://api.anthropic.com/v1/complete"`

84

Trust Score

2 verifications

100% success
  1. 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

Worked: 2
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

claudeanthropicllmapi