fix(engine): map anthropic-compatible custom providers to anthropic-messages api - #1702
Conversation
…essages api resolveCustomProviderApiType mapped the `anthropic-compatible` provider type to the api key "anthropic", but pi-ai (@earendil-works/pi-ai) registers the Anthropic Messages API under "anthropic-messages". Any custom provider configured as anthropic-compatible selected a model whose `api` did not match a registered provider, throwing "No API provider registered for api: anthropic" at stream time (the model registered fine, but failed when a task tried to stream). The openai-responses and default (openai-completions) arms already map to real registry keys and work; only the anthropic arm pointed at an unregistered key. Extend the existing custom-provider registration test (which covered openai-compatible and openai-responses but not anthropic-compatible) with a regression assertion that anthropic-compatible maps to "anthropic-messages". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Ready to review this PR? Stage has broken it down into 3 individual chapters for you:
Chapters generated by Stage for commit efd3743 on Jun 21, 2026 9:00am UTC. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesAnthropic-compatible provider mapping fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/engine/src/__tests__/pi-create-fn-agent.test.ts`:
- Around line 1398-1406: The current regression test for the
anthropic-compatible provider in the test file only asserts one specific path.
You need to expand this regression test to cover all documented surfaces in
docs/testing.md to ensure comprehensive coverage of the bug guard. Review the
testing documentation to identify the full surface checklist, then add
additional test cases or assertions within the test function to validate each
documented surface. Additionally, convert the inline comment explaining the
regression requirement (the comment block starting with "anthropic-compatible
must map...") from plain TS comment format to FNXC-formatted requirement
metadata as per the coding guidelines for test files.
- Around line 1401-1406: The test assertion for registerProviderMock only
validates that the correct "custom-anthropic" provider is registered but does
not explicitly prevent an incorrect bare "anthropic" registration from
occurring. Add a negative assertion using not.toHaveBeenCalledWith to verify
that registerProviderMock was never called with just "anthropic" as the provider
identifier, which will strengthen the regression test by explicitly guarding
against the unwanted provider registration.
In `@packages/engine/src/pi.ts`:
- Around line 1011-1014: The comment block describing the Anthropic Messages API
registration requirement is not in FNXC format. Convert this comment block to
use the FNXC-formatted metadata pattern following the structure
FNXC:<Area-of-product> yyyy-MM-dd-hh:mm: to maintain requirement traceability
consistency across the repository. Replace the existing multi-line comment with
the standardized FNXC format while preserving the core decision information
about mapping "anthropic" to "anthropic-messages" for the API provider registry.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: dd7ae5d0-af3c-41fa-8cd3-91ab75c6811a
📒 Files selected for processing (3)
.changeset/fix-anthropic-compatible-custom-provider.mdpackages/engine/src/__tests__/pi-create-fn-agent.test.tspackages/engine/src/pi.ts
- Add JSDoc to resolveCustomProviderApiType (docstring coverage + AGENTS.md
jsdoc convention) and convert the inline rationale to FNXC format.
- FNXC-format the test rationale comment.
- Strengthen the regression test per FN-5893 (fix the invariant, not the repro):
- negative assertion that no provider is ever registered with the bare
"anthropic" api key;
- assert every api key passed to registerProvider is one pi-ai's registry
actually registers, so a typo in any arm (not just anthropic) fails here.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Addressed the CodeRabbit feedback in efd3743:
Verification: |
|
Great fix thank you |
Problem
Adding a custom provider with
apiType: "anthropic-compatible"(e.g. a self-hosted Claude proxy or an enterprise AI gateway) registers fine, but any task that tries to run a model from it fails at stream time with:The provider is visible in the model picker and
[pi] Registered custom provider "<name>"is logged, so it looks configured — the failure only surfaces when an agent actually streams.Root cause
resolveCustomProviderApiTypeinpackages/engine/src/pi.tsmapsanthropic-compatibleto the api key"anthropic":But pi-ai (
@earendil-works/pi-ai) registers the Anthropic Messages API under"anthropic-messages"(seeregisterBuiltInApiProviders()indist/providers/register-builtins.js— the registered keys areanthropic-messages,openai-completions,openai-responses,azure-openai-responses,openai-codex-responses,google-generative-ai,google-vertex,mistral-conversations,bedrock-converse-stream).At stream time, pi-ai's
resolveApiProvider(model.api)callsgetApiProvider("anthropic"), getsundefined, and throws. The other two arms ofresolveCustomProviderApiType(openai-responsesand the defaultopenai-completions) map to real registry keys and work — only the anthropic arm pointed at a key that is never registered.Fix
Map
anthropic-compatible→"anthropic-messages"(one line + clarifying comment).Tests
The existing registration test (
registers custom providers from global settings) coveredopenai-compatibleandopenai-responsesbut notanthropic-compatible— which is how this shipped. Extended it with ananthropic-compatibleprovider assertingapi: "anthropic-messages"is what gets registered, as a regression guard.pnpm --filter @fusion/engine test:core→ 649 passedpi-create-fn-agent.test.ts→ 76 passedpnpm --filter @fusion/engine typecheck→ cleanVerification
Reproduced end-to-end against a real
anthropic-compatiblegateway: before the fix, planning failed withNo API provider registered for api: anthropic; after the fix (running from source viapnpm dev dashboard), a task planned successfully using<provider>/claude-opus-4-8with the model streaming normally and no errors.🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests