Skip to content

Anthropic models fail via Pydantic AI Gateway (404 NOT_FOUND) #187

@EgonFerri

Description

@EgonFerri

Initial Checks

Description

We’re seeing 404 errors for every Anthropic model when accessed via Pydantic AI Gateway. Example:

Command:
uv run --env-file .env python temp2.py

Error:
pydantic_ai.exceptions.ModelHTTPError: status_code: 404, model_name: claude-sonnet-4-0, body: {'error': {'code': 404, 'message': 'Publisher Model `projects/vertexai-485114/locations/europe-west8/publishers/anthropic/models/claude-sonnet-4` not found.', 'status': 'NOT_FOUND'}}

This happens for all Anthropic models via gateway.
Control cases succeed:

  • Direct Anthropic (no gateway) works (temp.py).
  • Direct Anthropic with key from .env works (temp3.py).
  • Gateway OpenAI works (temp4.py).
  • Gateway Google Vertex works (another script in our codebase, not shown here).

We verified with more than one gateway API key.

Environment variables in .env (keys omitted):

  • ANTHROPIC_API_KEY=...
  • PYDANTIC_AI_GATEWAY_API_KEY=...

Gateway provider settings for Anthropic:

  • Base URL: https://api.anthropic.com
  • Slug: anthropic-temp-egon-personal
  • Provider Type: Anthropic
  • Inject Cost: Enabled
  • Block on Error: False
  • Created: 23/01/2026, 10:35:58
  • Credentials: (redacted)

Expected: Anthropic models should run via gateway just like OpenAI and Vertex.

Minimal, Reproducible Example

# Minimal, Reproducible Example (fails)

from pydantic_ai import Agent

agent = Agent(
    "gateway/anthropic:claude-sonnet-4-0",
    instructions="Be concise, reply with one sentence.",
)

result = agent.run_sync('Where does "hello world" come from?')
print(result.output)

Run with:
uv run --env-file .env python temp2.py

---

#**Control examples (work)**

# 1) Direct Anthropic (no gateway) — works

from pydantic_ai import Agent
from pydantic_ai.models.anthropic import AnthropicModel
from pydantic_ai.providers.anthropic import AnthropicProvider

model = AnthropicModel("claude-haiku-4-5", provider=AnthropicProvider(api_key="***"))
agent = Agent(model, instructions="Be concise, reply with one sentence.")
result = agent.run_sync('Where does "hello world" come from?')
print(result.output)

Run with:
uv run --env-file .env python temp1.py

# 2) Direct Anthropic (no gateway) — works

from pydantic_ai import Agent

agent = Agent(
    "anthropic:claude-sonnet-4-0",
    instructions="Be concise, reply with one sentence.",
)

result = agent.run_sync('Where does "hello world" come from?')
print(result.output)

Run with:
uv run --env-file .env python temp3.py

# 3) Gateway OpenAI — works

from pydantic_ai import Agent

agent = Agent(
    "gateway/openai:gpt-4-turbo",
    instructions="Be concise, reply with one sentence.",
)

result = agent.run_sync('Where does "hello world" come from?')
print(result.output)

Run with:
uv run --env-file .env python temp4.py

Logfire Trace

https://logfire-eu.pydantic.dev/public-trace/a2f2b440-ba76-4c50-a029-1ea7563a5448?spanId=a4593853c16ab368

Python, Pydantic AI & LLM client version

  • Python: Python 3.13.11
  • Pydantic AI: 1.41.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions