fix(chat): update OpenAI API to use max_completion_tokens parameter#371
Merged
erichare merged 4 commits intoJun 10, 2026
Merged
Conversation
added 2 commits
June 10, 2026 15:22
- Replace deprecated max_tokens with max_completion_tokens in both streaming and non-streaming chat completions - Update documentation comment in model probe to reflect current parameter name - Add .gitignore patterns for feature development documentation artifacts This aligns with OpenAI's current API specification and ensures compatibility with future API versions. No breaking changes to public API or configuration.
There was a problem hiding this comment.
Pull request overview
Updates the TypeScript runtime’s OpenAI-compatible chat adapter to send the newer token-limit parameter name expected by the OpenAI Chat Completions API, and aligns related inline documentation.
Changes:
- Swapped request body field
max_tokens→max_completion_tokensfor both streaming and non-streaming chat completions. - Updated the model probe doc comment to reflect the new parameter name.
- Added new
.gitignoreentries for a local assistant state directory and certain docs artifacts.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| runtimes/typescript/src/chat/openai.ts | Updates outbound chat completion request bodies to use max_completion_tokens for token limiting (streaming + non-streaming). |
| runtimes/typescript/src/chat/model-probe.ts | Updates probe documentation comment to match the new request parameter name. |
| .gitignore | Adds ignores for .bob/ and specific docs artifact filenames. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
191
to
195
| body: JSON.stringify({ | ||
| model: this.modelId, | ||
| max_tokens: this.maxOutputTokens, | ||
| max_completion_tokens: this.maxOutputTokens, | ||
| messages: toOpenAIMessages(request.messages), | ||
| ...toolFields(request.tools), |
…hape tests Assert that both complete and streaming requests send max_completion_tokens (and never the deprecated max_tokens), so a silent revert of the parameter rename across OpenAI/OpenRouter/Ollama fails the suite. Addresses Copilot review feedback.
…es max_completion_tokens Ollama's /v1/chat/completions only honors max_tokens and silently drops unknown fields (ollama/ollama#7125 is still open), so sending max_completion_tokens unconditionally turned the output cap into a no-op for Ollama chats and made the 1-token model probe generate full-length responses. Name the cap field per provider instead: max_completion_tokens everywhere, max_tokens when providerId is ollama. Sending both is not an option because OpenAI rejects requests that set both. Adds wire-shape tests for the Ollama complete + streaming paths.
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
This PR updates the OpenAI chat completion API parameter from
max_tokenstomax_completion_tokensin the TypeScript runtime.What changed:
max_tokenswithmax_completion_tokensin both streaming and non-streaming chat completion requests (runtimes/typescript/src/chat/openai.tslines 193 and 264)model-probe.tsline 88 to reflect the correct parameter nameWhy it changed:
max_tokensin favor ofmax_completion_tokensas the standard parameter nameWho it affects:
OpenAIChatServiceclass is shared by all three providers, so this change affects all of themProvider Compatibility:
All three providers have been tested and verified compatible with
max_completion_tokens:Validation
max_completion_tokensis the correct parameter name in OpenAI's current API specificationChecklist
mainwith a descriptive prefix (feat/,fix/,chore/,docs/,refactor/, ortest/).not applicable is documented above.
npm run check, or the narrower commandslisted in
CONTRIBUTING.md).--no-verifyor--no-gpg-sign.documentation changes, or documented why one is not needed.
docs/api-spec.md, addedor regenerated conformance coverage, and kept runtime scaffolds in sync.
workbench.yaml, I documented the migration and keptexamples current.
Note on changeset: No changeset needed - this is an internal implementation detail that maintains backward compatibility. The public API (
maxOutputTokensconfiguration) remains unchanged, and all existing tests pass without modification.