CodeWiki
CodeWiki copied to clipboard
Use native Anthropic API for documentation agents when provider=anthropic
Summary Routes pydantic-ai documentation agents through AnthropicModel + AnthropicProvider (Anthropic Messages API) when config.provider is anthropic, instead of always using CompatibleOpenAIModel + OpenAIProvider. Declares the pydantic-ai[anthropic] extra so the Anthropic SDK is installed with the package.
Motivation With provider: anthropic and Anthropic model IDs, the previous stack still used the OpenAI-compatible client, which led to 404s and confusion when base_url pointed at Anthropic or when model names were valid for Anthropic but not for a chat.completions endpoint. Agents should use the same native Anthropic path that matches user configuration.
Changes
codewiki/src/be/llm_services.py
create_main_model / create_fallback_model: if provider (trimmed, lowercased) is anthropic, build AnthropicModel with AnthropicModelSettings (temperature=0, max_tokens from config) and AnthropicProvider (api_key, optional base_url).
_anthropic_api_model_name: strips a leading anthropic/ prefix so LiteLLM-style names still work.
_anthropic_provider_base_url: passes through a normal HTTPS base URL; if llm_base_url looks like a local OpenAI-compatible LiteLLM host (0.0.0.0:4000, localhost:4000, etc.), logs a warning and uses None (Anthropic default host). Documented expectation: use openai-compatible for LiteLLM’s OpenAI port.
Lazy import of Anthropic pydantic-ai modules with a clear ImportError if the extra is missing.
Return type widened to Any for the mixed OpenAI / Anthropic model types.
pyproject.toml
Dependency pydantic-ai>=1.0.6 → pydantic-ai[anthropic]>=1.0.6.```