pub struct Client { /* private fields */ }
Expand description
Main entry point for the Anthropic API
By default will use the ANTHROPIC_API_KEY
environment variable
§Example
let client = async_anthropic::Client::default();
let request = CreateMessagesRequestBuilder::default()
.model("claude-3.5-sonnet")
.messages(vec![MessageBuilder::default()
.role(MessageRole::User)
.content("Hello world!")
.build()
.unwrap()])
.build()
.unwrap();
client.messages().create(request).await.unwrap();
Implementations§
Source§impl Client
impl Client
Sourcepub fn from_api_key(api_key: impl Into<SecretString>) -> Self
pub fn from_api_key(api_key: impl Into<SecretString>) -> Self
Build a new client from an API key
Sourcepub fn with_backoff(self, backoff: ExponentialBackoff) -> Self
pub fn with_backoff(self, backoff: ExponentialBackoff) -> Self
Set a custom backoff strategy
pub fn models(&self) -> Models<'_>
pub async fn get<O>(&self, path: &str) -> Result<O, AnthropicError>where
O: DeserializeOwned,
Sourcepub async fn post<I, O>(
&self,
path: &str,
request: I,
) -> Result<O, AnthropicError>where
I: Serialize,
O: DeserializeOwned,
pub async fn post<I, O>(
&self,
path: &str,
request: I,
) -> Result<O, AnthropicError>where
I: Serialize,
O: DeserializeOwned,
Make post request to the API
This includes all headers and error handling
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
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