Skip to main content

Crate anthropic_async

Crate anthropic_async 

Source
Expand description

§anthropic-async

A production-ready Anthropic API client for Rust with prompt caching support.

§Quick Start

use anthropic_async::{Client, types::{content::*, messages::*}};

let client = Client::new();

let req = MessagesCreateRequest {
    model: "claude-3-5-sonnet".into(),
    max_tokens: 100,
    messages: vec![MessageParam {
        role: MessageRole::User,
        content: "Hello!".into(),
    }],
    system: None,
    temperature: None,
    stop_sequences: None,
    top_p: None,
    top_k: None,
    metadata: None,
    tools: None,
    tool_choice: None,
    stream: None,
    output_format: None,
};

let response = client.messages().create(req).await?;

§Authentication

The client supports API key and bearer token authentication. See AnthropicConfig for configuration options.

§Prompt Caching

Use CacheControl to cache prompts and reduce costs.

Re-exports§

pub use crate::client::Client;
pub use crate::config::AnthropicAuth;
pub use crate::config::AnthropicConfig;
pub use crate::config::BetaFeature;
pub use crate::error::AnthropicError;
pub use crate::error::ApiErrorObject;

Modules§

client
HTTP client implementation
config
Configuration types for the client
error
Error types
prelude
Prelude module for convenient imports
resources
API resource implementations API resource implementations for the Anthropic client
retry
Retry logic utilities
types
Request and response types Type definitions for Anthropic API requests and responses