Per CONTRIBUTING: this issue was written with AI assistance. The llm-generated label is required but outside contributors cannot apply labels (403). Could a maintainer add it. Findings below were verified by hand against the files and line numbers cited.
What happens
LLM(model="claude-sonnet-4-6") constructs an OpenAICompletion, not AnthropicCompletion. No error is raised.
claude-sonnet-4-6 is the second entry in the Anthropic list that crewai create offers, so this is reachable straight from the CLI picker.
Two lists, out of sync
lib/cli/src/crewai_cli/constants.py:163 offers claude-opus-4-6 and claude-sonnet-4-6 at the top of the Anthropic menu.
Neither is in ANTHROPIC_MODELS in lib/crewai/src/crewai/llms/constants.py:212, which stops at claude-opus-4-5. The AnthropicModels Literal at :184 has the same gap.
Why the mismatch routes wrong
LLM._infer_provider_from_model in lib/crewai/src/crewai/llm.py:634 checks the five constant lists and falls back to "openai":
if model in ANTHROPIC_MODELS:
return "anthropic"
...
return "openai"
Its docstring describes different behavior:
This method first checks the hardcoded constants list for known models. If not found, it uses pattern matching to infer the provider from model name patterns. This allows supporting new models and "latest" versions without hardcoding.
There is no pattern matching in the function.
The sibling _validate_model_in_constants does exactly what that docstring describes: it checks the lists, then falls through to _matches_provider_pattern at :617. That helper already handles the claude- and anthropic. prefixes at :538. _infer_provider_from_model just never calls it.
The bare-model path at :473 sets use_native = True, so the inferred provider goes straight to _get_native_provider and the wrong client is constructed.
Also in ANTHROPIC_MODELS
claude-4-sonnet-20250514 and claude-4-opus-20250514 are not valid Anthropic ids. Anthropic moved to claude-<family>-<version> at Claude 3, and the correct claude-sonnet-4-20250514 and claude-opus-4-20250514 are already present in the same list.
Missing beyond the CLI gap: claude-opus-4-7, claude-opus-4-8, and the Claude 5 family (claude-opus-5, claude-sonnet-5, claude-fable-5).
Suggested fix
Have _infer_provider_from_model fall through to _matches_provider_pattern before defaulting to openai, which is what its docstring already promises and what makes the constants list a fast path rather than a gate. Then refresh ANTHROPIC_MODELS and drop the two invalid ids.
Happy to send a PR for this. Assign it to me if you want me to take it.
What happens
LLM(model="claude-sonnet-4-6")constructs anOpenAICompletion, notAnthropicCompletion. No error is raised.claude-sonnet-4-6is the second entry in the Anthropic list thatcrewai createoffers, so this is reachable straight from the CLI picker.Two lists, out of sync
lib/cli/src/crewai_cli/constants.py:163offersclaude-opus-4-6andclaude-sonnet-4-6at the top of the Anthropic menu.Neither is in
ANTHROPIC_MODELSinlib/crewai/src/crewai/llms/constants.py:212, which stops atclaude-opus-4-5. TheAnthropicModelsLiteral at:184has the same gap.Why the mismatch routes wrong
LLM._infer_provider_from_modelinlib/crewai/src/crewai/llm.py:634checks the five constant lists and falls back to"openai":Its docstring describes different behavior:
There is no pattern matching in the function.
The sibling
_validate_model_in_constantsdoes exactly what that docstring describes: it checks the lists, then falls through to_matches_provider_patternat:617. That helper already handles theclaude-andanthropic.prefixes at:538._infer_provider_from_modeljust never calls it.The bare-model path at
:473setsuse_native = True, so the inferred provider goes straight to_get_native_providerand the wrong client is constructed.Also in
ANTHROPIC_MODELSclaude-4-sonnet-20250514andclaude-4-opus-20250514are not valid Anthropic ids. Anthropic moved toclaude-<family>-<version>at Claude 3, and the correctclaude-sonnet-4-20250514andclaude-opus-4-20250514are already present in the same list.Missing beyond the CLI gap:
claude-opus-4-7,claude-opus-4-8, and the Claude 5 family (claude-opus-5,claude-sonnet-5,claude-fable-5).Suggested fix
Have
_infer_provider_from_modelfall through to_matches_provider_patternbefore defaulting to openai, which is what its docstring already promises and what makes the constants list a fast path rather than a gate. Then refreshANTHROPIC_MODELSand drop the two invalid ids.Happy to send a PR for this. Assign it to me if you want me to take it.