Anthropic::Client
Constants
Constructors
Instance methods
Beta namespace for beta features
client.beta.messages.create(
betas: ["structured-outputs-2025-12-15"],
...
)
[Legacy] Text Completions API.
completion = client.completions.create(
model: "claude-haiku-4-5-20251001",
prompt: "\n\nHuman: Hello!\n\nAssistant:",
max_tokens_to_sample: 256
)
Files API for uploading and managing files.
file = client.files.upload(Path["document.pdf"])
GET request returning raw response body (for binary downloads)
POST with any JSON::Serializable body
POST multipart form data (for file uploads)
POST multipart form data with multiple files and optional form fields
POST with streaming response
Webhook signing key for BetaWebhooks#unwrap. Explicit argument wins,
falling back to ANTHROPIC_WEBHOOK_SIGNING_KEY.
Returns a copy of this client with middleware appended after the client's existing middleware (which stays outermost).
scoped = client.with_middleware(LoggingMiddleware.new)
Returns a copy of this client with per-request overrides applied.
Upstream SDKs take requestOptions on every call; the Crystal
equivalent is a scoped copy, so every resource through it picks the
overrides up. middleware replaces the chain; credentials, base
URL, and proxy override the copy's connection settings (handy for
per-tenant scoping):
scoped = client.with_options(timeout: 30.seconds, max_retries: 0)
scoped.messages.create(model: "...", max_tokens: 64, messages: [...])