Skip to content

Commit aec50b9

Browse files
committed
fix: address comments
1 parent 8880313 commit aec50b9

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

src/strands/models/bedrock.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,12 @@ class OpenAIEndpointConfig(TypedDict, total=False):
124124
OpenAI-compatible surface, such as the Responses API's server-side stateful conversations
125125
and reasoning controls.
126126
127-
Generic inference parameters (``temperature``, ``top_p``, ``max_tokens``,
128-
``stop_sequences``, ``streaming``) continue to live on :class:`BedrockModel.BedrockConfig`
129-
and are forwarded to the underlying OpenAI model.
127+
Generic inference parameters (``temperature``, ``top_p``, ``max_tokens``) live on
128+
:class:`BedrockModel.BedrockConfig` and are forwarded to the underlying OpenAI model.
129+
``stop_sequences`` is forwarded to Chat Completions as ``stop`` but is rejected at
130+
init time when ``api="responses"`` (the Responses API does not accept stop sequences).
131+
``streaming=False`` is not supported on this path and is also rejected at init time,
132+
since the OpenAI SDK's Responses and Chat Completions surfaces always stream.
130133
131134
Attributes:
132135
api: Which OpenAI API surface to use. ``"responses"`` maps to the Responses API and

tests/strands/models/test_bedrock.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3414,3 +3414,29 @@ def test_openai_endpoint_invalid_config_raises(session_cls, config_kwargs, error
34143414

34153415
with pytest.raises(ValueError, match=error_match):
34163416
BedrockModel(model_id="openai.gpt-oss-120b", region_name="us-east-1", **config_kwargs)
3417+
3418+
3419+
@pytest.mark.asyncio
3420+
async def test_openai_endpoint_count_tokens_falls_back_to_base(session_cls, openai_responses_model_cls, messages):
3421+
"""count_tokens bypasses the Converse client on the openai_endpoint path.
3422+
3423+
Bedrock's native CountTokens API lives on ``bedrock-runtime`` and has no Mantle
3424+
equivalent, so ``BedrockModel.count_tokens`` must route to the base ``Model.count_tokens``
3425+
estimator (tiktoken or heuristic). A regression that routed through ``self.client`` would
3426+
raise ``AttributeError`` since ``self.client is None`` on the Mantle path.
3427+
"""
3428+
_ = session_cls
3429+
3430+
model = BedrockModel(
3431+
model_id="openai.gpt-oss-120b",
3432+
region_name="us-east-1",
3433+
openai_endpoint={"api": "responses"},
3434+
)
3435+
3436+
# Delegate is a mock and does not implement count_tokens. Call should still succeed
3437+
# because the override dispatches to super() rather than the delegate or the boto client.
3438+
result = await model.count_tokens(messages=messages)
3439+
3440+
assert isinstance(result, int)
3441+
assert result > 0
3442+
openai_responses_model_cls.return_value.count_tokens.assert_not_called()

0 commit comments

Comments
 (0)