module

Anthropic

Constants

ADVANCED_TOOL_USE_BETA = "advanced-tool-use-2025-11-20"
ADVISOR_TOOL_BETA = "advisor-tool-2026-03-01"

Advisor tool (secondary-model advisor) beta header.

AGENT_MEMORY_BETA = "agent-memory-2026-07-22"

Agent persistent memory beta header (Memory Stores API).

CACHE_DIAGNOSTICS_BETA = "cache-diagnosis-2026-04-07"

Beta header constants

CODE_EXECUTION_BETA = "code-execution-2025-08-25"
COMPUTER_USE_BETA = "computer-use-2025-01-24"
COMPUTER_USE_LEGACY_BETA = "computer-use-2024-10-22"
CONTEXT_1M_BETA = "context-1m-2025-08-07"

1M context window beta header.

DEV_FULL_THINKING_BETA = "dev-full-thinking-2025-05-14"

Extended / interleaved thinking betas.

DREAMING_BETA = "dreaming-2026-04-21"

Dreams (memory consolidation) beta header.

Research-preview API: request/response shapes may change without a deprecation period. Required by client.beta.dreams.* together with MANAGED_AGENTS_BETA (both auto-attached). Access is separately gated.

EXTENDED_CACHE_TTL_BETA = "extended-cache-ttl-2025-04-11"
FALLBACK_CREDIT_BETA = FALLBACK_CREDIT_BETA_2026_07_01

Primary fallback-credit beta. Tracks the latest official default (July 2026).

FALLBACK_CREDIT_BETA_2026_06_01 = "fallback-credit-2026-06-01"

Fallback-credit beta header (June 2026). Kept for callers that pin the older bare-string credit-token behavior.

FALLBACK_CREDIT_BETA_2026_07_01 = "fallback-credit-2026-07-01"

Fallback-credit beta header (July 2026) — required for object-form fallback_credit_token ({token, mode}) and used by default by BetaRefusalFallbackMiddleware.

FALLBACKS_DEFAULT = "default"

Only valid string form of fallbacks (server-defined default chain).

FAST_MODE_BETA = "fast-mode-2026-02-01"

Fast mode beta header.

FILES_API_BETA = "files-api-2025-04-14"
FINE_GRAINED_STREAMING_BETA = "fine-grained-tool-streaming-2025-05-14"
INTERLEAVED_THINKING_BETA = "interleaved-thinking-2025-05-14"
MANAGED_AGENTS_BETA = "managed-agents-2026-04-01"
MCP_CLIENT_2025_04_04_BETA = "mcp-client-2025-04-04"
MCP_CLIENT_BETA = "mcp-client-2025-11-20"
MCP_CONNECTOR_BETA = "mcp-connector-2025-05-01"
MCP_TUNNELS_BETA = "mcp-tunnels-2026-06-22"

MCP Tunnels beta header (research preview).

Required by client.beta.tunnels.* and client.beta.tunnels.certificates.*. Supersedes Admin API /v1/organizations/tunnels during a migration window. Management calls need WIF with workspace:manage_tunnels — not API keys.

MEMORY_BETA = "context-management-2025-06-27"
MODEL_CONTEXT_WINDOW_EXCEEDED_BETA = "model-context-window-exceeded-2025-08-26"

Surfaces model_context_window_exceeded as a recoverable stop_reason.

MODEL_SHORTHANDS = {:sonnet => Model::CLAUDE_SONNET_5, :sonnet_5 => Model::CLAUDE_SONNET_5, :fable => Model::CLAUDE_FABLE_5, :fable_5 => Model::CLAUDE_FABLE_5, :mythos => Model::CLAUDE_MYTHOS_5, :mythos_5 => Model::CLAUDE_MYTHOS_5, :opus => Model::CLAUDE_OPUS_5, :opus_5 => Model::CLAUDE_OPUS_5, :opus_4_8 => Model::CLAUDE_OPUS_4_8, :opus_4_7 => Model::CLAUDE_OPUS_4_7, :haiku => Model::CLAUDE_HAIKU_4_5, :opus_4_6 => Model::CLAUDE_OPUS_4_6, :sonnet_4_6 => Model::CLAUDE_SONNET_4_6, :opus_4_5 => Model::CLAUDE_OPUS_4_5, :sonnet_4_5 => Model::CLAUDE_SONNET_4_5, :opus_4_1 => Model::CLAUDE_OPUS_4_1, :sonnet_4 => Model::CLAUDE_SONNET_4} of Symbol => String

Shorthand helper for accessing model IDs via symbols

Anthropic::Model::CLAUDE_SONNET # => "claude-sonnet-5"
Anthropic::Model::CLAUDE_FABLE  # => "claude-fable-5"
Anthropic::Model::CLAUDE_OPUS   # => "claude-opus-5"
Anthropic::Model::CLAUDE_HAIKU  # => "claude-haiku-4-5"

Anthropic.model_name(:sonnet) # => "claude-sonnet-5"
Anthropic.model_name(:fable)  # => "claude-fable-5"
Anthropic.model_name(:mythos) # => "claude-mythos-5"
Anthropic.model_name(:opus)   # => "claude-opus-5"
Anthropic.model_name(:opus_5) # => "claude-opus-5"
Anthropic.model_name(:haiku)  # => "claude-haiku-4-5-20251001"
OUTPUT_128K_BETA = "output-128k-2025-02-19"

Output token cap betas.

OUTPUT_300K_BETA = "output-300k-2026-03-24"
PDFS_BETA = "pdfs-2024-09-25"

PDF document support beta header.

SERVER_SIDE_FALLBACK_BETA = SERVER_SIDE_FALLBACK_BETA_2026_07_01

Primary server-side fallbacks beta. Tracks the latest official default (July 2026). Auto-attached when fallbacks: is set.

SERVER_SIDE_FALLBACK_BETA_2026_06_01 = "server-side-fallback-2026-06-01"

Server-side fallbacks beta header (June 2026).

Prefer SERVER_SIDE_FALLBACK_BETA / SERVER_SIDE_FALLBACK_BETA_2026_07_01 for new code; this constant is kept for callers that pin the older header.

SERVER_SIDE_FALLBACK_BETA_2026_07_01 = "server-side-fallback-2026-07-01"

Server-side fallbacks beta header (July 2026) — supports fallbacks: "default" and aligns with the official Python/Ruby/TS SDKs.

SKILLS_BETA = "skills-2025-10-02"
STRUCTURED_OUTPUT_BETA = "structured-outputs-2025-12-15"
THINKING_TOKEN_COUNT_BETA = "thinking-token-count-2026-05-13"

Thinking token count in streaming deltas (optional display).

TOKEN_COUNTING_BETA = "token-counting-2024-11-01"
TOKEN_EFFICIENT_TOOLS_BETA = "token-efficient-tools-2025-02-19"
USER_PROFILES_BETA = "user-profiles-2026-03-24"

User profiles beta header.

VERSION = "0.9.0"
WEB_FETCH_BETA = "web-fetch-2025-09-10"
WEB_SEARCH_BETA = "web-search-2025-03-05"

Class methods

beta_headers_for_tools(tools : Enumerable(ServerTool | ToolDefinition) | Nil) : Array(String)

Collect the beta header strings required by a set of server tools.

This is the single source of truth for server-tool-to-beta mappings so that resource classes don't have to duplicate the case logic.

Source
fallbacks_present?(fallbacks : FallbacksParam | Nil) : Bool

Returns true when fallbacks is a non-empty chain or the string "default".

Any other string (including empty) is treated as absent so we do not auto-attach the server-side fallback beta for typos like "defaults". Serialization via FallbacksParamConverter also rejects non-"default" strings with ArgumentError.

Source
model_name(shorthand : Symbol) : String
Source
output_schema(name : String, schema : Hash(String, Schema::Property), description : String | Nil = nil, required : Array(String) = [] of String) : OutputSchema

Convenience method to create an output schema

output = Anthropic.output_schema(
  name: "weather_report",
  schema: {
    "temperature" => Schema.number("Current temperature"),
    "conditions"  => Schema.string("Weather conditions"),
  },
  required: ["temperature", "conditions"]
)
Source
resolve_beta_headers(betas : Array(String) = [] of String, server_tools : Enumerable(ServerTool | ToolDefinition) | Nil = nil, cache_control : CacheControl | Nil = nil, diagnostics : DiagnosticsParam | Nil = nil, output_format : OutputFormat | Nil = nil, output_config : OutputConfig | Nil = nil, include_token_counting : Bool = false, include_user_profiles : Bool = false) : Hash(String, String) | Nil

Resolve and compile the complete "anthropic-beta" headers mapping

Source
tool(name : String, description : String, schema : Hash(String, Schema::Property), required : Array(String) = [] of String, cache_control : CacheControl | Nil = nil, &handler : JSON::Any -> String) : Tool

Helper method for creating inline tools with Schema DSL

weather_tool = Anthropic.tool(
  name: "get_weather",
  description: "Get current weather for a location",
  schema: {
    "location" => Schema.string("City name, e.g. San Francisco, CA"),
    "unit"     => Schema.enum("celsius", "fahrenheit", description: "Temperature unit"),
  },
  required: ["location"]
) do |input|
  location = input["location"].as_s
  unit = input["unit"]?.try(&.as_s) || "fahrenheit"
  "The weather in #{location} is sunny and 72°#{unit == "celsius" ? "C" : "F"}."
end
Source

Macros

output_schema(type, name, description = nil)

Macro to create a typed output schema from a struct

struct MyOutput
  include JSON::Serializable
  getter result : String
  getter confidence : Float64
end

schema = Anthropic.output_schema(type: MyOutput, name: "my_output")
Source
tool(name, description, input, &block)

Macro to create typed tools with struct input

This provides Ruby BaseTool-like functionality where:

  • Input schema is derived from a Crystal struct
  • Handler receives typed struct instead of JSON::Any
  • Field descriptions come from @[JSON::Field(description: "...")]
struct SearchInput
  include JSON::Serializable
  getter query : String
  getter category : Category?
end

tool = Anthropic.tool(
  name: "search",
  description: "Search products",
  input: SearchInput
) do |input|
  "Found results for #{input.query}"
end
Source

Nested types