Skip to main content

Crate aigw_anthropic

Crate aigw_anthropic 

Source
Expand description

Anthropic API client for the AI Gateway.

This crate provides a typed Rust client for the Anthropic API, including non-streaming and SSE streaming support.

§Features

  • claude-code — Enables non-standard endpoints used by Claude Code (/api/event_logging/batch, /v1/oauth/token).

§Quick Start

use aigw_anthropic::{Client, Transport, TransportConfig, MessagesRequest, Message, MessageContent, Role};
use secrecy::SecretString;

let transport = Transport::new(TransportConfig {
    api_key: SecretString::from("sk-ant-..."),
    ..Default::default()
})?;
let client = Client::new(transport)?;

let req = MessagesRequest::builder()
    .model("claude-sonnet-4-20250514")
    .messages(vec![Message {
        role: Role::User,
        content: MessageContent::Text("Hello, Claude!".into()),
    }])
    .max_tokens(1024)
    .build();

let resp = client.messages(&req).await?;
println!("{}", resp.body.id);

Re-exports§

pub use client::Client;
pub use error::Error;
pub use rate_limit::ApiResponse;
pub use rate_limit::RateLimitInfo;
pub use transport::AuthMode;
pub use transport::Transport;
pub use transport::TransportConfig;
pub use transport::TransportConfigError;
pub use types::*;

Modules§

client
Anthropic API client.
error
Error types for the Anthropic provider.
rate_limit
Rate limit information parsed from Anthropic API response headers.
streaming
SSE stream parser for Anthropic’s streaming Messages API.
translate
Translation layer: canonical ↔ Anthropic Messages API.
transport
HTTP transport layer for the Anthropic API.
types
Anthropic API wire types.