Fix Cohere provider-prefixed model routing#22
Merged
Conversation
📝 WalkthroughWalkthroughRefactors provider detection to use ChangesCohere Provider Prefix Stripping and Detection Unification
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
- `DetectProviderFromModel` now reads `knownProviderPrefixes` - Routes `cohere/` and `deepseek/` IDs, not `ErrNoProvider` - Removes the duplicate prefix `switch` that had drifted - Adds test asserting every stripped prefix is routable
jhaynie
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cohere/public model prefixes before forwarding to Coherecohere/anddeepseek/providers by name from that same listAutoRouterregression coverage for a prefixed Cohere catalog IDWhy
When AI Gateway sends a public model ID like
cohere/command-a-plus-05-2026, Cohere's compatibility API expects the native model ID:{ "model": "command-a-plus-05-2026" }AutoRouterkeeps provider-prefix knowledge in one map,knownProviderPrefixes, used for two jobs:stripProviderPrefix) rewritescohere/x→xbefore forwarding.DetectProviderFromModel) mapscohere/x→ providercohere.These previously read two separate hand-maintained lists.
cohere(this PR) anddeepseek(an earlier PR) were added to the strip list but never the routing switch, so a direct consumer sendingcohere/...with noX-Providerheader gotErrNoProvider. Through AI Gateway the gap was masked (Ion setsX-Providerand carries its own prefix fallback), so it was latent rather than a live outage.flowchart TD R["model: cohere/command-a-plus-05-2026"] --> H{"X-Provider header set?"} H -- yes --> U["use header value"] H -- no --> D["DetectProviderFromModel(model)"] D --> M{"prefix in knownProviderPrefixes?"} M -- yes --> PV["provider = cohere"] M -- no --> NH["name heuristics, else ErrNoProvider"] PV --> SP["stripProviderPrefix() reads same map"] SP --> UP["upstream gets command-a-plus-05-2026"]Implementation
Cohere stays in the central prefix-stripping path used by providers such as DeepSeek:
DetectProviderFromModelnow reads that same map instead of a second hardcodedswitch, so a prefix the router strips is always a prefix it can route:A new guard asserts every stripped prefix is routable, so the two lists can't silently drift again:
The
AutoRouterregression still exercisesAutoRouter.Forwardand asserts the fake Cohere upstream receives the stripped model, and the gated live regression still uses the public ID shapecohere/command-a-plus-05-2026.Verification
Prefix-routing change (this commit):
go test . -run 'TestDetectProviderFromModel|TestDefaultProviderDetector|TestAutoRouter_Cohere|TestStripProviderPrefix' -count=1go build ./...andgo vet ./...go test ./... -count=1Carried from the strip commit (re-run after stacking before merge):
go test -race ./... -count=1go test -tags integration ./... -run 'TestLiveAIGatewayRegressionModels' -count=1make testblocked locally atgovulncheckbecause local Go isgo1.26.2and the stdlib vuln gate requires a newer Go patch versionSummary by CodeRabbit
Bug Fixes
Tests