create_react_agent bad request with gpt-oss-120b tool calls and Responses API
Fix bad request errors when using create_react_agent with gpt-oss-120b tool calls by adjusting Responses API settings in ChatOpenAI.
The symptom
When calling a create_react_agent built with ChatOpenAI configured for gpt-oss-120b and tool calls, the request fails with a bad request error. The exact error text is not included in the thread, but it occurs during the agent's execution, likely when the model attempts to invoke a tool or when the response is parsed.
The developer sees the failure after setting use_responses_api=True and output_version='responses/v1' in the ChatOpenAI constructor. The error may surface as an HTTP 400 from the API or as a parsing exception in LangChain.
Why it happens
The root cause is not definitively confirmed in the thread. Based on the discussion, the most likely cause is that the Responses API mode is not fully compatible with gpt-oss-120b when used with tool calls in create_react_agent. The API may return a response that LangChain cannot map to the expected tool call structure, leading to a bad request or a state mismatch.
A second hypothesis is a synchronization issue between LangGraph's expected state and the API's response format. The agent expects a valid tool call message, but the API may return a different structure when the Responses API is enabled.
A third possibility is that the combination of streaming=True and the Responses API introduces timing or parsing issues. However, this is not confirmed.
- To confirm the first cause: remove use_responses_api and output_version, then rerun the same code. If the error disappears, the Responses API path is the culprit.
- To confirm the second cause: log the raw API response and compare it to the expected tool call schema. Look for missing or malformed tool call fields.
- To confirm the third cause: set streaming=False and test again. If the error persists, streaming is not the issue.
How to fix it
- Remove the parameters use_responses_api=True and output_version='responses/v1' from the ChatOpenAI constructor. This is the suggested quick fix from the community.
- Ensure that your model name is correctly specified as 'openai/gpt-oss-120b' and that the base_url points to a compatible endpoint.
- If you need the Responses API features, test with a minimal example that does not use create_react_agent to isolate whether the issue is specific to the agent integration.
- Check the LangChain and LangGraph versions for any known issues; update to the latest patch if available.
- If the error persists, capture the full error message and the request payload, then open a new issue with those details.
When this is not the cause
If removing use_responses_api and output_version does not fix the error, the problem may lie elsewhere. For example, the tool definition might be incompatible with the model, or the API endpoint might not support the model at all. In that case, verify that the model name is correct and that your API key has access to it.
Another differential is the reasoning parameter. If you set reasoning={'effort': 'high', 'summary': 'auto'}, try removing it to see if the error changes. Some models may not support reasoning parameters in certain API modes.
Finally, check for network issues or proxy configurations that could cause bad requests. Use a simple curl command to test the API directly.
How to apply this with Admesh
Admesh provides an OpenAI-compatible endpoint at https://api.admesh.ai/v1, so you can use the same ChatOpenAI class with base_url set to that URL. This allows you to route requests to multiple model families with a single API key and balance.
To avoid the Responses API compatibility issue, configure ChatOpenAI without use_responses_api and output_version when using Admesh. For example: model = ChatOpenAI(model='openai/gpt-oss-120b', api_key='YOUR_ADMESH_KEY', base_url='https://api.admesh.ai/v1'). This uses the standard chat completions endpoint, which is more widely supported.
If you need to use the Anthropic-compatible endpoint, set base_url to https://api.admesh.ai/v1/messages and adjust the model name accordingly. Check the model catalog at https://admesh.ai/models for available models and their capabilities.
For detailed configuration and examples, refer to the Admesh documentation at https://docs.admesh.ai. You can manage your API keys and balance in the console at https://console.admesh.ai.
FAQ
Is the Responses API supported with gpt-oss-120b?
Why does the error only occur with tool calls?
Can I still use streaming with the workaround?
What should I do if the error persists after removing those parameters?
References
Call these models through one gateway
Admesh provides a unified OpenAI-compatible API: one Base URL and one key for Claude, GPT, DeepSeek and more. New accounts get trial credit that never expires.
