claude-api
Type-safe Rust client for the Anthropic API.
Workspace
| Crate | Description |
|---|---|
claude-api |
The SDK |
claude-api-derive |
#[derive(Tool)] proc-macro (re-exported via the derive feature) |
claude-api-test |
Cassette-based replay + recorder for integration tests |
Quick start
[]
= "0.5"
= { = "1", = ["macros", "rt-multi-thread"] }
use ;
async
See crates/claude-api/examples/ for
streaming, streaming-with-callbacks, tool use, derived tools, vision,
document, conversation, and the agent loop.
API surface
Every documented Anthropic endpoint is reachable through a typed
namespace handle off [Client]:
| Namespace | Endpoints | Feature flag |
|---|---|---|
client.messages() |
create, count_tokens, streaming | (default) |
client.models() |
list, get | (default) |
client.batches() |
create, get, list, cancel, delete, results, wait_for | (default) |
client.files() |
upload, get, list, delete, download | (default) |
client.skills() |
full CRUD across skills + skill versions | skills |
client.user_profiles() |
create, list, get, update, create-enrollment-url | user-profiles |
client.managed_agents() |
sessions, agents, environments, vaults + credentials, memory_stores + memories + versions, resources, threads, events | managed-agents-preview |
client.admin() |
organizations, invites, users, workspaces + members, api_keys, usage_report, cost_report, rate_limits | admin |
Capabilities
- Forward-compatible types.
ContentBlock,StreamEvent,ContentDelta,Citation,BuiltinTool,BetaHeader,SessionResourceand similar wrapper enums round-trip unknown variants through anOther(Value)arm. New API variants don't break older SDK builds. Retry-Afterhonored. ConfigurableRetryPolicy { max_attempts, initial_backoff, max_backoff, jitter, respect_retry_after }.request-idon every error. Surfaced asError::request_id() -> Option<&str>.- Streaming with typed
EventStreamplus optionalon_text_delta/on_tool_use_complete/on_thinking_delta/on_message_stop/on_errorcallback hooks. - Tool dispatch with
ToolRegistry, parallel-by-default invocation, mid-stream approval gates, cumulative cost budget, cancellation token. #[derive(Tool)]proc-macro generates theToolimpl from a struct'sJsonSchema(under thederivefeature).Conversationmulti-turn helper with cumulative usage and optional context compaction.PricingTablewith bundled per-model rates pluscost_preview()for pre-flight USD estimates.dry_runmode renders the would-be HTTP request asDryRun { method, url, headers, body }plusto_curl()/to_curl_with_key()helpers.- Auth: API key (default), AWS Bedrock sigv4 signer (
bedrockfeature), pluggable via theRequestSignertrait. - Sync + async: same surface, blocking variants under the
syncfeature. - Structured
tracingspans + events on every request and retry. Zero plumbing required. - Cassette-based integration tests via
claude-api-test-- record once against the real API, replay deterministically in CI.
Feature flags
| Flag | Default | Adds |
|---|---|---|
async |
yes | Async client (tokio + reqwest) |
rustls |
yes | rustls TLS backend |
streaming |
yes | SSE streaming + EventStream::aggregate + callback hooks |
sync |
Blocking client (reqwest blocking) | |
native-tls |
native-tls instead of rustls | |
schemars-tools |
Tool::from_schemars::<T: JsonSchema> constructor |
|
derive |
#[derive(Tool)] (pulls in claude-api-derive) |
|
pricing |
PricingTable + cost calculation + cost_preview |
|
conversation |
Multi-turn Conversation helper |
|
bedrock |
AWS sigv4 BedrockSigner |
|
vertex |
(placeholder, not yet wired -- see #6) | |
admin |
Admin API | |
skills |
Skills API | |
user-profiles |
User Profiles API | |
managed-agents-preview |
Managed Agents preview |
Disable defaults if you only want the type definitions:
= { = "0.5", = false }
Resources
- Examples
- Changelog
- Open issues -- roadmap items, planned work, known gaps
MSRV
Rust 1.90 or later. Edition 2024.
License
Licensed under either of Apache-2.0 or MIT at your option. Contributions are dual-licensed under the same terms.