Skip to content

feat(py/bedrock)!: typed Stability image config and model refs - #6977

Merged
huangjeff5 merged 7 commits into
fix/py-plugin-embedder-reffrom
feat/py-bedrock-image-config
Nov 4, 2026
Merged

huangjeff5 merged 7 commits into
fix/py-plugin-embedder-reffrom
feat/py-bedrock-image-config

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #7049.

Bedrock image models took an untyped dict. BedrockImageConfig declared no fields and allowed any key, so a typo like aspectRatio for aspect_ratio was merged into the body unchecked, and an image-config typo was silently dropped (Jacob's comment on #6644). Stability now has a typed config class with flat snake_case fields, and Bedrock gets typed refs named after Bedrock's output modalities (Bedrock.text, Bedrock.stability for IMAGE, Bedrock.embedder) that bind each model to its config class. Unknown keys raise. extra (added in #6644) is the only way to send raw AWS body fields.

Titan Image and Nova Canvas were retired on Bedrock (Titan Image v2 on 2026-06-30, Nova Canvas on 2026-09-30) and aren't typed; anyone with residual access passes the raw model ID with config['extra'].

# --- BEFORE ---
# 1. Stability: the whole dict was merged into the body, unknown keys included
await ai.generate(
    model='bedrock/stability.sd3-5-large-v1:0',
    prompt='A food truck at dusk, string lights.',
    config={'aspectRatio': '16:9', 'seed': 42},
)
# => body: {'prompt': ..., 'output_format': 'png', 'aspectRatio': '16:9', 'seed': 42}
#    nothing checked it locally; the misspelled key went to Bedrock as-is

# --- AFTER ---
from genkit_amazon_bedrock import Bedrock, StabilityImageConfig

# 1. Typed ref + flat, typed fields with autocomplete and range checks
sd = Bedrock.stability('stability.sd3-5-large-v1:0')  # => ModelRef[StabilityImageConfig], name 'bedrock/stability.sd3-5-large-v1:0'
response = await ai.generate(
    model=sd,
    prompt='A food truck at dusk, string lights.',
    config=StabilityImageConfig(aspect_ratio='16:9', seed=42, negative_prompt='blurry', output_format='jpeg'),
)
# => body: {'prompt': 'A food truck at dusk, string lights.', 'output_format': 'jpeg',
#           'aspect_ratio': '16:9', 'seed': 42, 'negative_prompt': 'blurry'}
print(response.media[0].content_type)
# => image/jpeg

# 2. Embedder ref via Bedrock.embedder() — returns EmbedderRef, so it cannot be passed to generate()
titan = Bedrock.embedder('amazon.titan-embed-text-v2:0')  # => EmbedderRef, name 'bedrock/amazon.titan-embed-text-v2:0'
embeddings = await ai.embed(embedder=titan, content='Smoked salmon tartine')
print(len(embeddings[0].embedding))
# => 1024

# 3. A ref refuses an ID from another family, using the plugin's own routing
Bedrock.text('stability.sd3-5-large-v1:0')
# => INVALID_ARGUMENT: Bedrock.text: 'stability.sd3-5-large-v1:0' is a Stability model; use Bedrock.stability().
Bedrock.stability('stability.stable-image-inpaint-v1:0')
# => INVALID_ARGUMENT: Bedrock.stability: 'stability.stable-image-inpaint-v1:0' is an unsupported Stability image editing/upscale service; the plugin supports text-to-image only.
Bedrock.text('amazon.titan-embed-text-v2:0')
# => INVALID_ARGUMENT: Bedrock.text: 'amazon.titan-embed-text-v2:0' is an embedding model; use Bedrock.embedder().

# 4. A plain dict still works, with declared keys only (snake_case or camelCase)
config={'aspectRatio': '16:9', 'seed': 42}

# 5. Unknown keys raise before the call
config={'aspect_ratio': '16:9', 'style_preset': 'photographic'}
# => INVALID_ARGUMENT: unknown config key 'style_preset'; put provider-only settings in config['extra']

# 6. Raw AWS fields go in extra, deep-merged into the body (from #6644)
config=StabilityImageConfig(aspect_ratio='16:9', extra={'mode': 'text-to-image'})
# => body: {'prompt': ..., 'output_format': 'png', 'mode': 'text-to-image'}

# 7. Retired Titan Image / Nova Canvas: raw ID, body fields in extra
await ai.generate(
    model='bedrock/amazon.nova-canvas-v1:0',
    prompt='A dim sum spread on a marble table.',
    config={'extra': {'imageGenerationConfig': {'width': 512, 'height': 512}}},
)
# => body: {'taskType': 'TEXT_IMAGE', 'textToImageParams': {'text': 'A dim sum spread on a marble table.'},
#           'imageGenerationConfig': {'width': 512, 'height': 512}}

Ref constructors, classmethods on Bedrock; each takes a bare or bedrock/-prefixed ID and an optional default config:

  • Bedrock.text(name) -> ModelRef[BedrockConfig]: Bedrock's TEXT output modality, served over Converse, including models that take image or document input. Unknown IDs are accepted; autocomplete comes from the text catalog
  • Bedrock.stability(name) -> ModelRef[StabilityImageConfig]: SD 3.5, Stable Image Core, Stable Image Ultra
  • Bedrock.embedder(name) -> EmbedderRef: for ai.embed(), mirroring GoogleAI.embedder. No config parameter: Bedrock embedders ignore per-request options today, so it would be dropped silently

Config class, exported from genkit_amazon_bedrock:

  • StabilityImageConfig: aspect_ratio (the 9 AWS ratios), seed (0-4294967295; SD 3.5 caps at 4294967294), negative_prompt (max 10,000 chars), output_format (png | jpeg | webp; webp is SD 3.5 only), extra

Decisions

  • Typed surface is Stability only. Titan Image and Nova Canvas are retired on Bedrock and fail with ResourceNotFoundException, so typed classes and refs for them would be new public API for dead models. Their IDs still route to InvokeModel under a private extra-only config: the plugin builds taskType and textToImageParams.text, and everything else comes from config['extra']. Bedrock.text('amazon.nova-canvas-v1:0') says so and names the raw form.
  • One class per family, picked from the model ID. Each image action registers its family's class, so generate(config=...) and the Dev UI form validate against it, and a BedrockConfig sent to a Stability model fails Genkit's class check. The old reason for an open schema (families take different keys) no longer applies.
  • Refs reuse the runtime routing, so they can't disagree with it. Names follow AWS's output modalities (TEXT, IMAGE, EMBEDDING). The constructors check embedder, rerank, image family, then text, in resolve's order and with the same image_family() it uses. A ref's config_schema is therefore always the class its action registers, us. profiles and model ARNs route as they do at runtime, and an opaque application inference profile ARN (no model ID in it) is text-only, as it is at runtime. An embedding ID only ever becomes an EmbedderRef, so it can't reach generate(model=...). Same shape as OpenAI.gpt / Anthropic.claude, with Google's refuse-other-families rule.
  • extra is the only path to the AWS body. Stability no longer merges the whole config dict, and Titan/Nova no longer read a nested imageGenerationConfig. Undeclared settings go in extra, which keeps fix(py/bedrock, py/vertexai)!: unlisted Bedrock settings go in extra; Model Garden rejects a per-request key #6644's deep merge and prompt-field rejection unchanged.
  • Image configs extend GenkitConfig, like VeoConfig; generic knobs raise. GenkitConfig gives the same camelCase aliases and extra='forbid' as ModelConfig, without temperature, top_p, max_output_tokens, top_k, stop_sequences or version. Bedrock's image APIs take none of those knobs, so they now raise as unknown keys instead of being accepted and dropped, and the Dev UI form shows only real image fields. BedrockConfig stays on ModelConfig, since text models use them. A Stability call with no config sends the same body as before.

Breaking

  • BedrockImageConfig is removed (it was never exported from the package root). Use StabilityImageConfig.
  • Unknown top-level keys on Stability raise INVALID_ARGUMENT instead of being sent. Move them to extra.
  • Titan Image / Nova Canvas: config={'imageGenerationConfig': {...}} raises INVALID_ARGUMENT; send it as config={'extra': {'imageGenerationConfig': {...}}}. The plugin no longer fills in imageGenerationConfig defaults for these IDs ({'numberOfImages': 1, 'height': 1024, 'width': 1024, 'cfgScale': 8.0, 'seed': 0}, plus 'quality': 'standard' on Nova Canvas), so Bedrock applies its own.
  • Genkit's generic knobs (temperature, top_p, max_output_tokens, top_k, stop_sequences) on an image model raise INVALID_ARGUMENT instead of being ignored. Drop them from image calls.
  • Stability output_format takes lowercase png | jpeg | webp only; other spellings go through extra.
  • A non-mapping config['extra'] on an image model now fails Genkit's config check and raises, instead of coming back on response.error.

@github-actions github-actions Bot added docs Improvements or additions to documentation python Python labels Oct 30, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request refactors the Amazon Bedrock plugin's image generation configuration by replacing the generic, open BedrockImageConfig with strict, typed config classes for each model family: TitanImageConfig, NovaCanvasConfig, and StabilityImageConfig. This change enables local validation of parameters (such as image dimensions and quality) and allows the Dev UI to render these fields as a form. The documentation, implementation, and tests have been updated to support these new schemas. Feedback on the changes suggests dynamically extracting model fields from the passed config instance in build_amazon_image_body rather than relying on a static set based on NovaCanvasConfig, which improves maintainability if the configurations diverge in the future.

@huangjeff5
huangjeff5 requested a review from hilariie October 30, 2026 21:34
@huangjeff5
huangjeff5 force-pushed the feat/py-bedrock-image-config branch from 3888a6d to 2175943 Compare November 3, 2026 02:50
@huangjeff5
huangjeff5 requested a review from hilariie November 3, 2026 02:51
@huangjeff5 huangjeff5 changed the title feat(py/bedrock)!: typed image configs for Nova Canvas, Titan Image and Stability feat(py/bedrock)!: typed Stability image config and model refs Nov 3, 2026
@huangjeff5
huangjeff5 force-pushed the feat/py-bedrock-image-config branch from d02f19f to a7b312a Compare November 3, 2026 04:34

@cabljac cabljac 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.

LGTM with comments

@huangjeff5
huangjeff5 changed the base branch from main to fix/py-plugin-embedder-ref November 3, 2026 17:18
@huangjeff5
huangjeff5 added this pull request to stack #7050 November 3, 2026 17:38
Also update README to three families, fix number_of_images, and fix stable-image-inpaint hint.
Bedrock retired Titan Image v2 on 2026-06-30 and Nova Canvas on 2026-09-30;
both now fail with ResourceNotFoundException. Drop NovaCanvasConfig,
TitanImageConfig, Bedrock.nova_canvas(), Bedrock.titan_image() and their
Known* literals.

The raw IDs still route to InvokeModel under an extra-only config, so anyone
with residual access sends the body through config['extra']; the plugin
builds only taskType and textToImageParams.text. The ref constructors point
those IDs at the raw form.
…ed max

Route non-text-to-image stability.* IDs (after stripping inference-profile
prefixes and ARNs) to a dedicated stability_service ref route so text(),
stability(), and embedding() all refuse editing and upscale IDs with a
text-to-image-only message instead of steering to Bedrock.text().

Widen StabilityImageConfig.seed upper bound from 4294967294 to 4294967295
for Stable Image Core and Ultra, documenting SD 3.5's 4294967294 cap.
@huangjeff5
huangjeff5 force-pushed the feat/py-bedrock-image-config branch from 8ee570b to ab2e974 Compare November 4, 2026 20:13
@huangjeff5
huangjeff5 enabled stacked auto-merge (squash) November 4, 2026 20:13
@huangjeff5
huangjeff5 merged commit a9c7250 into main Nov 4, 2026
24 checks passed
@huangjeff5
huangjeff5 deleted the feat/py-bedrock-image-config branch November 4, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation python Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants