Support a per-model input context window override for custom gateways

Open
#30,333 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
58/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
ai, cli

Research direction

Start with packages/core/src/core/tokenLimits.ts and trace how model configuration reaches token budgeting and compaction. Check the documented modelConfigs settings and the tests covering those paths. Done means a validated per-model contextWindowTokens override is used when supplied, invalid values are rejected, and existing Gemini defaults remain the fallback; test values below and above 1,048,576.

Written by the indexing model from the issue text.

Description

status/need-triage

Custom model gateways can advertise their actual context window, but packages/core/src/core/tokenLimits.ts currently gives every unknown model DEFAULT_TOKEN_LIMIT (1,048,576). The function accepts only the model name. The documented modelConfigs settings allow generation settings such as maxOutputTokens, without an input context-window override.

We encountered this while fixing https://github.com/link-assistant/formal-ai/issues/1582. Our symbolic server derives its context capacity from available resources and publishes context_window_tokens through its model metadata. Assuming the fixed Gemini window can trigger premature compaction when the server supports more, or allow a larger context than a smaller server supports.

Reproduction against the current source (not an installed CLI end-to-end test):

  1. Configure a custom gateway/model named formal-ai whose advertised input window is 1,234,567 tokens.
  2. Evaluate tokenLimit('formal-ai') from packages/core/src/core/tokenLimits.ts.
  3. It returns 1,048,576 regardless of the gateway's advertised value. The default branch cannot receive an override.

Expected: a validated per-model input context-window setting, optionally populated from gateway model discovery. Existing Gemini model defaults should remain the fallback when no override is supplied.

Suggested change: add an optional positive integer contextWindowTokens to model configuration, resolve it alongside the existing model-specific generation configuration, and pass it to the token-budget/compaction code before falling back to tokenLimit(model). Reject invalid/non-finite values and test both values below and above 1,048,576. Do not infer an unlimited context from a model name.

Current workaround: use a client exposing an actual context-window override, or keep the gateway within the fixed window while accepting the reduced capacity. maxOutputTokens alone cannot fix the input budget. We have not patched installed Gemini packages or claimed this workaround satisfies our all-clients acceptance criterion.

Dominant language
TypeScript
Stars
109k
Forks
15k
Avg merge
1d 1h
Merged PRs (30d)
106

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google-gemini/gemini-cli

All issues in google-gemini/gemini-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.