apache/seatunnel · error · ValueError

ANTHROPIC_API_KEY environment variable is required for…

Error message

ANTHROPIC_API_KEY environment variable is required for AI_PROVIDER=anthropic

What it means

AnthropicProvider requires an API key from the ANTHROPIC_API_KEY environment variable to construct anthropic.Anthropic(api_key=...). If the variable is unset or empty, it raises ValueError before creating the client.

Solutions

  1. Export ANTHROPIC_API_KEY with a valid key before running: export ANTHROPIC_API_KEY=sk-ant-...
  2. Ensure the variable is visible to the CLI process (CI secret injection, shell profile, or source .env)
  3. Confirm no typo in the variable name and that it is non-empty

Example fix

// before
export AI_PROVIDER=anthropic
// after
export AI_PROVIDER=anthropic
export ANTHROPIC_API_KEY=sk-ant-api03-...
Defensive patterns

Strategy: validation

Validate before calling

import os, sys
if not os.environ.get('ANTHROPIC_API_KEY'):
    sys.exit('ANTHROPIC_API_KEY is not set')

Try / catch

try:
    provider = AnthropicProvider()
except ValueError as e:
    print(e)  # missing ANTHROPIC_API_KEY
    sys.exit(2)

Prevention

When it happens

Trigger: AI_PROVIDER=anthropic with the anthropic package installed, but ANTHROPIC_API_KEY is unset/empty when the provider __init__ runs.

Common situations: Exported the key in one shell but launched the CLI from another; CI secrets not injected; .env file not loaded; key set under a different variable name.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/803404c727bf3c3f. Report an issue: GitHub.

Appendix: source

Thrown at seatunnel-cli/seatunnel_cli/llm_provider.py:485


# ─── Anthropic Provider ───

class AnthropicProvider(LLMProvider):
    """Anthropic Messages API provider (direct, not via Bedrock)."""

    def __init__(self):
        try:
            import anthropic
        except ImportError:
            raise ImportError(
                "anthropic package required for AI_PROVIDER=anthropic. "
                "Install it: pip install anthropic"
            )

        api_key = os.environ.get("ANTHROPIC_API_KEY")
        if not api_key:
            raise ValueError("ANTHROPIC_API_KEY environment variable is required for AI_PROVIDER=anthropic")

        self._client = anthropic.Anthropic(api_key=api_key)
        self._model_id = os.environ.get("ANTHROPIC_MODEL", "claude-sonnet-4-20250514")
        self._fast_model_id = os.environ.get("ANTHROPIC_SMALL_FAST_MODEL", "claude-haiku-4-5-20251001")

    @property
    def provider_name(self) -> str:
        return "anthropic"

    @property
    def model_id(self) -> str:
        return self._model_id

    @property
    def fast_model_id(self) -> str:
        return self._fast_model_id

    def chat(

View on GitHub (pinned to cf67b549a7)