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
- 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
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
- 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
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
- OPENAI_API_KEY environment variable is required for…
- anthropic package required for AI_PROVIDER=anthropic…
- bedrock-mantle provider requires: pip install openai…
- Bedrock Mantle response ended with status
- openai package required for AI_PROVIDER=openai. Install it…
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)