Background
Production is hitting OpenAI 429 insufficient_quota errors with gpt-5-nano. This causes silent failures in the lead classification pipeline. Beyond the quota issue, gpt-5-nano is underpowered for the 3-stage pipeline (triage → research → scoring) — classification quality suffers at the cheap tier.
Switching to Claude Sonnet (claude-sonnet-4-6) removes the OpenAI dependency entirely and gives us a significantly more capable model for lead scoring.
Proposed Change
This is a provider swap — pydantic-ai supports Anthropic natively, so no framework changes are needed.
Files to modify
-
pyproject.toml
- Change
pydantic-ai-slim[openai,duckduckgo] → pydantic-ai-slim[anthropic,duckduckgo]
-
src/leads_agent/agent.py (lines 9-10, 105-106)
- Remove
OpenAIProvider, OpenAIChatModel, OpenAIChatModelSettings imports
- Add
AnthropicModel from pydantic_ai.models.anthropic
- Update
agent_factory() to instantiate AnthropicModel(model_name=llm_model_name) — no base_url needed
-
src/leads_agent/config.py (lines 52-54)
- Change default
LLM_MODEL_NAME from gpt-5-nano → claude-sonnet-4-6
- Remove
LLM_BASE_URL field (Anthropic client doesn't take a custom base URL)
- Rename
OPENAI_API_KEY → ANTHROPIC_API_KEY
-
.env.example
- Update env var name:
OPENAI_API_KEY → ANTHROPIC_API_KEY
- Update default model:
gpt-5-nano → claude-sonnet-4-6
- Remove
LLM_BASE_URL line (or leave as optional for Ollama use cases)
-
src/leads_agent/core/init_wizard.py (lines 45-47)
- Update interactive setup prompt default to
claude-sonnet-4-6
Out of Scope
- No changes to agent prompts or system instructions
- No changes to output schemas or Pydantic models
- No changes to Slack integration or Docker configuration (beyond
.env)
Testing
- Set
ANTHROPIC_API_KEY in .env
- Run
docker compose up locally
- Send a test lead through the Slack trigger
- Confirm all 3 stages (triage, research, scoring) complete without errors in logs
- Verify
✅/❌ reaction appears on the Slack message as expected
Background
Production is hitting OpenAI
429 insufficient_quotaerrors withgpt-5-nano. This causes silent failures in the lead classification pipeline. Beyond the quota issue,gpt-5-nanois underpowered for the 3-stage pipeline (triage → research → scoring) — classification quality suffers at the cheap tier.Switching to Claude Sonnet (
claude-sonnet-4-6) removes the OpenAI dependency entirely and gives us a significantly more capable model for lead scoring.Proposed Change
This is a provider swap — pydantic-ai supports Anthropic natively, so no framework changes are needed.
Files to modify
pyproject.tomlpydantic-ai-slim[openai,duckduckgo]→pydantic-ai-slim[anthropic,duckduckgo]src/leads_agent/agent.py(lines 9-10, 105-106)OpenAIProvider,OpenAIChatModel,OpenAIChatModelSettingsimportsAnthropicModelfrompydantic_ai.models.anthropicagent_factory()to instantiateAnthropicModel(model_name=llm_model_name)— no base_url neededsrc/leads_agent/config.py(lines 52-54)LLM_MODEL_NAMEfromgpt-5-nano→claude-sonnet-4-6LLM_BASE_URLfield (Anthropic client doesn't take a custom base URL)OPENAI_API_KEY→ANTHROPIC_API_KEY.env.exampleOPENAI_API_KEY→ANTHROPIC_API_KEYgpt-5-nano→claude-sonnet-4-6LLM_BASE_URLline (or leave as optional for Ollama use cases)src/leads_agent/core/init_wizard.py(lines 45-47)claude-sonnet-4-6Out of Scope
.env)Testing
ANTHROPIC_API_KEYin.envdocker compose uplocally✅/❌reaction appears on the Slack message as expected