From 2f23efc26969960afd9f9d87e755567c129732a8 Mon Sep 17 00:00:00 2001 From: Azizultra32 Date: Tue, 24 Mar 2026 16:24:55 -0700 Subject: [PATCH] fix: use max_completion_tokens instead of deprecated max_tokens The OpenAI API deprecated `max_tokens` in favor of `max_completion_tokens` for chat completion endpoints. Newer models (gpt-4o, o1, o3, gpt-5.x) reject `max_tokens` with: "Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead." This updates both the OpenAI and Azure OpenAI text completion providers to use the new parameter name. Fixes both streaming and non-streaming code paths. --- .../trustgraph/model/text_completion/azure_openai/llm.py | 4 ++-- .../trustgraph/model/text_completion/openai/llm.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/trustgraph-flow/trustgraph/model/text_completion/azure_openai/llm.py b/trustgraph-flow/trustgraph/model/text_completion/azure_openai/llm.py index 4ab0b302..9d803c90 100755 --- a/trustgraph-flow/trustgraph/model/text_completion/azure_openai/llm.py +++ b/trustgraph-flow/trustgraph/model/text_completion/azure_openai/llm.py @@ -90,7 +90,7 @@ class Processor(LlmService): } ], temperature=effective_temperature, - max_tokens=self.max_output, + max_completion_tokens=self.max_output, top_p=1, ) @@ -159,7 +159,7 @@ class Processor(LlmService): } ], temperature=effective_temperature, - max_tokens=self.max_output, + max_completion_tokens=self.max_output, top_p=1, stream=True, stream_options={"include_usage": True} diff --git a/trustgraph-flow/trustgraph/model/text_completion/openai/llm.py b/trustgraph-flow/trustgraph/model/text_completion/openai/llm.py index d65e27bf..cdc8602a 100755 --- a/trustgraph-flow/trustgraph/model/text_completion/openai/llm.py +++ b/trustgraph-flow/trustgraph/model/text_completion/openai/llm.py @@ -86,7 +86,7 @@ class Processor(LlmService): } ], temperature=effective_temperature, - max_tokens=self.max_output, + max_completion_tokens=self.max_output, ) inputtokens = resp.usage.prompt_tokens @@ -152,7 +152,7 @@ class Processor(LlmService): } ], temperature=effective_temperature, - max_tokens=self.max_output, + max_completion_tokens=self.max_output, stream=True, stream_options={"include_usage": True} )