pub struct Anthropic { /* private fields */ }Expand description
Main Anthropic API client
Implementations§
Source§impl Anthropic
impl Anthropic
Sourcepub fn new(api_key: impl Into<String>) -> Result<Self>
pub fn new(api_key: impl Into<String>) -> Result<Self>
Create a new Anthropic client with the provided API key
Sourcepub fn with_config(config: ClientConfig) -> Result<Self>
pub fn with_config(config: ClientConfig) -> Result<Self>
Create a new Anthropic client with custom configuration
Sourcepub fn config(&self) -> &ClientConfig
pub fn config(&self) -> &ClientConfig
Get the current configuration
Sourcepub async fn test_connection(&self) -> Result<()>
pub async fn test_connection(&self) -> Result<()>
Test the connection by making a simple API call
Sourcepub fn messages(&self) -> MessagesResource<'_>
pub fn messages(&self) -> MessagesResource<'_>
Access to the Messages API
§Example
use agentik_sdk::{Anthropic, types::MessageCreateBuilder};
let client = Anthropic::from_env()?;
let message = client.messages().create(
MessageCreateBuilder::new("claude-3-5-sonnet-latest", 1024)
.user("Hello, Claude!")
.build()
).await?;
println!("Claude responded: {:?}", message.content);Sourcepub fn batches(&self) -> BatchesResource
pub fn batches(&self) -> BatchesResource
Access to the Message Batches API (Beta)
§Example
use agentik_sdk::{Anthropic, types::{BatchRequest, BatchCreateParams}};
let client = Anthropic::from_env()?;
let requests = vec![
BatchRequest::new("req1", "claude-3-5-sonnet-latest", 1024)
.user("Hello, world!")
.build(),
];
let batch = client.batches().create(
BatchCreateParams::new(requests)
).await?;
println!("Created batch: {}", batch.id);Sourcepub fn files(&self) -> FilesResource
pub fn files(&self) -> FilesResource
Access to the Files API (Beta)
§Example
use agentik_sdk::{Anthropic, FileUploadParams, FilePurpose};
let client = Anthropic::from_env()?;
let upload_params = FileUploadParams::new(
std::fs::read("document.pdf")?,
"document.pdf",
"application/pdf",
FilePurpose::Document,
);
let file_object = client.files().upload(upload_params).await?;
println!("Uploaded file: {}", file_object.id);Sourcepub fn models(&self) -> ModelsResource<'_>
pub fn models(&self) -> ModelsResource<'_>
Access to the Models API
§Example
use agentik_sdk::{Anthropic, ModelListParams, ModelRequirements, ModelCapability};
let client = Anthropic::from_env()?;
// List all models
let models = client.models().list(None).await?;
println!("Found {} models", models.data.len());
// Get specific model
let model = client.models().get("claude-3-5-sonnet-latest").await?;
println!("Model: {} ({})", model.display_name, model.id);
// Find best model for requirements
let requirements = ModelRequirements::new()
.require_vision()
.min_context_length(100000);
let best_model = client.models().find_best_model(&requirements).await?;
// Compare models
let comparison = client.models().compare_models(&[
"claude-3-5-sonnet-latest",
"claude-3-5-haiku-latest"
]).await?;
// Estimate costs
let cost = client.models().estimate_cost("claude-3-5-sonnet-latest", 1000, 500).await?;
println!("Estimated cost: ${:.4}", cost.final_cost_usd);Trait Implementations§
Auto Trait Implementations§
impl Freeze for Anthropic
impl !RefUnwindSafe for Anthropic
impl Send for Anthropic
impl Sync for Anthropic
impl Unpin for Anthropic
impl UnsafeUnpin for Anthropic
impl !UnwindSafe for Anthropic
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