{"record":{"id":"803404c727bf3c3f","repo":"apache/seatunnel","slug":"anthropic-api-key-environment-variable-is-required","errorCode":null,"errorMessage":"ANTHROPIC_API_KEY environment variable is required for AI_PROVIDER=anthropic","messagePattern":"ANTHROPIC_API_KEY environment variable is required for AI_PROVIDER=anthropic","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"seatunnel-cli/seatunnel_cli/llm_provider.py","lineNumber":485,"sourceCode":"\n\n# ─── Anthropic Provider ───\n\nclass AnthropicProvider(LLMProvider):\n    \"\"\"Anthropic Messages API provider (direct, not via Bedrock).\"\"\"\n\n    def __init__(self):\n        try:\n            import anthropic\n        except ImportError:\n            raise ImportError(\n                \"anthropic package required for AI_PROVIDER=anthropic. \"\n                \"Install it: pip install anthropic\"\n            )\n\n        api_key = os.environ.get(\"ANTHROPIC_API_KEY\")\n        if not api_key:\n            raise ValueError(\"ANTHROPIC_API_KEY environment variable is required for AI_PROVIDER=anthropic\")\n\n        self._client = anthropic.Anthropic(api_key=api_key)\n        self._model_id = os.environ.get(\"ANTHROPIC_MODEL\", \"claude-sonnet-4-20250514\")\n        self._fast_model_id = os.environ.get(\"ANTHROPIC_SMALL_FAST_MODEL\", \"claude-haiku-4-5-20251001\")\n\n    @property\n    def provider_name(self) -> str:\n        return \"anthropic\"\n\n    @property\n    def model_id(self) -> str:\n        return self._model_id\n\n    @property\n    def fast_model_id(self) -> str:\n        return self._fast_model_id\n\n    def chat(","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-cli/seatunnel_cli/llm_provider.py#L467-L503","documentation":"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.","triggerScenarios":"AI_PROVIDER=anthropic with the anthropic package installed, but ANTHROPIC_API_KEY is unset/empty when the provider __init__ runs.","commonSituations":"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.","solutions":["Export ANTHROPIC_API_KEY with a valid key before running: export ANTHROPIC_API_KEY=sk-ant-...","Ensure the variable is visible to the CLI process (CI secret injection, shell profile, or source .env)","Confirm no typo in the variable name and that it is non-empty"],"exampleFix":"// before\nexport AI_PROVIDER=anthropic\n// after\nexport AI_PROVIDER=anthropic\nexport ANTHROPIC_API_KEY=sk-ant-api03-...","handlingStrategy":"validation","validationCode":"import os, sys\nif not os.environ.get('ANTHROPIC_API_KEY'):\n    sys.exit('ANTHROPIC_API_KEY is not set')","typeGuard":null,"tryCatchPattern":"try:\n    provider = AnthropicProvider()\nexcept ValueError as e:\n    print(e)  # missing ANTHROPIC_API_KEY\n    sys.exit(2)","preventionTips":["Export ANTHROPIC_API_KEY in shell profiles or dotenv loaded by the entrypoint","Inject the secret explicitly in CI/CD jobs","Never rely on another provider's key variable","Validate env vars at startup with a preflight script"],"tags":["python","llm","env","anthropic","api-key"],"backgroundTag":"missing-env-var","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}