class

Anthropic::Client

Inherits Reference < Object

Constants

API_VERSION = "2023-06-01"
DEFAULT_BASE_URL = "https://api.anthropic.com"
DEFAULT_INITIAL_DELAY = 0.5
DEFAULT_MAX_DELAY = 8.0
DEFAULT_MAX_RETRIES = 2

Constructors

new(api_key : String | Nil = nil, base_url : String = DEFAULT_BASE_URL, timeout : Time::Span = 600.seconds, max_retries : Int32 = DEFAULT_MAX_RETRIES, initial_retry_delay : Float64 = DEFAULT_INITIAL_DELAY, max_retry_delay : Float64 = DEFAULT_MAX_DELAY, default_headers : Hash(String, String) = {} of String => String, middleware : Array = [] of Middleware)
Source

Instance methods

beta

Beta namespace for beta features

client.beta.messages.create(
  betas: ["structured-outputs-2025-12-15"],
  ...
)
Source
delete(path : String, extra_headers : Hash(String, String) | Nil = nil) : HTTP::Client::Response
Source
get(path : String, params : QueryParams | Nil = nil, extra_headers : Hash(String, String) | Nil = nil) : HTTP::Client::Response
Source
get_raw(path : String, extra_headers : Hash(String, String) | Nil = nil) : IO::Memory

GET request returning raw response body (for binary downloads)

Source
get_stream(path : String, extra_headers : Hash(String, String) | Nil = nil, &)
Source
messages

Resource accessors

Source
middleware

The configured middleware chain (outermost first).

Source
models
Source
post(path : String, body, extra_headers : Hash(String, String) | Nil = nil) : HTTP::Client::Response

POST with any JSON::Serializable body

Source
post_multipart(path : String, file : IO, filename : String, content_type : String = "application/octet-stream", extra_headers : Hash(String, String) | Nil = nil) : HTTP::Client::Response

POST multipart form data (for file uploads)

Source
post_multipart_files(path : String, files : Array(FileUpload), form_fields : Hash(String, String) | Nil = nil, extra_headers : Hash(String, String) | Nil = nil) : HTTP::Client::Response

POST multipart form data with multiple files and optional form fields

Source
post_stream(path : String, body, extra_headers : Hash(String, String) | Nil = nil, &)

POST with streaming response

Source

Nested types