Repository navigation
feat(providers): openai on bedrock (#1009 cell) - #1026
Merged
Merged
Conversation
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.
|
8 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Adds AWS Bedrock OpenAI-partner support (gpt-oss family) to the
openai provider. 8th cell delivered against #1009 — only
claude×azureremains.Wire format verified against live Bedrock us-west-2:
{baseURL}/model/{model-id}/invoke(standard Bedrock invoke)credentials.AWSCredentialmodelin body — routes by URL)Code structure
bedrockPlatformconstant +isBedrock()predicate in openai.gochatCompletionsURL()andresponsesURL()branch for Bedrock — Bedrock has no Responses API so it falls back to Chat Completions (mirrors the existing Azure fallback)NewProviderFromConfig:PlatformConfig.Regionviacredentials.BedrockEndpointwhenBaseURL == ""APIModeCompletionsmax_tokensandtop_pto UnsupportedParams for Bedrock:max_tokens— gpt-oss requiresmax_completion_tokensinstead (the request builder already flips for o-series)top_p— gpt-oss rejects0.0(must be in(0, 1]); the framework default is0, so omitting it leaves the model default in placeUnsupportedParamsregistry.go:https://api.openai.com/v1default skipped forPlatform=="bedrock"(same [BUG] OpenAI provider on Azure platform routes to api.openai.com — registry default clobbers Azure URL construction #1010 root cause asPlatform=="azure")Streaming (known limitation)
Bedrock's
invoke-with-response-streamreturns 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/PredictStreamWithToolsrun a non-streamingPredictand emit a single terminalStreamChunkwith content +FinishReason+CostInfo. This is honest (Bedrock's plaininvokeis non-streaming) and keeps Arena scenarios withstreaming: truecompatible.Tests
bedrock_unit_test.go— predicates, URL builders, factory URL derivation, API-mode forcing, unsupported-params auto-detection, explicit-override precedencebedrock_integration_test.go(//go:build integration) — URL construction, predict, predict-with-tools, streaming fallback, error propagation, cost calculation against real Bedrock gpt-oss6/6 integration tests pass against
omnia-awsprofile in us-west-2 (openai.gpt-oss-20b-1:0):Pre-commit
Matrix status after this PR
8 of 9 cells delivered. Only
claude×azureremains — blocked on availability of an Azure AI Foundry serverless Anthropic deployment (different resource type from Cognitive Services accounts; surface needs probing).Refs #1009