pub enum Auth {
ApiKey(String),
FromEnv,
ClaudeCli,
OAuth {
token: String,
},
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(String)
Direct API key authentication.
FromEnv
Load API key from ANTHROPIC_API_KEY environment variable.
ClaudeCli
cli-integration only.Use credentials from Claude Code CLI (~/.claude/credentials.json).
Requires cli-integration feature.
OAuth
OAuth token authentication.
Resolved(Credential)
Use a pre-resolved credential directly. Useful for testing, credential reuse, or custom credential sources.
Bedrock
aws only.Vertex
gcp only.Foundry
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
cli-integration only.pub fn oauth(token: impl Into<String>) -> Self
pub fn bedrock(region: impl Into<String>) -> Self
aws only.pub fn vertex(project: impl Into<String>, region: impl Into<String>) -> Self
gcp only.pub fn foundry(resource: impl Into<String>) -> Self
azure only.Sourcepub fn resolved(credential: Credential) -> Self
pub fn resolved(credential: Credential) -> Self
Use a pre-resolved credential directly.
Sourcepub async fn resolve(&self) -> Result<Credential>
pub async fn resolve(&self) -> Result<Credential>
Resolve authentication to internal credential format.
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>>)>
Resolve authentication and return both credential and provider.
Returns the credential provider for auth methods that support token refresh. This enables automatic 401 retry with credential 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
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
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>
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>
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 more