class

Anthropic::Client

Inherits Reference < Object

Constructors

new(config : Configuration)

Initialize from a Configuration struct.

Source
new(api_key : String | Nil = nil, base_url : String = ENV["ANTHROPIC_BASE_URL"]? || Configuration::DEFAULT_BASE_URL, timeout : Time::Span = Configuration::DEFAULT_TIMEOUT, max_idle_pool_size : Int32 = Configuration::DEFAULT_POOL_SIZE)

Backward-compatible initialize with individual parameters.

Source

Class methods

request_id(response : HTTP::Client::Response) : String | Nil

Extract request ID from a response header. Checks both "request-id" (preferred) and "x-request-id" headers.

Source

Instance methods

api_key
Source
base_url
Source
batches
Source
beta(beta_headers : Array(String) = [] of String) : Beta::API

Access beta-only features through an opt-in namespace.

Creates a Beta::API wrapper that automatically injects beta headers into requests. Pass specific beta headers to include them in all requests made through the beta namespace.

Example:

client.beta.skills.list
client.beta(["some-beta-feature"]).options
Source
completions

Access the legacy completions API.

DEPRECATED: Use #messages instead. The /v1/complete endpoint is deprecated and provided for backward compatibility only.

Source
config
Source
delete(path : String, options : RequestOptions | Nil = nil) : HTTP::Client::Response

Synchronous DELETE with retry

Source
files
Source
get(path : String, options : RequestOptions | Nil = nil) : HTTP::Client::Response

Synchronous GET with retry

Source
get_stream(path : String, options : RequestOptions | Nil = nil, &block : HTTP::Client::Response -> ) : Nil

Streaming GET — yields response with body_io for streaming responses.

NOTE: Streaming requests do NOT retry because streams cannot be safely replayed. Once the stream starts, there's no way to resume from a partial position. If a transport error occurs mid-stream, the caller must handle retry logic at the application level (e.g., re-initiate the request).

Source
messages
Source
models
Source
post(path : String, body : String, options : RequestOptions | Nil = nil) : HTTP::Client::Response

Synchronous POST with retry

Source
post_stream(path : String, body : String, options : RequestOptions | Nil = nil, &block : HTTP::Client::Response -> ) : Nil

Streaming POST — yields response with body_io for SSE.

NOTE: Streaming requests do NOT retry because SSE streams cannot be safely replayed. Once the stream starts, there's no way to resume from a partial position. If a transport error occurs mid-stream, the caller must handle retry logic at the application level (e.g., re-initiate the request).

Source
skills
Source
timeout
Source