fix(models): use /v1/models?provider=<slug> and drop hardcoded fallbacks#7
Open
siddharthsambharia-portkey wants to merge 1 commit into
Open
fix(models): use /v1/models?provider=<slug> and drop hardcoded fallbacks#7siddharthsambharia-portkey wants to merge 1 commit into
siddharthsambharia-portkey wants to merge 1 commit into
Conversation
- Removed the normalization of provider headers and updated the fetchModels function to use the provider query parameter for model retrieval. - Updated testGatewayConnection to require a model parameter, ensuring explicit model specification for connection tests. - Removed fallback model suggestions in setup.js, enforcing exclusive use of models from the Portkey catalog. - Enhanced error handling for missing model configurations in the verify function.
There was a problem hiding this comment.
Pull request overview
This PR updates Claude Code setup/verification to rely exclusively on Portkey’s Model Catalog API (GET /v1/models?provider=<slug>) rather than merging in hardcoded model fallbacks, aligning CLI behavior with the gateway’s actual routable model set.
Changes:
- Switch model discovery to
/v1/models?provider=<slug>and removex-portkey-providerusage for the models endpoint. - Remove bundled
MODEL_DEFAULTS/curated model suggestions so the picker reflects only the API response. - Require an explicit configured model for verification/connection testing; add gateway model discovery env flag and ensure uninstall removes it.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/api.js |
Updates fetchModels request shape to use provider query param; makes testGatewayConnection require a caller-supplied model. |
src/commands/claude-code/setup.js |
Removes hardcoded model fallback lists/merging; updates prompts; enforces --model in certain --yes config flows; writes CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1. |
src/commands/claude-code/verify.js |
Drops hardcoded model fallback and now requires a configured model to run verification. |
src/commands/claude-code/uninstall.js |
Ensures the new gateway model discovery env var is removed during uninstall. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const existing = readExistingConfig(); | ||
| const gateway = process.env.ANTHROPIC_BASE_URL || existing.gateway || PORTKEY_GATEWAY; | ||
| const testModel = existing.model || "claude-haiku-4-20250514"; | ||
| const testModel = existing.model; |
Comment on lines
107
to
111
| try { | ||
| const data = await fetchJSON(`${base(gateway)}/v1/models`, { | ||
| "x-portkey-api-key": portkeyKey, | ||
| "x-portkey-provider": providerHeader, | ||
| const url = `${base(gateway)}/v1/models?provider=${encodeURIComponent(slug)}`; | ||
| const data = await fetchJSON(url, { | ||
| "x-portkey-api-key": portkeyKey, | ||
| }); |
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
Fixes two issues with model selection during
portkey setup:The CLI was showing more models than the API actually returns. We were merging a hardcoded
MODEL_DEFAULTStable (anthropic, openai, azure, google, mistral, cohere, groq, deepseek) on top of the gateway's/v1/modelsresponse, so stale or invented models leaked into the picker.The provider slug was being sent as the
x-portkey-providerheader, but Portkey's/v1/modelsexpects it as a query parameter (?provider=<slug>) — same shape as:Changes
src/api.jsfetchModelsnow hitsGET /v1/models?provider=<slug>and no longer sendsx-portkey-provider. Leading@is stripped from the slug.testGatewayConnectionrequires the caller to pass amodel; the hardcodedclaude-haiku-4-20250514default is gone.src/commands/claude-code/setup.jsMODEL_DEFAULTSmap,getModelOptions(), and the merge step that appended curated suggestions to the API response. The picker now shows exactly what/v1/models?provider=<slug>returns.providerTypetracking variable.e.g. gpt-4o,e.g. claude-sonnet-4-20250514) in the Codex/alias flows.--yesmode with a Config (no single provider), the CLI now errors if--modelisn't supplied instead of defaulting togpt-4o.CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1into the env block ofsettings.json(and the shell-rc env block) so Claude Code asks the Portkey gateway for the model list at runtime instead of using its hardcoded Anthropic list.src/commands/claude-code/verify.jsclaude-haiku-4-20250514fallback — if no model is configured the CLI tells the user to runportkey setup.src/commands/claude-code/uninstall.jsCLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERYtoENV_KEYS_TO_REMOVEso uninstall cleans it up fromsettings.jsonandprocess.env.Net effect
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1is set automatically, so Claude Code's/modelpicker also reflects the gateway catalog instead of Anthropic's bundled list.Test plan
npm test— all 121 tests pass locally.npx portkey setupagainst a Cohere virtual key and confirm the picker shows exactly the 33 models returned byGET /v1/models?provider=cohere-main-77fe39(no extras).~/.claude/settings.json(or chosen scope) after setup and confirmenv.CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY === "1".portkey uninstalland confirm the key is removed./modeland confirm gateway-discovered models appear.Made with Cursor