langchain-ai/deepagents · error · ModelConfigError

Claude model '{model_name}' uses the Anthropic Messages API

Error message

Claude model '{model_name}' uses the Anthropic Messages API on Vertex AI. Use 'google_anthropic_vertex:{model_name}' instead of 'google_vertexai:{model_name}'.

What it means

Raised when a Claude model is requested via the `google_vertexai` provider. Claude on Vertex AI uses the Anthropic Messages API, which requires the `google_anthropic_vertex` provider, not the Vertex AI Gemini provider.

Source

Thrown at libs/code/deepagents_code/config.py:5756

        else:
            msg = (
                f"Invalid model spec '{model_spec}': model name is required "
                "(e.g., 'anthropic:claude-sonnet-4-5' or 'claude-sonnet-4-5')"
            )
            raise ModelConfigError(msg)
    else:
        # Bare model name — auto-detect provider or let init_chat_model infer
        model_name = model_spec
        provider = inferred_provider or ""

    if provider == "google_vertexai" and model_name.lower().startswith("claude-"):
        msg = (
            f"Claude model '{model_name}' uses the Anthropic Messages API on "
            "Vertex AI. Use "
            f"'google_anthropic_vertex:{model_name}' instead of "
            f"'google_vertexai:{model_name}'."
        )
        raise ModelConfigError(msg)

    resolved_spec = f"{provider}:{model_name}" if provider else model_spec
    # The authoritative policy gate, and its position is load-bearing: it runs
    # after provider inference (so a bare name is matched in canonical form)
    # but before credential bridging, provider profiles, and provider imports.
    # A blocked spec must not copy stored keys onto env vars or run a provider
    # `pre_init` hook. `test_rejects_before_credential_side_effects` pins this.
    config.require_model_allowed(resolved_spec)

    # Stored API keys (added via `/auth`) take effect by being copied onto
    # the env var name LangChain reads. Apply before the credential check so
    # `has_provider_credentials` and the downstream SDK see the same value.
    if provider:
        # Flag a key/endpoint resolved from different env tiers *before*
        # `apply_stored_credentials` bridges stored values onto plain env vars,
        # so the check sees the user's raw env intent rather than post-bridge
        # state. Diagnostic only -- never alters resolution.
        warn_on_split_credential_source(provider)

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Use the 'google_anthropic_vertex:claude-...' provider prefix explicitly.
  2. If you meant a Gemini model, correct the model name (it should not start with 'claude-').
  3. Install/configure the Anthropic-on-Vertex integration (langchain-google-vertexai with the anthropic_vertex route) and its credentials.

Example fix

// before
model = create_model("google_vertexai:claude-sonnet-4-5")
// after
model = create_model("google_anthropic_vertex:claude-sonnet-4-5")
Defensive patterns

Strategy: validation

Validate before calling

def route_provider(provider: str, model: str) -> str:
    if provider == "google_vertexai" and model.lower().startswith("claude-"):
        return "google_anthropic_vertex"
    return provider
# spec = f"{route_provider(p, m)}:{m}"

Try / catch

try:
    result = create_model(spec)
except ModelConfigError as e:
    if "google_anthropic_vertex" in str(e):
        spec = spec.replace("google_vertexai:", "google_anthropic_vertex:", 1)
        result = create_model(spec)

Prevention

When it happens

Trigger: `create_model('google_vertexai:claude-...')` or a bare 'claude-*' name auto-resolved to google_vertexai (e.g. when Vertex credentials are present), with the model name starting with 'claude-'.

Common situations: Users on GCP assuming all Vertex AI models use google_vertexai; auto-detection picking google_vertexai because GOOGLE_APPLICATION_CREDENTIALS/Vertex creds are configured while the intended backend is Claude on Vertex.

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/05c5550f91d8282a. Report an issue: GitHub.