#20593: fix: route Anthropic OAT tokens to /v1/messages endpoint (#20107)
agents
size: S
Cluster:
Tool Call ID Sanitization
## Summary
Fixes #20107 - Anthropic OAT tokens now correctly route to `/v1/messages` instead of `/v1/responses`, preventing HTTP 404 errors.
## Problem
When using Anthropic setup-tokens (OAT: `sk-ant-oat01-...`), unknown Anthropic models fell through to a generic fallback that hardcoded `api: "openai-responses"`. This caused requests to route to `/v1/responses` (OpenAI-compatible API) instead of `/v1/messages` (native Anthropic API), resulting in `HTTP 404 not_found_error`.
### Control Test from Issue
- `POST https://api.anthropic.com/v1/messages` with `claude-sonnet-4-6` → **200 ✅**
- `POST https://api.anthropic.com/v1/responses` with `claude-sonnet-4-6` → **404 ❌**
## Solution
Added `PROVIDER_API_MAP` that maps providers to their correct API types:
- `anthropic` → `anthropic-messages` (routes to `/v1/messages`)
- `amazon-bedrock` → `bedrock-converse-stream`
- `google` → `google-generative-ai`
- `ollama` → `ollama`
Created `inferApiForProvider()` function that looks up the map, falling back to `openai-responses` for unknown providers.
## Verification
All mappings verified against authoritative sources:
**Anthropic** → `anthropic-messages`
- Official API docs: https://platform.claude.com/docs/en/api/messages
- pi-ai models registry: All 20+ Anthropic models use `"anthropic-messages"`
**Amazon Bedrock** → `bedrock-converse-stream`
- pi-ai models registry: All Bedrock models use `"bedrock-converse-stream"`
**Google** → `google-generative-ai`
- pi-ai models registry: All Google models use `"google-generative-ai"`
**Ollama** → `ollama`
- OpenClaw config types: `ModelApi` includes `"ollama"`
- OpenClaw docs: `docs/providers/ollama.md` confirms native `/api/chat` endpoint
## Changes
- `src/agents/pi-embedded-runner/model.ts` - Added `PROVIDER_API_MAP` and `inferApiForProvider()`
- `src/agents/pi-embedded-runner/model.test.ts` - Added 5 new tests (all passing, 28 total)
## Testing
```bash
npm test -- model.test.ts
```
All 28 tests passing, including new tests for:
- ✅ Anthropic unknown models use `anthropic-messages`
- ✅ Bedrock unknown models use `bedrock-converse-stream`
- ✅ Google unknown models use `google-generative-ai`
- ✅ Ollama unknown models use `ollama`
- ✅ Unknown providers default to `openai-responses`
## Impact
- Fixes silent failures for Anthropic OAT tokens with unknown/future models
- Prevents similar routing issues for Bedrock, Google, and Ollama
- Maintains backward compatibility (unknown providers still default to `openai-responses`)
## Related
- Issue #20107 (this fix)
- Issue #20079 (separate `-1m` suffix issue)
- PR #20104 (fixes only the `-1m` case, doesn't address routing)
Most Similar PRs
#13976: fix(anthropic): include Anthropic in tool call ID sanitization
by omair445 · 2026-02-11
72.7%
#2353: fix: ensure api field is set for inline provider models
by sbknana · 2026-01-26
72.7%
#13188: fix: add cross-provider fallback when primary provider is rate-limited
by 1bcMax · 2026-02-10
72.1%
#21977: Preserve provider API for discovered Ollama models
by graysurf · 2026-02-20
71.3%
#19407: fix(agents): strip thinking blocks on cross-provider model switch (...
by lailoo · 2026-02-17
71.0%
#10108: fix: override stale Anthropic OAuth stealth headers for Opus 4.6
by CivilBooks · 2026-02-06
70.6%
#13831: fix(agents): include Anthropic in tool call ID sanitization
by lailoo · 2026-02-11
70.1%
#16891: fix(models): generic opus-4-6 forward-compat for all providers
by battman21 · 2026-02-15
69.7%
#7821: feat: Support ANTHROPIC_BASE_URL environment variable for custom en...
by y1y2u3u4 · 2026-02-03
69.4%
#17015: fix: correct Claude 4.5 context limits in model registry
by Limitless2023 · 2026-02-15
69.3%