View Source Anthropic.Client (anthropic_community v0.5.0)

Holds connection-level configuration for the Anthropic API: credentials, base URL, API version, retry policy, and transport pool. Built once via new/1 and passed explicitly as the first argument to every resource function (Anthropic.Messages.create/2, Anthropic.Models.list/1, etc.) rather than held implicitly in process/application state.

Resolution order for :api_key and :base_url

  1. Explicit option passed to new/1.
  2. Application.get_env(:anthropic, key).
  3. ANTHROPIC_API_KEY / ANTHROPIC_BASE_URL environment variables.
  4. For :api_key only: raises ArgumentError if still unresolved. :base_url defaults to "https://api.anthropic.com".

Summary

Types

@type t() :: %Anthropic.Client{
  api_key: String.t(),
  api_version: String.t(),
  base_url: String.t(),
  default_headers: [{String.t(), String.t()}],
  default_model: String.t() | nil,
  http_pool: atom(),
  max_retries: non_neg_integer(),
  timeout: pos_integer()
}

Functions

@spec new(keyword()) :: t()