Skip to content

fix(proxy): resolve 400 Bad Request for gemini-3.1-pro-high model#187

Open
abhijeetatgit wants to merge 1 commit into
Draculabo:mainfrom
abhijeetatgit:fix/gemini-model-routing-and-thinking-budget
Open

fix(proxy): resolve 400 Bad Request for gemini-3.1-pro-high model#187
abhijeetatgit wants to merge 1 commit into
Draculabo:mainfrom
abhijeetatgit:fix/gemini-model-routing-and-thinking-budget

Conversation

@abhijeetatgit
Copy link
Copy Markdown

Summary

The upstream Google API rejects gemini-3.1-pro-high as a model name with 400 INVALID_ARGUMENT, causing all requests using the high-tier Gemini Pro model to fail.

Changes

src/modules/proxy-gateway/antigravity/model-specs.json

  • Reduce thinking_budget for gemini-3.1-pro-high from 49152 to 32768 to match the API's accepted maximum. Values above 32768 trigger a 400 error.

src/modules/proxy-gateway/server/token-manager.service.ts

  • In buildDynamicModelCandidates(), prioritize gemini-3.1-pro-preview as the first fallback candidate when gemini-3.1-pro-high or gemini-3.1-pro is requested.
  • The upstream API accepts -preview but rejects -high, so this ensures requests succeed on the first attempt.
  • The existing deduplication logic (seen set) ensures no model name is tried twice in the fallback sequence.

Testing

  • Verified that requests using gemini-3.1-pro-high model no longer return 400 errors.
  • The -preview variant is functionally equivalent and accepted by the upstream API.

The upstream Google API rejects 'gemini-3.1-pro-high' as a model name
with 400 INVALID_ARGUMENT. This causes all requests using the high-tier
Gemini Pro model to fail.

Changes:
- model-specs.json: Reduce thinking_budget for gemini-3.1-pro-high
  from 49152 to 32768 to match the API's accepted maximum.
- token-manager.service.ts: Prioritize 'gemini-3.1-pro-preview' as
  the first fallback candidate when 'gemini-3.1-pro-high' or
  'gemini-3.1-pro' is requested, since '-preview' is accepted by
  the upstream API while '-high' is not.

The deduplication logic (seen set) ensures that the same model name
is never tried twice in the fallback sequence.
Comment on lines 1119 to 1135
}
};

// Keep requested model first, then fallback across the same family.
pushCandidate(normalizedModel);
// When the requested model is gemini-3.1-pro-high or gemini-3.1-pro,
// prioritize gemini-3.1-pro-preview as the first candidate. The upstream
// API rejects the '-high' suffix with 400 INVALID_ARGUMENT.
if (normalizedModel === 'gemini-3.1-pro-high' || normalizedModel === 'gemini-3.1-pro') {
pushCandidate('gemini-3.1-pro-preview');
pushCandidate('gemini-3.1-pro');
pushCandidate(normalizedModel);
} else {
pushCandidate(normalizedModel);
}

pushCandidate('gemini-3.1-pro-preview');
pushCandidate('gemini-3-pro-preview');
pushCandidate('gemini-3.1-pro-high');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainability Concern:
The candidate model list and prioritization logic are hardcoded, which reduces flexibility and maintainability. If the set of supported models changes, this function will require manual updates. Consider externalizing the candidate list and prioritization rules to configuration or constants, or making the logic more data-driven to facilitate easier updates and reduce risk of errors.

Example improvement:

const proFamilyCandidates = getProFamilyCandidatesFromConfig();
// ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant