[BUG] Openai Compatible Endpoint Issue
Checks
- [x] I have updated to the lastest minor and patch version of Strands
- [x] I have checked the documentation and this is not expected behavior
- [x] I have searched ./issues and there are no duplicates of my issue
Strands Version
0.1.5
Python Version
3.11.0
Operating System
macOS 15.4.1
Installation Method
pip
Steps to Reproduce
Certain models which use the Openai compatible endpoint capability return a router returned invalid model undefined error; however, the strands logs show that the model was successfully invoked.
Steps to reproduce:
- Install with pip and set up agents.py file as directed on the Welcome page
- Set up a connection to an Openai compatible server as instructed in the user guide. To exactly replicate this error, I'm using models from Arcee Conductor, which you can get an API key for free.
- Add debugging logs as directed in the "Debug Logs" section of the Quickstart
The code now looks like this:
from strands import Agent
from strands.models.openai import OpenAIModel
import logging
# Define model connection details
base_url="https://conductor.arcee.ai/v1"
api_key="" # Your key here
model_id = "auto"
# Enables Strands debug log level
logging.getLogger("strands").setLevel(logging.DEBUG)
# Sets the logging format and streams logs to stderr
logging.basicConfig(#
format="%(levelname)s | %(name)s | %(message)s",
handlers=[logging.StreamHandler()]
)
# Define the model
model = OpenAIModel(
client_args={
"api_key": api_key,
"base_url": base_url,
},
model_id=model_id,
params={
"max_tokens": 1000,
"temperature": 0.7,
}
)
agent = Agent(
model=model
)
# Ask the agent a question
agent("Tell me about agentic AI")
- Run the script using
python -u agents.py
Expected Behavior
If the model_id in the script above is a specific model, such as "blitz", the script runs as expected. Setting the model_id to "auto", which has the exact same response as an individual model, should work exactly as all other models do and this script should return an answer to the question.
Actual Behavior
Debugging Logs:
DEBUG | strands.models.openai | config=<{'model_id': 'auto', 'params': {'max_tokens': 1000, 'temperature': 0.7}}> | initializing
DEBUG | strands.tools.registry | tools_dir=</Users/XXX/Desktop/aws-strands/tools> | tools directory not found
DEBUG | strands.tools.registry | tool_modules=<[]> | discovered
DEBUG | strands.tools.registry | tool_count=<0>, success_count=<0> | finished loading tools
DEBUG | strands.tools.registry | tools_dir=</Users/XXX/Desktop/aws-strands/tools> | tools directory not found
DEBUG | strands.tools.watcher | tool directory watching initialized
DEBUG | strands.tools.registry | getting tool configurations
DEBUG | strands.tools.registry | tool_count=<0> | tools configured
DEBUG | strands.tools.registry | getting tool configurations
DEBUG | strands.tools.registry | tool_count=<0> | tools configured
DEBUG | strands.event_loop.streaming | model=<<strands.models.openai.OpenAIModel object at 0x1024e2050>> | streaming messages
DEBUG | strands.types.models.model | formatting request
DEBUG | strands.types.models.model | invoking model
DEBUG | strands.types.models.model | got response from model
DEBUG | strands.agent.conversation_manager.sliding_window_conversation_manager | window_size=<0>, message_count=<40> | skipping context reduction
Full Error Trace:
Traceback (most recent call last):
File "/Users/XXX/Desktop/aws-strands/agents.py", line 38, in <module>
agent("Tell me about agentic AI")
File "/Users/XXX/Desktop/aws-strands/.venv/lib/python3.11/site-packages/strands/agent/agent.py", line 335, in __call__
result = self._run_loop(prompt, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/XXX/Desktop/aws-strands/.venv/lib/python3.11/site-packages/strands/agent/agent.py", line 439, in _run_loop
return self._execute_event_loop_cycle(invocation_callback_handler, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/XXX/Desktop/aws-strands/.venv/lib/python3.11/site-packages/strands/agent/agent.py", line 467, in _execute_event_loop_cycle
stop_reason, message, metrics, state = event_loop_cycle(
^^^^^^^^^^^^^^^^^
File "/Users/XXX/Desktop/aws-strands/.venv/lib/python3.11/site-packages/strands/event_loop/event_loop.py", line 190, in event_loop_cycle
raise e
File "/Users/XXX/Desktop/aws-strands/.venv/lib/python3.11/site-packages/strands/event_loop/event_loop.py", line 148, in event_loop_cycle
stop_reason, message, usage, metrics, kwargs["request_state"] = stream_messages(
^^^^^^^^^^^^^^^^
File "/Users/XXX/Desktop/aws-strands/.venv/lib/python3.11/site-packages/strands/event_loop/streaming.py", line 340, in stream_messages
return process_stream(chunks, callback_handler, messages, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/XXX/Desktop/aws-strands/.venv/lib/python3.11/site-packages/strands/event_loop/streaming.py", line 290, in process_stream
for chunk in chunks:
File "/Users/XXX/Desktop/aws-strands/.venv/lib/python3.11/site-packages/strands/types/models/model.py", line 115, in converse
for event in response:
File "/Users/XXX/Desktop/aws-strands/.venv/lib/python3.11/site-packages/strands/models/openai.py", line 89, in stream
response = self.client.chat.completions.create(**request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/XXX/Desktop/aws-strands/.venv/lib/python3.11/site-packages/openai/_utils/_utils.py", line 287, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/XXX/Desktop/aws-strands/.venv/lib/python3.11/site-packages/openai/resources/chat/completions/completions.py", line 925, in create
return self._post(
^^^^^^^^^^^
File "/Users/XXX/Desktop/aws-strands/.venv/lib/python3.11/site-packages/openai/_base_client.py", line 1239, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/XXX/Desktop/aws-strands/.venv/lib/python3.11/site-packages/openai/_base_client.py", line 1034, in request
raise self._make_status_error_from_response(err.response) from None
openai.InternalServerError: router returned invalid model undefined
Issue
The trace logs show that the model is undefined, but the debug logs show that a response was received from the model.
Note: I noticed that any time the word "auto" is in the model_id, this behavior occurs. For example, "auto", "auto-reasoning", and "auto-tools" all give this same behavior.
Additional Context
If you invoke these models directly using the chat completions API, you'll notice that the responses are the exact same. For example, take the following code snippet:
from openai import OpenAI
base_url="https://conductor.arcee.ai/v1"
api_key="" # Your key here
model_id = "auto"
client = OpenAI(
base_url=base_url,
api_key=api_key
)
completion = client.chat.completions.create(
model=model_id,
messages=[{'role': 'user', 'content': 'Say hi'}],
max_tokens=2,
)
print(completion)
If model_id is set to "blitz" the output is:
ChatCompletion(id='nwAUeSR-z1gNr-94816eb40a19cf56', choices=[Choice(finish_reason='length', index=0, logprobs=None, message=ChatCompletionMessage(content='Hi!', refusal=None, role='assistant', annotations=None, audio=None, function_call=None, tool_calls=[]), seed=None)], created=1748641672, model='arcee-ai/arcee-blitz', object='chat.completion', service_tier=None, system_fingerprint=None, usage=CompletionUsage(completion_tokens=2, prompt_tokens=171, total_tokens=173, completion_tokens_details=None, prompt_tokens_details=None), prompt=[])
If the model_id is set to "auto" the output is:
ChatCompletion(id='nwAVSVp-z1gNr-9481727c4f9c1528', choices=[Choice(finish_reason='length', index=0, logprobs=None, message=ChatCompletionMessage(content='Hello!', refusal=None, role='assistant', annotations=None, audio=None, function_call=None, tool_calls=[]), seed=None)], created=1748641827, model='arcee-ai/arcee-blitz', object='chat.completion', service_tier=None, system_fingerprint=None, usage=CompletionUsage(completion_tokens=2, prompt_tokens=171, total_tokens=173, completion_tokens_details=None, prompt_tokens_details=None), prompt=[])
Notice there is no difference in the format of the response, so I'd expect both of these to work similarly in Strands.
Possible Solution
No response
Related Issues
No response
Thanks for reporting this @andrew-arcee, the team is taking a look in to it.
hi @andrew-arcee, thanks again for reporting this! here are the findings:
i've reproduced the error and i have found that the format of the messages attribute within strands is
messages=[{"role": "user", "content": [{"text": "say hi", "type": "text"}]}]
which differs from the working snippet you provided. i then retested your working snippet with the messages format above:
from openai import OpenAI
base_url = "https://conductor.arcee.ai/v1"
api_key = "" # replace with Arcee AI API key
model_id = "auto"
client = OpenAI(base_url=base_url, api_key=api_key)
completion = client.chat.completions.create(
model=model_id,
messages=[{"role": "user", "content": [{"text": "say hi", "type": "text"}]}],
max_tokens=2,
)
print(completion)
and i receive the same error that you initially experienced:
Traceback (most recent call last):
File "/local/home/jerebill/github/sdk-python/openai_sync.py", line 9, in <module>
completion = client.chat.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/local/home/jerebill/.local/share/hatch/env/virtual/strands-agents/_dXqv6H0/dev/lib/python3.12/site-packages/openai/_utils/_utils.py", line 287, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/local/home/jerebill/.local/share/hatch/env/virtual/strands-agents/_dXqv6H0/dev/lib/python3.12/site-packages/openai/resources/chat/completions/completions.py", line 925, in create
return self._post(
^^^^^^^^^^^
File "/local/home/jerebill/.local/share/hatch/env/virtual/strands-agents/_dXqv6H0/dev/lib/python3.12/site-packages/openai/_base_client.py", line 1242, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/local/home/jerebill/.local/share/hatch/env/virtual/strands-agents/_dXqv6H0/dev/lib/python3.12/site-packages/openai/_base_client.py", line 1037, in request
raise self._make_status_error_from_response(err.response) from None
openai.InternalServerError: router returned invalid model undefined
as a comparison, i also tested the same messages format against OpenAI's API using both strands and the simplified snippet and responses are generated correctly.
from strands import Agent
from strands.models.openai import OpenAIModel
import logging
api_key = "" # replace with OpenAI API key
model_id = "gpt-4.1"
# Enables Strands debug log level
logging.getLogger("strands").setLevel(logging.DEBUG)
# Sets the logging format and streams logs to stderr
logging.basicConfig( #
format="%(levelname)s | %(name)s | %(message)s", handlers=[logging.StreamHandler()]
)
# Define the model
model = OpenAIModel(
client_args={
"api_key": api_key,
},
model_id=model_id,
params={
"max_tokens": 1000,
"temperature": 0.7,
},
)
agent = Agent(model=model)
# Ask the agent a question
agent("Tell me about agentic AI")
truncated response:
....
DEBUG | strands.types.models.model | {'chunk_type': 'metadata', 'data': CompletionUsage(completion_tokens=522, prompt_tokens=29, total_tokens=551, completion_tokens_details=CompletionTokensDetails(accepted_prediction_tokens=0, audio_tokens=0, reasoning_tokens=0, rejected_prediction_tokens=0), prompt_tokens_details=PromptTokensDetails(audio_tokens=0, cached_tokens=0))}
DEBUG | strands.types.models.model | finished streaming response from model
DEBUG | strands.agent.conversation_manager.sliding_window_conversation_manager | window_size=<2>, message_count=<40> | skipping context reduction
**In summary:** Agentic AI systems are autonomous, goal-driven, and capable of acting independently in pursuit of objectives, distinguishing them from more passive, tool-like AI systems.DEBUG | strands.agent.agent | thread pool executor shutdown complete
i've also confirmed the messages format with OpenAI API docs and spec:
- https://platform.openai.com/docs/api-reference/chat/create
- https://github.com/openai/openai-openapi/blob/master/openapi.yaml#L18125
based on these findings, i believe that Arcee AI's API does not fully supporting the OpenAI API specification which leads to this error, despite the error message mentioning an undefined model.
Hi @jer96, thank you for the detailed response. I've replicated your findings and agree with your conclusion. Thank you for calling out the messages format that is utilized by strands.
no problem! i will go ahead and resolve this. please feel free reach out again!