Skip to content

Python: Support OpenAI models (GPT-6 Sol/Luna/Astra, GPT-5.x, gpt-oss) in the Bedrock chat connector - #14471

Closed
Lucas Kim (kimnamu) wants to merge 1 commit into
microsoft:mainfrom
kimnamu:fix/bedrock-gpt-6-openai-provider
Closed

Lucas Kim (kimnamu) wants to merge 1 commit into
microsoft:mainfrom
kimnamu:fix/bedrock-gpt-6-openai-provider

Conversation

@kimnamu

@kimnamu Lucas Kim (kimnamu) commented Sep 23, 2026 •

Copy link
Copy Markdown

Motivation and Context

Thanks to the Python team for the Bedrock connector (#9100) and its per-provider modules; OpenAI support follows the chat region of bedrock_mistralai.py.

Fixes #14470

BedrockChatCompletion rejected every OpenAI model ID on Bedrock (GPT-6 Sol/Luna/Astra, GPT-5.6, gpt-oss) with ValueError: ... does not contain a valid model provider name.. With the provider forced, the default stopSequences: [] got a 400.

case (live, us-east-1) Before (main) After (this PR) After (this PR + #14469)
GPT-6 Sol us./global.: plain, streaming, system prompt, tools (Auto, Required, streaming) ❌ ValueError ✅ ✅
GPT-6 Sol: image, 2-turn, max_tokens=20 ❌ ValueError ❌ reasoningContent block (#14468) ✅ (max_tokens=20 gives LENGTH, empty text)
GPT-6 Luna us./global.: "Say pong." non-streaming / streaming ❌ ValueError ❌ 10/30 / 8/30 OK (3 rounds), the rest hit a reasoningContent block ✅ 20/20 / 20/20 (2 rounds)
GPT-6 Luna: system prompt, tools (Auto, Required, streaming) ❌ ValueError ✅ ✅
GPT-6 Astra us./global.: plain, streaming, system prompt, tools (Auto, Required, streaming) ❌ ValueError ✅ ("Say pong." 30/30 / 30/30, 3 rounds) ✅ (20/20 / 20/20, 2 rounds)
GPT-6 Astra: image, 2-turn, max_tokens=20 ❌ ValueError ❌ reasoningContent block (#14468) ✅ (max_tokens=20 gives LENGTH, empty text)
GPT-5.6 Sol: plain, streaming, system prompt, tools, image / 2-turn, max_tokens=20 ❌ ValueError ✅ / ❌ can hit a reasoningContent block ✅
gpt-oss-120b: all of the above ❌ ValueError ❌ reasoningContent block on every text check ✅ (except image: the model has no image input)
BEDROCK_MODEL_PROVIDER=openai (Sol, Astra) ❌ ValidationError ✅ 'pong' ✅
Default inferenceConfig sent {"stopSequences": []} {} {}
stop=["world"] set by the user sent ✅ unchanged, sent ✅
temperature set by the user on GPT-6 sent (service returns 400 on Converse) ✅ unchanged ✅
Claude Haiku 4.5 (plain, streaming, tools), Nova Lite (plain, streaming) ✅ ✅ unchanged ✅
Public API (only the new OPENAI member), additionalModelRequestFields for other providers ✅ ✅ unchanged ✅

Description

  • bedrock_model_provider.py: add OPENAI = "openai" and one CHAT_COMPLETION_ADDITIONAL_MODEL_REQUEST_FIELDS_MAPPING entry.
  • bedrock_openai.py (new): the chat region of bedrock_mistralai.py, returning None, with the Bedrock OpenAI parameters link.
  • bedrock_chat_completion.py: "stopSequences": settings.stop or None, so remove_none_recursively drops the empty default like the other unset fields.
  • Tests: openai.gpt in the four provider parametrize lists, two GPT-6 profile IDs in test_inference_profile_with_bedrock_model, and a new test_prepare_settings_for_request_with_stop. The old assert all([parsed_settings["inferenceConfig"].values()]) is always true (a one-item list), so the two prepare_settings tests now assert == {}.

Out of scope: text completion and embeddings for OpenAI stay unsupported, and a reasoning-effort setting would be a separate feature. GPT-6 Luna, gpt-oss and some Sol/Astra prompts need #14469 as well; the two PRs touch different lines and pass the Bedrock unit tests together (120).

Tests (red/green, lint) and live output

New tests kept, source reverted to main:

E       AssertionError: assert {'stopSequences': []} == {}          (x7)
E           ValueError: Model ID openai.gpt does not contain a valid model provider name.          (x4)
E           ValueError: Model ID us.openai.gpt-6-sol does not contain a valid model provider name.
FAILED tests/unit/connectors/ai/bedrock/services/test_bedrock_chat_completion.py::test_prepare_settings_for_request[anthropic.claude]   (and the 5 other providers)
FAILED tests/unit/connectors/ai/bedrock/services/test_bedrock_chat_completion.py::test_prepare_settings_for_request[openai.gpt]
FAILED tests/unit/connectors/ai/bedrock/services/test_bedrock_chat_completion.py::test_prepare_settings_for_request_with_application_inference_profile[...]
FAILED tests/unit/connectors/ai/bedrock/services/test_bedrock_chat_completion.py::test_bedrock_chat_completion[openai.gpt]
FAILED tests/unit/connectors/ai/bedrock/services/test_bedrock_chat_completion.py::test_bedrock_streaming_chat_completion[openai.gpt]
FAILED tests/unit/connectors/ai/bedrock/services/test_bedrock_chat_completion.py::test_bedrock_streaming_chat_completion_invalid_event[openai.gpt]
FAILED tests/unit/connectors/ai/bedrock/services/test_bedrock_model_provider_utils.py::test_inference_profile_with_bedrock_model
12 failed, 106 passed in 0.17s

With the fix:

$ uv run pytest tests/unit/connectors/ai/bedrock
118 passed in 0.13s
$ uv run ruff check <changed files>          -> All checks passed!
$ uv run ruff format --check <changed files> -> 5 files already formatted
$ uv run mypy --config-file mypy.ini semantic_kernel/connectors/ai/bedrock -> Success: no issues found in 18 source files
pyupgrade --py310-plus, bandit -c pyproject.toml -> no changes, no findings

"Say pong.", 5 non-streaming + 5 streaming calls per model per round:

this PR          us.openai.gpt-6-sol       non-streaming 5/5  streaming 5/5
this PR          global.openai.gpt-6-sol   non-streaming 5/5  streaming 5/5
this PR          us.openai.gpt-6-luna      rounds 1/2/3: non-streaming 0/5, 3/5, 2/5  streaming 0/5, 3/5, 1/5  ['ServiceInvalidResponseError'] / ['KeyError']
this PR          global.openai.gpt-6-luna  rounds 1/2/3: non-streaming 0/5, 2/5, 3/5  streaming 2/5, 1/5, 1/5  ['ServiceInvalidResponseError'] / ['KeyError']
this PR + #14469 all four IDs              rounds 1/2: non-streaming 5/5, 5/5  streaming 5/5, 5/5
this PR          us.openai.gpt-6-astra     rounds 1/2/3: non-streaming 5/5, 5/5, 5/5  streaming 5/5, 5/5, 5/5
this PR          global.openai.gpt-6-astra rounds 1/2/3: non-streaming 5/5, 5/5, 5/5  streaming 5/5, 5/5, 5/5
this PR + #14469 both Astra IDs            rounds 1/2: non-streaming 5/5, 5/5  streaming 5/5, 5/5

Wider check through BedrockChatCompletion, this PR + #14469 (us.openai.gpt-6-luna shown; Sol, Astra, the global. IDs and us.openai.gpt-5.6-sol give the same OK/FAIL per check):

- plain: OK text='pong' finish=FinishReason.STOP | request(minus messages)={"modelId": "us.openai.gpt-6-luna", "system": [], "inferenceConfig": {}, "additionalModelRequestFields": null}
- system: OK text='HELLO' system_sent=[{'text': 'Reply in UPPERCASE only.'}]
- stream: OK text_chunks=39 ttft=0.77 total=0.96
- tools_auto: OK text='It’s sunny and 21°C in Paris.' history_roles=['user', 'assistant', 'tool']
- tools_required: OK items=['FunctionCallContent'] toolChoice={'tool': {'name': 'w-get_weather'}}
- tools_stream: OK text='It’s sunny and 21°C in Oslo.'
- image: OK text='Red'
- two_turn: OK t1='391' t2='392'
- max_tokens=20: OK text='' finish=FinishReason.LENGTH
- temperature=0.2(user-set): FAIL ValidationException: ... This model doesn't support the temperature field. Remove temperature and try again.

Streaming speed matches raw boto3 converse_stream (this PR + #14469, "Write about 250 words explaining how a hash map works.", maxTokens=2000, 3 interleaved runs (Astra 5), medians):

model                  path  TTFT s  total s  output tokens
us.openai.gpt-6-sol    raw   0.99    3.37     307
us.openai.gpt-6-sol    SK    1.11    3.49     308
us.openai.gpt-6-luna   raw   1.13    2.78     413
us.openai.gpt-6-luna   SK    0.97    2.78     408
us.openai.gpt-6-astra  raw   2.48    9.29     328
us.openai.gpt-6-astra  SK    1.38    8.69     327

Contribution Checklist

…he Bedrock chat connector

BedrockModelProvider had no "openai" member, so any openai.* model ID
(us.openai.gpt-6-sol, global.openai.gpt-6-luna, openai.gpt-oss-120b-1:0)
failed with "does not contain a valid model provider name", and
BEDROCK_MODEL_PROVIDER=openai failed validation.

Once routed, every request was still rejected because the default empty
stop list was sent as inferenceConfig.stopSequences=[]; OpenAI models on
Bedrock reject the stopSequences field. Only send it when stop is set.

Co-Authored-By: Claude <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified that would block approval.

Review effort: Lite
Findings: None

What changed in this PR

Adds OpenAI model support to the Python Bedrock chat connector and prevents empty stop sequences from being sent.

Changes:

  • Adds OpenAI provider routing and chat request handling.
  • Omits default empty stopSequences.
  • Extends unit tests for OpenAI IDs and stop settings.
File Description
python/​tests/​unit/​connectors/​ai/​bedrock/​services/​test_bedrock_model_provider_utils.py Updated as part of this pull request.
python/​tests/​unit/​connectors/​ai/​bedrock/​services/​test_bedrock_chat_completion.py Updated as part of this pull request.
python/​semantic_kernel/​connectors/​ai/​bedrock/​services/​model_provider/​bedrock_openai.py Updated as part of this pull request.
python/​semantic_kernel/​connectors/​ai/​bedrock/​services/​model_provider/​bedrock_model_provider.py Updated as part of this pull request.
python/​semantic_kernel/​connectors/​ai/​bedrock/​services/​bedrock_chat_completion.py Updated as part of this pull request.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@kimnamu Lucas Kim (kimnamu) changed the title Python: Support OpenAI models (GPT-6 Sol/Luna, GPT-5.x, gpt-oss) in the Bedrock chat connector Python: Support OpenAI models (GPT-6 Sol/Luna/Astra, GPT-5.x, gpt-oss) in the Bedrock chat connector Sep 24, 2026
@eavanvalkenburg

Copy link
Copy Markdown
Member

Thank you for the contribution. We are not adding new features to Semantic Kernel (SK) at the moment, so I am closing this PR. Please consider creating a feature request issue in microsoft/agent-framework.

This branch had an error being deployed

1 failed deployment
github-app-auth — cf3ca071 Deployed Sep 23, 2026 by kimnamu via review #531
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Bug: Bedrock chat connector rejects OpenAI models (GPT-6 Sol/Luna/Astra, GPT-5.6, gpt-oss) with a model provider ValueError

3 participants