Skip to content

Commit 2305dcb

Browse files
committed
Refactor error handling for missing API key in AnthropicProvider to use custom MissingApiKeyError
1 parent d2052c7 commit 2305dcb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/any_llm/providers/anthropic/anthropic.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from openai.types.chat.chat_completion_message import ChatCompletionMessage
1515
from openai.types.chat.chat_completion_message_tool_call import ChatCompletionMessageToolCall, Function
1616
from any_llm.provider import Provider, ApiConfig
17+
from any_llm.exceptions import MissingApiKeyError
1718

1819
# Define a constant for the default max_tokens value
1920
DEFAULT_MAX_TOKENS = 4096
@@ -186,8 +187,10 @@ def __init__(self, config: ApiConfig) -> None:
186187
if not config.api_key:
187188
config.api_key = os.getenv("ANTHROPIC_API_KEY")
188189
if not config.api_key:
189-
msg = "No Anthropic API key provided. Please provide it in the config or set the ANTHROPIC_API_KEY environment variable."
190-
raise ValueError(msg)
190+
raise MissingApiKeyError(
191+
"Anthropic",
192+
"ANTHROPIC_API_KEY",
193+
)
191194
self.client = Anthropic(api_key=config.api_key, base_url=config.api_base)
192195

193196
def completion(

0 commit comments

Comments
 (0)