feat(openai): expose max_output_tokens on Responses API LLM#5449
Open
piyush-gambhir wants to merge 1 commit intolivekit:mainfrom
Open
feat(openai): expose max_output_tokens on Responses API LLM#5449piyush-gambhir wants to merge 1 commit intolivekit:mainfrom
piyush-gambhir wants to merge 1 commit intolivekit:mainfrom
Conversation
Adds max_output_tokens as a first-class constructor argument on the OpenAI, Azure, and xAI Responses API LLM wrappers, mirroring how service_tier is handled. Previously callers had to reach for extra_kwargs per-call to set an upper bound on generated tokens, even though the underlying /v1/responses endpoint accepts max_output_tokens natively.
4 tasks
Contributor
Author
|
Smoke test (live OpenAI API,
|
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
Adds
max_output_tokensas a first-class constructor argument on the OpenAI, Azure, and xAI Responses API LLM wrappers β mirroring howservice_tieris handled today (#5346).The underlying
/v1/responsesendpoint acceptsmax_output_tokensnatively (seeopenai.types.responses.response_create_params), but the plugins previously required callers to reach forextra_kwargson everychat()call to set it. This PR makes it a plain constructor arg so a bound can be set once at LLM construction time.Changes
livekit-plugins-openai/.../responses/llm.py: addmax_output_tokens: NotGivenOr[int]to_LLMOptionsand theLLM.__init__signature; forward it intoextraso it reaches both the HTTP (client.responses.create) and WebSocket (response.create) paths.livekit-plugins-azure/.../responses/llm.py: thread the new arg through toopenai.responses.LLM.__init__.livekit-plugins-xai/.../responses/llm.py: thread the new arg through toopenai.responses.LLM.__init__.Usage
Motivation
All sibling chat-completions LLMs (
openai.LLM,anthropic.LLM,google.LLM,aws.LLM,mistralai.LLM,groq.LLM) already expose a first-classmax_completion_tokens/max_tokens/max_output_tokensargument. The Responses variants were the only remaining path that forced callers intoextra_kwargs. This brings them in line.Test plan
ast.parsepasses on all three modified filesmake check(format + lint + type-check)openai.responses.LLM(model="gpt-4.1", max_output_tokens=64)and verify the response honors the cap in bothuse_websocket=Trueanduse_websocket=Falsemodes