← Back to PRs

#20593: fix: route Anthropic OAT tokens to /v1/messages endpoint (#20107)

by KyleKincer open 2026-02-19 03:51 View on GitHub →
agents size: S
## 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