we-promise/sure · error · Provider::Anthropic::Error

Model is required when using a custom Anthropic-compatible e

Error message

Model is required when using a custom Anthropic-compatible endpoint

What it means

Provider::Anthropic#initialize raises Error when a custom base_url is configured (custom_endpoint? is true) but model is blank. When you point the provider at your own Anthropic-compatible gateway (Bedrock, Vertex, OpenRouter-style proxies), model IDs follow that endpoint's conventions (e.g. anthropic.claude-sonnet-4-5-20250929-v1:0), so the provider cannot fall back to DEFAULT_MODEL ("claude-sonnet-4-6") and requires an explicit model.

Source

Thrown at app/models/provider/anthropic.rb:37

    configured_model.presence || DEFAULT_MODEL
  end

  def self.configured?
    ENV["ANTHROPIC_ACCESS_TOKEN"].present? ||
      ENV["ANTHROPIC_API_KEY"].present? ||
      Setting.anthropic_access_token.present?
  end

  def initialize(access_token, base_url: nil, model: nil)
    client_options = { api_key: access_token }
    client_options[:base_url] = base_url if base_url.present?
    client_options[:timeout] = ENV.fetch("ANTHROPIC_REQUEST_TIMEOUT", 600).to_i

    @client = ::Anthropic::Client.new(**client_options)
    @base_url = base_url

    if custom_endpoint? && model.blank?
      raise Error, "Model is required when using a custom Anthropic-compatible endpoint"
    end

    @default_model = model.presence || DEFAULT_MODEL
  end

  def supports_model?(model)
    # Custom endpoints (Bedrock, Vertex, or other Anthropic-compatible proxies)
    # use their own model-ID conventions — e.g. Bedrock IDs look like
    # `anthropic.claude-sonnet-4-5-20250929-v1:0`. Mirror the OpenAI provider
    # and bypass the prefix gate when the caller has wired a custom base_url.
    return true if custom_endpoint?

    DEFAULT_ANTHROPIC_MODEL_PREFIXES.any? { |prefix| model.to_s.start_with?(prefix) }
  end

  def provider_name
    custom_endpoint? ? "Custom Anthropic-compatible (#{@base_url})" : "Anthropic"
  end

View on GitHub (pinned to e69894adb9)

Solutions

  1. Set the model in your Anthropic provider settings (the model ID your custom endpoint expects, e.g. an Bedrock inference-profile ID) so the provider is constructed with both base_url and model.
  2. If you instantiate the provider directly, always pass model: together with base_url:.
  3. Verify the Setting that holds the custom model is actually persisted (check the settings UI round-trip, not just the env var).
  4. If you actually want api.anthropic.com, remove the base_url so the default model fallback applies.

Example fix

# before
Provider::Anthropic.new(token, base_url: "https://bedrock-proxy.internal")
# => Model is required when using a custom Anthropic-compatible endpoint

# after
Provider::Anthropic.new(token,
  base_url: "https://bedrock-proxy.internal",
  model: "anthropic.claude-sonnet-4-5-20250929-v1:0"
)
Defensive patterns

Strategy: validation

Validate before calling

def build_anthropic_provider(setting)
  raise ArgumentError, "custom endpoint needs a model" if setting.base_url.present? && setting.model.blank?
  Provider::Anthropic.new(setting.access_token, base_url: setting.base_url, model: setting.model)
end

Try / catch

begin
  Provider::Anthropic.new(token, base_url:, model:)
rescue Provider::Anthropic::Error => e
  flash.now[:alert] = e.message # surface config error in settings UI
end

Prevention

When it happens

Trigger: Provider::Anthropic.new(access_token, base_url: "https://my-proxy.example.com", model: nil) — or the Settings layer constructing the provider from a custom-endpoint configuration where the model field was left empty. The check runs immediately at construction, before any API call.

Common situations: Wiring a Bedrock/Vertex proxy: base_url saved but model field skipped in the settings UI; env var for the model name missing (ANTHROPIC_MODEL unset) while ANTHROPIC_BASE_URL is set; test suite building the provider without a model stub.

Related errors


AI-assisted analysis of we-promise/sure@e69894adb9 (2026-08-21). Data as JSON: /api/errors/8eac1c44875781d5. Report an issue: GitHub.