pub enum Auth {
ApiKey(SecretString),
FromEnv,
ClaudeCli,
OAuth {
token: SecretString,
},
Resolved(Credential),
Bedrock {
region: String,
},
Vertex {
project: String,
region: String,
},
Foundry {
resource: String,
},
}Expand description
Primary authentication configuration for SDK usage.
Auth provides a unified interface for all authentication methods.
Use this enum to configure how the SDK authenticates with Claude API.
§Variants
ApiKey: Direct API key authenticationFromEnv: Load API key from ANTHROPIC_API_KEY environment variableClaudeCli: Use credentials from Claude Code CLI (requirescli-integrationfeature)OAuth: OAuth token authenticationResolved: Pre-resolved credential (for testing or credential reuse)Bedrock: AWS Bedrock (requiresawsfeature)Vertex: GCP Vertex AI (requiresgcpfeature)Foundry: Azure Foundry (requiresazurefeature)
Variants§
ApiKey(SecretString)
FromEnv
ClaudeCli
Available on crate feature
cli-integration only.OAuth
Fields
§
token: SecretStringResolved(Credential)
Bedrock
Available on crate feature
aws only.Vertex
Available on crate feature
gcp only.Foundry
Available on crate feature
azure only.Implementations§
Source§impl Auth
impl Auth
pub fn api_key(key: impl Into<String>) -> Self
pub fn from_env() -> Self
pub fn claude_cli() -> Self
Available on crate feature
cli-integration only.pub fn oauth(token: impl Into<String>) -> Self
pub fn bedrock(region: impl Into<String>) -> Self
Available on crate feature
aws only.pub fn vertex(project: impl Into<String>, region: impl Into<String>) -> Self
Available on crate feature
gcp only.pub fn foundry(resource: impl Into<String>) -> Self
Available on crate feature
azure only.pub fn resolved(credential: Credential) -> Self
pub async fn resolve(&self) -> Result<Credential>
Sourcepub async fn resolve_with_provider(
&self,
) -> Result<(Credential, Option<Arc<dyn CredentialProvider>>)>
pub async fn resolve_with_provider( &self, ) -> Result<(Credential, Option<Arc<dyn CredentialProvider>>)>
Returns (credential, optional_provider) for auth methods that support token refresh.
pub fn is_cloud_provider(&self) -> bool
pub fn is_oauth(&self) -> bool
Sourcepub fn supports_server_tools(&self) -> bool
pub fn supports_server_tools(&self) -> bool
Check if Anthropic’s server-side tools (WebSearch, WebFetch) are available.
Server-side tools are available with Anthropic direct API (API Key or OAuth) but NOT with cloud providers (Bedrock, Vertex, Foundry).
Trait Implementations§
Source§impl From<Credential> for Auth
impl From<Credential> for Auth
Source§fn from(credential: Credential) -> Self
fn from(credential: Credential) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for Auth
impl RefUnwindSafe for Auth
impl Send for Auth
impl Sync for Auth
impl Unpin for Auth
impl UnwindSafe for Auth
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.