Expand description
Error type, result alias, and wire-format error payload.
Every endpoint method returns Result<T> where the
error variant is Error. The error carries:
- HTTP status (when the API responded with one) via
Error::status request-id(always populated when the server sent one) viaError::request_id– this is the field to include in support tickets- Retry classification via
Error::is_retryable– theretry::RetryPolicylayer uses the same logic Retry-Afterhonoring viaError::retry_after– the parsedRetry-Afterheader (in seconds), used by the retry layer to wait before the next attempt- Structured kind via
ApiErrorKindfor documented API error types (rate-limit, authentication, not-found, etc.)
§Quick start
use claude_api::{Client, messages::CreateMessageRequest, types::ModelId};
let client = Client::new("sk-ant-...");
let req = CreateMessageRequest::builder()
.model(ModelId::SONNET_4_6)
.max_tokens(8)
.user("hi")
.build()?;
match client.messages().create(req).await {
Ok(resp) => println!("ok: {}", resp.id),
Err(e) if e.is_retryable() => {
// The retry layer already retried; if we're here, attempts
// were exhausted.
eprintln!("gave up after retries: {} (request_id={:?})",
e, e.request_id());
}
Err(e) => {
// Permanent error -- 4xx, deserialization, signing, etc.
eprintln!("error: {} (request_id={:?})",
e, e.request_id());
}
}Variants tied to optional features (async/sync for
Error::Network, streaming for Error::Stream) are
conditionally compiled out when those features are disabled.
Structs§
- ApiError
Payload - Wire-format error payload, as it appears inside an HTTP error response or
inside a streaming
errorevent.
Enums§
- ApiError
Kind - Categories of errors the Anthropic API can return.
- Error
- Errors returned by this crate.
- Stream
Error streaming - Errors specific to the streaming layer.
Type Aliases§
- Result
- Crate-wide result alias.