Skip to content

feat(providers): openai on bedrock (#1009 cell) - #1026

Merged
chaholl merged 2 commits into
mainfrom
feat/openai-bedrock-1009
Apr 20, 2026
Merged

chaholl merged 2 commits into
mainfrom
feat/openai-bedrock-1009

Conversation

@chaholl

@chaholl chaholl commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds AWS Bedrock OpenAI-partner support (gpt-oss family) to the
openai provider. 8th cell delivered against #1009 — only
claude×azure remains.

Wire format verified against live Bedrock us-west-2:

  • URL: {baseURL}/model/{model-id}/invoke (standard Bedrock invoke)
  • Auth: AWS SigV4 via credentials.AWSCredential
  • Request: OpenAI Chat Completions JSON (Bedrock ignores model in body — routes by URL)
  • Response: standard OpenAI Chat Completions JSON — existing parser works as-is

Code structure

  • bedrockPlatform constant + isBedrock() predicate in openai.go
  • chatCompletionsURL() and responsesURL() branch for Bedrock — Bedrock has no Responses API so it falls back to Chat Completions (mirrors the existing Azure fallback)
  • NewProviderFromConfig:
    • Derives baseURL from PlatformConfig.Region via credentials.BedrockEndpoint when BaseURL == ""
    • Forces APIModeCompletions
    • Auto-adds max_tokens and top_p to UnsupportedParams for Bedrock:
      • max_tokens — gpt-oss requires max_completion_tokens instead (the request builder already flips for o-series)
      • top_p — gpt-oss rejects 0.0 (must be in (0, 1]); the framework default is 0, so omitting it leaves the model default in place
    • Operators can still override via explicit UnsupportedParams
  • registry.go: https://api.openai.com/v1 default skipped for Platform=="bedrock" (same [BUG] OpenAI provider on Azure platform routes to api.openai.com — registry default clobbers Azure URL construction #1010 root cause as Platform=="azure")

Streaming (known limitation)

Bedrock's invoke-with-response-stream returns binary event-stream framing with OpenAI-format chunks inside — distinct from the SSE the rest of the openai stream code consumes. Until a dedicated scanner lands, PredictStream / PredictStreamWithTools run a non-streaming Predict and emit a single terminal StreamChunk with content + FinishReason + CostInfo. This is honest (Bedrock's plain invoke is non-streaming) and keeps Arena scenarios with streaming: true compatible.

Tests

  • bedrock_unit_test.go — predicates, URL builders, factory URL derivation, API-mode forcing, unsupported-params auto-detection, explicit-override precedence
  • bedrock_integration_test.go (//go:build integration) — URL construction, predict, predict-with-tools, streaming fallback, error propagation, cost calculation against real Bedrock gpt-oss

6/6 integration tests pass against omnia-aws profile in us-west-2 (openai.gpt-oss-20b-1:0):

=== TestBedrockOpenAI_BaseURLConstruction        --- PASS (0.00s)
=== TestBedrockOpenAI_Predict                    --- PASS (1.62s)  Response: <reasoning>...</reasoning>Hello.
=== TestBedrockOpenAI_PredictWithTools           --- PASS (0.83s)  Tool call: get_weather({"city":"Paris"})
=== TestBedrockOpenAI_PredictStream_Fallback     --- PASS (0.99s)  Terminal chunk with finish=stop
=== TestBedrockOpenAI_ErrorOnInvalidModel        --- PASS (0.70s)
=== TestBedrockOpenAI_CostCalculation            --- PASS (1.64s)  Cost: 73 in / 79 out / $0.000058

Pre-commit

  • lint: 0 issues
  • coverage on changed files: openai.go 88.5%, openai_tools.go 80.6%, registry.go 93.5% (all ≥80%)

Matrix status after this PR

bedrock vertex azure
claude ✅ ✅ ❌ open
openai ✅ (this PR) ⛔ rejected ✅
gemini ⛔ rejected ✅ ⛔ rejected

8 of 9 cells delivered. Only claude×azure remains — blocked on availability of an Azure AI Foundry serverless Anthropic deployment (different resource type from Cognitive Services accounts; surface needs probing).

Refs #1009

chaholl added 2 commits April 20, 2026 13:34
Adds the AWS Bedrock OpenAI-partner cell (gpt-oss family) to the
provider matrix. 7th cell delivered against #1009 following:
openai+azure (#1010), gemini+vertex (#1023), claude+vertex (#1024),
fail-fast rejections (#1025).

Wire format (verified against live Bedrock us-west-2):

- URL:      {baseURL}/model/{model-id}/invoke  (standard Bedrock invoke)
- Auth:     AWS SigV4 via credentials.AWSCredential
- Request:  OpenAI Chat Completions JSON. Bedrock ignores the model
            field in the body (it routes by URL) so no stripping is
            needed — the existing request builder works as-is.
- Response: standard OpenAI Chat Completions JSON — parsed by the
            existing openAIResponse unmarshal path.

Code structure:

- `bedrockPlatform` constant + `isBedrock()` predicate in openai.go.
- `chatCompletionsURL()` and `responsesURL()` branch for Bedrock:
  the invoke URL path; Responses API falls back to Chat Completions
  (mirrors the existing Azure fallback — neither partner exposes it).
- `NewProviderFromConfig` derives baseURL from PlatformConfig.Region
  via credentials.BedrockEndpoint when BaseURL is empty, forces
  APIModeCompletions, and auto-adds `max_tokens` and `top_p` to
  UnsupportedParams for the Bedrock default set:
    * max_tokens: gpt-oss requires `max_completion_tokens` instead
      (same switch the request builder already flips for o-series).
    * top_p:      gpt-oss rejects 0.0 and the framework default is 0;
      omitting leaves the model default in place.
  Operators can override the full unsupported set via
  ProviderSpec.UnsupportedParams.
- registry.go: api.openai.com/v1 default now skipped for
  Platform=="bedrock" as well as "azure", so the factory's
  PlatformConfig URL derivation is reachable (same root cause as
  #1010).

Streaming (known limitation):

Bedrock's `invoke-with-response-stream` returns binary event-stream
framing with OpenAI-format chunks inside — distinct from the SSE the
rest of the openai stream code expects. Until a dedicated scanner
lands, PredictStream / PredictStreamWithTools run a non-streaming
Predict and emit a single terminal StreamChunk with content +
FinishReason + CostInfo. This is honest (Bedrock's plain `invoke` is
non-streaming) and keeps Arena scenarios with `streaming: true`
compatible.

Tests:

- bedrock_unit_test.go covers predicates, URL builders, factory URL
  derivation, API-mode forcing, unsupported-params auto-detection,
  and that explicit UnsupportedParams overrides Bedrock auto-detect.
- bedrock_integration_test.go (//go:build integration) covers
  URL construction, predict, predict-with-tools, streaming fallback,
  error propagation, and cost calculation against a real Bedrock
  gpt-oss deployment. All 6 pass locally against us-west-2 on the
  omnia-aws profile.

Refs #1009
… coverage

The bedrock_integration_test.go suite covers the new code path
end-to-end against real AWS Bedrock, but build-tag `integration` is
not run in CI so SonarCloud sees the predictStreamBedrockFallback and
predictStreamWithToolsBedrockFallback bodies as uncovered (new_coverage
41.4% < 80% threshold).

Adds httptest-based unit tests that mock the Bedrock invoke endpoint
with canned OpenAI Chat Completions JSON and exercise:

- PredictStream Bedrock path: emits exactly one terminal chunk with
  Content/Delta/FinishReason=stop/CostInfo populated.
- PredictStream Bedrock error: 4xx upstream surfaces as error from
  the streaming entrypoint.
- PredictStreamWithTools Bedrock path: emits exactly one terminal
  chunk with ToolCalls populated and FinishReason=tool_calls.
- PredictStreamWithTools Bedrock error: 5xx upstream surfaces as
  error.

No production code changes.
@sonarqubecloud

Copy link
Copy Markdown

@chaholl
chaholl merged commit e9b0e71 into main Apr 20, 2026
23 checks passed
@chaholl
chaholl deleted the feat/openai-bedrock-1009 branch April 20, 2026 14:06
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.

1 participant