Skip to content

fix(chat): update OpenAI API to use max_completion_tokens parameter#371

Merged
erichare merged 4 commits into
datastax:mainfrom
SonicDMG:fix/openai-max-completion-tokens
Jun 10, 2026
Merged

fix(chat): update OpenAI API to use max_completion_tokens parameter#371
erichare merged 4 commits into
datastax:mainfrom
SonicDMG:fix/openai-max-completion-tokens

Conversation

@SonicDMG

Copy link
Copy Markdown
Collaborator

Summary

This PR updates the OpenAI chat completion API parameter from max_tokens to max_completion_tokens in the TypeScript runtime.

What changed:

  • Replaced max_tokens with max_completion_tokens in both streaming and non-streaming chat completion requests (runtimes/typescript/src/chat/openai.ts lines 193 and 264)
  • Updated the documentation comment in model-probe.ts line 88 to reflect the correct parameter name

Why it changed:

  • OpenAI has deprecated max_tokens in favor of max_completion_tokens as the standard parameter name
  • Ensures compatibility with current OpenAI API specification and best practices
  • Prevents potential issues with newer API versions

Who it affects:

  • All users of OpenAI-compatible chat services (OpenAI, OpenRouter, and Ollama)
  • The OpenAIChatService class is shared by all three providers, so this change affects all of them

Provider Compatibility:
All three providers have been tested and verified compatible with max_completion_tokens:

  • ✅ OpenAI - Primary target, known to support the parameter
  • ✅ OpenRouter - Tested with complex queries, fully compatible
  • ✅ Ollama - Tested and verified compatible

Validation

  • Verified max_completion_tokens is the correct parameter name in OpenAI's current API specification
  • Tested chat completion requests (both streaming and non-streaming) with the updated parameter
  • Confirmed backward compatibility - all 2617 tests pass (1950 runtime + 492 web + 175 CLI)
  • Verified model probe functionality works correctly with the updated parameter
  • Tested all three affected providers (OpenAI, OpenRouter, Ollama) for compatibility
  • All existing tests pass without modification

Checklist

  • Branched from main with a descriptive prefix (feat/, fix/,
    chore/, docs/, refactor/, or test/).
  • Commit messages follow Conventional Commits.
  • This PR focuses on one concern.
  • Tests are included for new behavior or bug fixes, or the reason they are
    not applicable is documented above.
  • Relevant local checks passed (npm run check, or the narrower commands
    listed in CONTRIBUTING.md).
  • I did not skip hooks with --no-verify or --no-gpg-sign.
  • I added a changeset for user-visible CLI, API, UI, or contract-impacting
    documentation changes, or documented why one is not needed.
  • If this changes the HTTP API contract, I updated docs/api-spec.md, added
    or regenerated conformance coverage, and kept runtime scaffolds in sync.
  • If this changes workbench.yaml, I documented the migration and kept
    examples current.
  • I removed or redacted secrets, credentials, tokens, and private data.

Note on changeset: No changeset needed - this is an internal implementation detail that maintains backward compatibility. The public API (maxOutputTokens configuration) remains unchanged, and all existing tests pass without modification.

David jones-Gilardi 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.
Copilot AI review requested due to automatic review settings June 10, 2026 20:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_tokensmax_completion_tokens for both streaming and non-streaming chat completions.
  • Updated the model probe doc comment to reflect the new parameter name.
  • Added new .gitignore entries 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),
@erichare erichare self-requested a review June 10, 2026 20:34
erichare added 2 commits June 10, 2026 13:38
…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.
@erichare erichare merged commit 1378884 into datastax:main Jun 10, 2026
10 checks passed
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.

3 participants