Repository navigation
feat(cz-git,plugin-loader): add apiExtraBody option - #262
Merged
Merged
Conversation
The AI request body is hardcoded, so a model that rejects one of its fields cannot be used at all. Models which require `max_completion_tokens` are the current case: they reject `max_tokens` at any value, and accept only the default `temperature`. `apiExtraBody` is merged into the request body, and a `null` value removes the field instead of overriding it, because such fields have to be absent from the request rather than carry a different value. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
π· Deploy request for cz-git pending review.Visit the deploys page to approve it
|
Zhengqbbb
added a commit
that referenced
this pull request
Aug 18, 2026
Owner
|
LGTM π |
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.
Related ISSUE
#261
Type Of Change
Clear Describe
apiExtraBodyoption to adjust the AI request bodyapiExtraBodyoption document (en / zh)Description
useModelStrategy()builds one fixed request body for every model, and none of its fields can bereached from config. As reported in #261, models which require
max_completion_tokensthereforecannot be used at all: they reject
max_tokensat any value, and accept only the defaulttemperature.apiExtraBodyis merged into the request body after the defaults are built.The one design point worth reviewing: a
nullvalue removes the field instead of overriding it.A plain merge is not enough here β sending
max_tokensalongsidemax_completion_tokensstillfails, and
max_tokens: nullfails as well, so the key has to be absent from the JSON entirely.temperature, by contrast, could be repaired by overriding it with1;nulljust keeps the twocases uniform.
Notes on the implementation:
aiLoader()the key is spread only when it is set, so an unset value in~/.config/.czrccannot clobber a project-level
apiExtraBody.useModelStrategyis now exported so it can be unit tested. It is not re-exported fromgenerator/index.ts, so the public API is unchanged.apiModel,apiEndpoint, β¦) are not part ofscripts/czrc-schema.d.tstoday, soapiExtraBodyfollows the same treatment. Happy to add themall if you would prefer.
β Please review the Chinese documentation
The Chinese docs in this PR β
docs/zh/config/engineer.mdanddocs/zh/recipes/openai.mdβ werewritten with AI assistance. I do not read Chinese and cannot verify the wording myself, so
please review those two files closely rather than trusting them. I would much rather you correct
or rewrite them than merge phrasing I am unable to check.
If you prefer, I can drop the zh changes from this PR entirely and leave them to you.
Test Case
Unit tests β added
packages/cz-git/__tests__/api.test.ts(6 cases): default payload unchanged,add a field, override a field, remove a field via
null, themax_completion_tokensscenario, andthat the option object is not mutated.
Against the real API β loaded the config above from
~/.config/.czrcthroughconfigLoader()β
generateOptions()βuseModelStrategy(), then posted the resulting body toapi.openai.com/v1/chat/completions:apiModel: gpt-5.6-luna+ theapiExtraBodyabovemodel, messages, stream, top_p, n, max_completion_tokensapiModel: gpt-4o-mini, noapiExtraBodymodel, messages, stream, top_p, temperature, max_tokens, nThe second row is the regression check: with no
apiExtraBodyset, the request body is identical towhat it was before this change.
Unrelated note, in case it is useful: 4 tests in
packages/@cz-git/plugin-loader/__tests__/loader.test.tsfail on my machine both with and withoutthis change, because
aiLoader()reads the real$HOME/.config/.czrc. They pass with a cleanHOME, and CI onmainis green β so it is not a regression here, but it may be worth isolatingthat test from the developer's home config.