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 load_with_precedence(env_vars: &[&str]) -> AnthropicResult<Self>
pub fn load_with_precedence(env_vars: &[&str]) -> AnthropicResult<Self>
Load secret trying each environment variable in order; return first valid one found
§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
Sourcepub fn load_from_shell_file(path: &Path, key_name: &str) -> Result<Self>
pub fn load_from_shell_file(path: &Path, key_name: &str) -> Result<Self>
Load secret from an explicit shell-format file path
Unlike load_from_workspace, this method does not search for a secret/ directory —
it reads the named key directly from the file at path.
§Errors
Returns an error if the file cannot be read, the key is not found, or the key is invalid