Add Type Validation for API Key and Auth Token to Prevent Common Configuration Errors #408
+12
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While integrating the Anthropic API client, I encountered an issue where I mistakenly passed the api_key as a list instead of a string. This led to several hours of debugging to identify the root cause of the issue, as the current implementation does not explicitly validate the type of api_key and auth_token upon instantiation of the Anthropic client class.
To prevent such issues for other developers and to enhance the usability of the API client, I propose adding explicit type validation for both api_key and auth_token parameters within the init method of the Anthropic class. This small yet impactful change ensures that developers are immediately alerted with a clear and informative error message if the types of these parameters do not match the expected string type.
The proposed change has been implemented as follows: