Gemini API (OpenAI-compatible) gemini-2.5-flash-preview-05-20
causes AttributeError
in Agents SDK when tools
are specified
#744
Labels
bug
Something isn't working
Please read this first
Describe the question
When using the Agents SDK with Google's Gemini API (OpenAI-compatible endpoint
https://generativelanguage.googleapis.com/v1beta/openai/
) as a custom model provider, using thegemini-2.5-flash-preview-05-20
model withtools
specified in theAgent
leads to anAttributeError: 'NoneType' object has no attribute 'model_dump'
within the SDK'sopenai_chatcompletions.py
file.This error occurs because the Gemini API returns a
ChatCompletion
object wherechoices[0].message
isNone
. Debugging reveals thefinish_reason
for thisNone
message iscontent_filter: OTHER
.Key observations:
AttributeError
(and the underlyingNone
message withcontent_filter: OTHER
) does not occur with the oldergemini-2.5-flash-preview-04-17
model when tools are specified.AttributeError
does not occur with thegemini-2.5-flash-preview-05-20
model iftools
are omitted from theAgent
initialization.This suggests an issue with how the
gemini-2.5-flash-preview-05-20
model (via its OpenAI-compatible API) handles requests that include thetools
parameter, leading to a response structure that causes an error in the Agents SDK.Debug information
v0.0.16
(approximated, based on User-Agent during testing)Repro steps
openai-agents
,openai
libraries. PointOpenAIChatCompletionsModel
to Gemini's OpenAI-compatible endpoint with a valid API key.openai_chatcompletions.py
is in its original state, without the manual error handling forNone
messages):CURRENT_MODEL_TO_TEST
set toMODEL_WITH_ISSUE
.AttributeError: 'NoneType' object has no attribute 'model_dump'
atagents\models\openai_chatcompletions.py", line 78
. If the SDK is modified to inspect the response before this line, it's seen thatresponse.choices[0].message
isNone
andresponse.choices[0].finish_reason
iscontent_filter: OTHER
.Expected behavior
The
gemini-2.5-flash-preview-05-20
model, when used with the Agents SDK via its OpenAI-compatible endpoint and withtools
specified, should return aChatCompletion
object wherechoices[0].message
is properly populated (with text content ortool_calls
). This would prevent theAttributeError
in the SDK and allow for normal tool use, consistent withgemini-2.5-flash-preview-04-17
or when tools are omitted for the05-20
model. The API should not return aNone
message withcontent_filter: OTHER
solely due to the presence of thetools
parameter for innocuous prompts.The text was updated successfully, but these errors were encountered: