anthropic4s
GitHub

Reference Client

AnthropicConfig

The client's settings. Start from an API key or the environment and adjust with withX; one call overrides any of them with RequestOptions.

Reference#

AnthropicConfig#

core · AnthropicConfig.scala
final case class AnthropicConfig private (
    credentials: Credentials,
    baseUrl: String,
    apiVersion: String,
    timeout: FiniteDuration,
    retryPolicy: RetryPolicy,
    betas: Set[Beta],
    headers: List[(String, String)]
)

Fields

core · AnthropicConfig.scala
val DefaultBaseUrl: String         = "https://api.anthropic.com"
val DefaultApiVersion: String      = "2026-10-21"
val DefaultTimeout: FiniteDuration = 10.minutes

AnthropicConfig(apiKey)#

core · AnthropicConfig.scala
def apply(credentials: Credentials): AnthropicConfig
def apply(apiKey: String): AnthropicConfig
core · AnthropicConfig.scala
sealed trait Credentials extends Product with Serializable
final case class ApiKey(key: Secret[String]) extends Credentials
final case class AuthToken(token: Secret[String]) extends Credentials

Caveats

AnthropicConfig.fromEnv#

core · AnthropicConfig.scala
def fromEnv[F[_]](implicit F: MonadThrow[F], env: Env[F]): F[AnthropicConfig]

Reads ANTHROPIC_API_KEY, or else ANTHROPIC_AUTH_TOKEN, and ANTHROPIC_BASE_URL when it is set.

Caveats

withX methods#

core · AnthropicConfig.scala
def withCredentials(c: Credentials): AnthropicConfig
def withBaseUrl(url: String): AnthropicConfig
def withApiVersion(v: String): AnthropicConfig
def withRetryPolicy(p: RetryPolicy): AnthropicConfig
def withMaxRetries(n: Int): AnthropicConfig
def withTimeout(d: FiniteDuration): AnthropicConfig
def withBetas(bs: Beta*): AnthropicConfig
def withHeader(name: String, value: String): AnthropicConfig

Caveats

RetryPolicy#

core · RetryPolicy.scala
final case class RetryPolicy private (
    maxRetries: Int,
    initialDelay: FiniteDuration,
    maxDelay: FiniteDuration,
    jitter: Double
)
def withMaxRetries(n: Int): RetryPolicy
def withInitialDelay(d: FiniteDuration): RetryPolicy
def withMaxDelay(d: FiniteDuration): RetryPolicy
core · RetryPolicy.scala
val default: RetryPolicy = new RetryPolicy(2, 500.millis, 8.seconds, 0.25)

/** Never retry. */
val none: RetryPolicy = default.withMaxRetries(0)

Retries connection failures, timeouts, 408, 409, 429 and 5xx. The wait doubles from initialDelay, is capped at maxDelay and is shortened by up to jitter.

Caveats

Usage#

Adjusting the defaults#

core · AnthropicConfig.scala
AnthropicConfig.fromEnv[IO].map(_.withTimeout(2.minutes).withBetas(Beta.ServerSideFallback))

Errors, retries and timeouts explains when to change them.

Every signature and example on this page is copied, character for character, from the public source of anthropic4s and its Scaladoc. The complete API, every type included, is in the Scaladoc of each module.