pub struct Secret {
pub ANTHROPIC_API_KEY: String,
}Expand description
Anthropic API key secret
§Examples
use api_claude::Secret;
// Create a secret with valid API key
let secret = Secret::new( "sk-ant-api03-example".to_string() ).unwrap();
// Invalid keys will return an error
let invalid_secret = Secret::new( "invalid-key".to_string() );
assert!( invalid_secret.is_err() );
// Empty keys will return an error
let empty_secret = Secret::new( "".to_string() );
assert!( empty_secret.is_err() );Fields§
§ANTHROPIC_API_KEY: StringAnthropic API key
Implementations§
Source§impl Secret
Extension methods for Secret
impl Secret
Extension methods for Secret
Sourcepub fn new_with_validation(
api_key: String,
required_prefix: &str,
min_length: Option<usize>,
max_length: Option<usize>,
) -> AnthropicResult<Self>
pub fn new_with_validation( api_key: String, required_prefix: &str, min_length: Option<usize>, max_length: Option<usize>, ) -> AnthropicResult<Self>
Create secret with explicit validation requirements
§Errors
Returns an error if API key fails explicit validation requirements
Sourcepub fn new_validated(api_key: String) -> AnthropicResult<Self>
pub fn new_validated(api_key: String) -> AnthropicResult<Self>
Create secret with enhanced validation (compatibility wrapper for tests)
§Errors
Returns an error if API key validation fails
NOTE: This is a compatibility wrapper for tests. Use new_with_validation() for explicit control.
Sourcepub fn load_with_precedence(env_vars: &[&str]) -> AnthropicResult<Self>
pub fn load_with_precedence(env_vars: &[&str]) -> AnthropicResult<Self>
Load secret with environment variable precedence
§Errors
Returns an error if no valid environment variable is found
Source§impl Secret
impl Secret
Sourcepub fn new(api_key: String) -> Result<Self>
pub fn new(api_key: String) -> Result<Self>
Create new secret with API key
§Errors
Returns an error if the API key is empty or has invalid format
Sourcepub fn new_unchecked(api_key: String) -> Self
pub fn new_unchecked(api_key: String) -> Self
Create secret without validation (for testing)
Sourcepub fn load_from_env(env_var: &str) -> Result<Self>
pub fn load_from_env(env_var: &str) -> Result<Self>
Load secret from environment variable
§Errors
Returns an error if the environment variable is not found or the API key is invalid
Sourcepub fn load_from_file(path: &Path) -> Result<Self>
pub fn load_from_file(path: &Path) -> Result<Self>
Sourcepub fn load_from_workspace(key_name: &str, filename: &str) -> Result<Self>
pub fn load_from_workspace(key_name: &str, filename: &str) -> Result<Self>
Load from workspace secrets (workspace_tools pattern)
§Errors
Returns an error if workspace loading fails or the API key is invalid
Sourcepub fn from_workspace() -> Result<Self>
pub fn from_workspace() -> Result<Self>
Load secret from workspace with default settings
§Errors
Returns an error if workspace loading fails or the API key is invalid