Introducing a new way to review your PRs.

Read the announcement

floci-io / floci

Light, fluffy, and always free - The AWS Local Emulator alternative

View on GitHub

38 documents · Updated Nov 23, 2026

docs / svc-bedrock-runtime

Bedrock platform and runtime

Bedrock provides two related AWS-shaped surfaces. Its control plane manages regional guardrails, model catalogs, inference profiles, resource policies, and tags, while its runtime surface accepts model requests and returns local or proxy-backed inference results. Together they let clients manage AI resources and use model APIs without changing their Bedrock-facing request flow.

Control-plane boundary

The Bedrock control plane manages guardrails, model and inference-profile metadata, resource policies, and tags. The separate Bedrock Runtime surface handles /model/{modelId}/... inference routes, so resource setup and model execution remain related but distinct parts of the platform.

The control plane resolves the request region before it reads or changes a resource. Its responses and errors follow Bedrock-shaped contracts so infrastructure tools can manage AI resources through the same interface they use for Bedrock.

flowchart LR
    Client[Bedrock client] --> Control[Bedrock control plane]
    Control --> Guardrails[Guardrail resources]
    Control --> Catalog[Model catalog and profiles]
    Control --> Policies[Resource policies and tags]
    Client --> Runtime[Bedrock Runtime]
    Runtime --> Models[Configured model backend]

References: src/…/BedrockController.java• L35-57 src/…/BedrockController.java• L59-307 src/…/BedrockService.java• L41-49

Guardrail resources

Guardrails are named, regional resources that hold safety policy data and the messages shown when input or output is blocked. A resource also carries its ARN, timestamps, tags, and an optional resolved KMS key ARN. The policy data remains flexible JSON so the control plane can carry several policy families without changing the resource shape.

The control plane supports these resource actions:

ActionPurpose
Create and getCreate a draft guardrail and read a draft or numbered version
UpdateChange the draft policy, messages, description, or KMS key reference
ListList drafts across a region or all versions of one guardrail
DeleteDelete one numbered version or the full resource when no version is given
Tag operationsAdd, remove, or read tags on a guardrail resource
Resource policy operationsAttach, read, or remove a supported policy from a guardrail

Create and update requests accept policy configuration names. Read responses expose the corresponding policy data in its resource form. A KMS key reference is checked through the KMS service and is returned as a full key ARN when it is usable.

References: src/…/BedrockController.java• L59-144 src/…/BedrockService.java• L171-239 src/…/Guardrail.java• L10-31

Guardrail versioning

Guardrail changes use a draft-and-version model. New and updated content lives in the DRAFT version. Creating a guardrail version copies that draft into the next numerical version, which gives clients a stable snapshot to reference.

The lifecycle is:

  1. Create a guardrail in the DRAFT version.
  2. Update the draft as policy content changes.
  3. Create a numbered version to snapshot the current draft.
  4. Read or delete a numbered version, or delete the complete guardrail resource.

Guardrails report READY immediately after creation. This gives resource clients a completed status on their first read instead of requiring an asynchronous wait. Listing without an identifier returns drafts in the region. Listing with an identifier returns all versions of that guardrail.

References: src/…/BedrockService.java• L53-54 src/…/BedrockService.java• L247-288 src/…/BedrockService.java• L584-599

Foundation models

The foundation model catalog describes which built-in models are available in a region and what each model can accept or return. Clients can list models with provider, output modality, inference type, and customization filters, or get one model by ID or ARN.

The catalog reports model identity, provider, input and output modalities, streaming support, lifecycle status, and the inference types available in the selected region. A known model that is not served in the request region is reported as invalid for that region rather than as a usable model.

References: src/…/BedrockController.java• L146-173 src/…/BedrockService.java• L291-323

Inference profiles

Inference profiles give clients a stable Bedrock resource that represents one or more model destinations. The service exposes both system-defined profiles from the model catalog and application profiles created by a client.

Application profiles are regional resources with a name, optional description, tags, timestamps, and a list of model ARNs. A profile can be created from a foundation model or a system-defined inference profile in the same region. Clients can create, list, get, and delete these profiles. A valid client request token makes a repeated create request return the existing profile instead of creating a second resource.

Profile identifiers are region and account aware. A profile ARN from another account is denied, while an ARN from another region does not resolve to the local profile. Application profiles also appear in resource discovery and use the same tag resource actions as guardrails.

References: src/…/BedrockController.java• L176-228 src/…/BedrockService.java• L325-480 src/…/ApplicationInferenceProfile.java• L10-22

Resource policies

Resource policies control access to Bedrock guardrails and guardrail profiles. A guardrail policy is stored with the guardrail draft. A guardrail-profile policy is stored for the calling region because the same system-defined profile ARN can have a different policy at each regional endpoint.

The policy language is intentionally narrow. Statements must allow supported Bedrock actions on the exact resource, and the principal must be the account root or * with the required organization condition. This gives callers a useful Bedrock policy contract without treating arbitrary policy documents as valid.

Resource policy operations require an ARN. Guardrail profiles support only bedrock:ApplyGuardrail, while guardrails support bedrock:ApplyGuardrail and bedrock:GetGuardrail. A guardrail profile with no policy returns an empty policy document.

References: src/…/BedrockController.java• L230-264 src/…/BedrockService.java• L601-647 src/…/BedrockService.java• L885-997

Resource tags

Tags provide key-value labels for guardrails and application inference profiles. Create and tag operations merge tags onto the resource, while untag operations remove selected keys. Tag reads return the current set for the resource.

Bedrock tag actions validate the AWS TagList shape before the service stores tags. The same key and value rules are shared with AgentCore tag fields, although AgentCore receives tags as an object and Bedrock receives tag entries as an array. A request can carry at most 200 tag entries, and a resource can hold at most 50 tags after merging replacements.

Bedrock exposes tag actions through its own resource API. The Resource Groups Tagging API also delegates list, tag, and untag operations to the same guardrail tag state, while resource discovery exposes guardrails and application inference profiles as supported Bedrock resource types.

References: src/…/BedrockController.java• L266-307 src/…/BedrockController.java• L417-426 src/…/BedrockService.java• L649-735 src/…/BedrockTagValidator.java• L13-45 src/…/BedrockAgentCoreTagValidation.java• L13-38

Request surface

The REST surface in src/…/BedrockRuntimeController.java maps Bedrock model paths to three supported request types. The controller checks the model ID and the JSON message list before it passes a request to the selected backend. InvokeModel bodies remain opaque because their shape depends on the model provider.

RequestPurposeRuntime result
POST /model/{modelId}/converseSend a structured conversationA normal Bedrock Converse response
POST /model/{modelId}/invokeSend a provider-specific model bodyA provider-shaped JSON body from the stub, or a clear rejection in proxy mode
POST /model/{modelId}/converse-streamReceive a conversation as it is generatedA Bedrock event stream
POST /model/{modelId}/invoke-with-response-streamStream an InvokeModel responseNot supported; the service returns an AWS-shaped 501 error

Converse requests need a non-empty messages array. Invalid JSON, a missing model ID, or an empty message list fails at the request boundary instead of reaching a backend.

References: src/…/BedrockRuntimeController.java• L23-35 src/…/BedrockRuntimeController.java• L49-113

Backend selection

BedrockRuntimeService is the small routing layer between the HTTP surface and a concrete BedrockBackend. The floci.services.bedrock-runtime.backend setting selects stub or proxy for each operation, while an unknown value safely falls back to the stub.

The same backend contract covers normal Converse responses, InvokeModel responses, and Converse streams. This keeps the request surface stable while the source of the model result changes. The controller uses a blocking boundary because proxy calls perform synchronous network work.

The request path is therefore:

flowchart LR
    Client[Bedrock client] --> Controller[Runtime request surface]
    Controller --> Service[Backend selection]
    Service --> Stub[Local stub]
    Service --> Proxy[OpenAI-compatible proxy]
    Proxy --> Provider[Configured model service]

References: src/…/BedrockRuntimeService.java• L15-57 src/…/BedrockBackend.java• L9-20 src/…/BedrockRuntimeController.java• L49-99

Stub responses

StubBackend emulates the Bedrock contract without network access or model inference. It returns a fixed assistant result for Converse and a small provider-shaped body for InvokeModel, so client flows can run when no AI service is available.

The stub also supports Converse streaming. It emits the same broad event sequence as a completed Bedrock stream, with fixed text fragments followed by a stop event and usage metadata. The incoming conversation does not change the generated text.

OperationEmulated behavior
ConverseOne assistant text block, end_turn, fixed usage, and a small latency value
InvokeModelAn Anthropic-like body for Anthropic model IDs; a generic outputs[].text body for other model families
Converse streamAssistant start, text deltas, content stop, message stop, and metadata

References: src/…/StubBackend.java• L13-18 src/…/StubBackend.java• L27-79 src/…/StubBackend.java• L82-109

Proxy requests

ProxyBackend connects Bedrock Converse calls to an OpenAI-compatible /chat/completions endpoint. It sends the translated request to the configured service and converts the provider result back to the Bedrock Converse shape. This supports local and hosted model services that expose the OpenAI chat contract.

The proxy resolves the upstream model in a fixed order:

  1. An exact Bedrock model ID mapping.
  2. The incoming Bedrock model ID when passthrough is enabled.
  3. The configured default model.

If none of these choices exists, the request fails validation. The proxy requires a base URL and can add a configured bearer token. Its request timeout and upstream failures become AWS-shaped model errors instead of local stub data.

Proxy InvokeModel is intentionally not emulated. It fails fast because provider-specific InvokeModel bodies cannot be translated safely to the OpenAI chat contract.

References: src/…/ProxyBackend.java• L25-29 src/…/ProxyBackend.java• L54-83 src/…/ProxyBackend.java• L132-179

Converse translation

BedrockOpenAiTranslator bridges the two conversation contracts. It preserves the meaning of system, user, and assistant text while adapting Bedrock content blocks to OpenAI messages. It also carries inference options and tool definitions across the boundary.

Tool use is treated as a two-way contract. Bedrock toolUse blocks become OpenAI tool calls with JSON arguments, while OpenAI tool calls become Bedrock toolUse blocks. Tool results become OpenAI tool messages and retain the tool call ID needed to connect a result to the earlier call.

For normal responses, the translator returns assistant content, token usage, latency, and a Bedrock stop reason. It derives tool_use from actual usable tool blocks. It does not claim tool use from a provider finish reason when the response has no matching tool call.

References: src/…/BedrockOpenAiTranslator.java• L18-25 src/…/BedrockOpenAiTranslator.java• L29-108 src/…/BedrockOpenAiTranslator.java• L117-177 src/…/BedrockOpenAiTranslator.java• L208-261

Streaming responses

Converse streaming gives clients incremental Bedrock events instead of one complete JSON result. The local stub writes a known event sequence, while the proxy reads OpenAI server-sent events and forwards text as soon as it arrives.

The stream path is:

sequenceDiagram
    participant Client as Bedrock client
    participant Runtime as Runtime service
    participant Proxy as Proxy backend
    participant Model as OpenAI-compatible service

    Client->>Runtime: ConverseStream request
    Runtime->>Proxy: Select proxy and resolve model
    Proxy->>Model: Streaming chat request
    Model-->>Proxy: SSE text and tool-call chunks
    Proxy-->>Client: Bedrock event-stream frames
    Proxy-->>Client: message stop and metadata

BedrockStreamEncoder frames each event as application/vnd.amazon.eventstream and flushes it to the response. Text deltas arrive as content events. Tool-call fragments are collected until their ID, name, and JSON arguments form a usable tool block. The stream then reports a Bedrock stop reason and usage metadata.

The HTTP response starts before the full upstream stream ends. If the upstream closes without a finish reason or [DONE], the service cannot change the status code, so it writes an in-band modelStreamErrorException event. This keeps the failure visible to a Bedrock client after a successful HTTP start.

References: src/…/BedrockRuntimeController.java• L77-99 src/…/BedrockStreamEncoder.java• L12-50 src/…/BedrockOpenAiTranslator.java• L264-363 src/…/ProxyBackend.java• L85-110

Configuration boundaries

Bedrock Runtime keeps backend choice and proxy connection details in the emulator configuration. The default backend is the local stub, while proxy mode needs an endpoint and a usable model selection rule. These settings are the integration points between the emulator and an external AI service.

The main configuration concerns are:

  • Backend choice: stub or proxy.
  • Proxy URL: the base address used to form /chat/completions.
  • API key: an optional bearer credential.
  • Model mapping and default model: rules for converting Bedrock IDs to provider IDs.
  • Passthrough: whether an unmapped Bedrock ID can go to the provider unchanged.
  • Request timeout: the limit for an upstream generation call.

The proxy treats upstream response data as untrusted. Non-success status codes, unreachable services, timeouts, malformed JSON, and incomplete successful responses produce explicit AWS-shaped failures rather than fabricated model output.

For the wider configuration and service lifecycle, see Service configuration and lifecycle. For the shared request and protocol model, see Request routing and protocols. For the related agent runtime, see Bedrock AgentCore. For related infrastructure deployment, see CloudFormation. For identity and access behavior, see IAM and authentication.

References: src/…/BedrockRuntimeService.java• L47-57 src/…/ProxyBackend.java• L118-179 src/…/ProxyBackend.java• L181-207

Change checklist

When these files or sections are changed, remember to consider these:

  • If guardrail request or response fields change, keep draft reads, numbered versions, list summaries, resource policies, and tag lookups aligned.
  • If guardrail policy configuration names change, preserve the conversion between create/update input shapes and read response shapes.
  • If guardrail version rules change, preserve the distinction between mutable DRAFT content and immutable numbered snapshots.
  • If resource identity or region handling changes, keep IDs, ARNs, storage scope, resource policies, and tag operations pointed at the same regional resource.
  • If inference profile creation changes, keep foundation model validation, system-profile expansion, idempotency, account checks, and resource discovery consistent.
  • If ARN recognition or parsing changes, keep bare IDs, ARN-shaped values, malformed ARN errors, cross-partition resources, and account boundaries on the intended paths.
  • If resource policy rules change, keep the allowed actions, exact resource match, principal rules, and regional profile policy scope aligned.
  • If tag handling changes, keep Bedrock tag actions and Resource Groups Tagging API delegation on the same resource state. Keep Bedrock array tags separate from AgentCore object tags while using the shared key and value rules.
  • If the Bedrock or provider message shape changes, update both directions of the translator. Tool IDs and JSON arguments must remain linked across the round trip.
  • If stream event names or payloads change, keep the event framing headers and Bedrock SDK event shapes aligned.
  • If model resolution changes, preserve the mapping, passthrough, and default precedence. Missing model configuration must still fail before the provider call.
  • If backend selection changes, keep all three backend operations aligned. Proxy InvokeModel is intentionally unsupported.
  • If timeout or upstream error handling changes, keep connection, timeout, HTTP status, malformed JSON, and mid-stream failures distinct.

Important failure modes

TriggerConsequenceGuard
Proxy mode has no URLThe request fails with ValidationException before the provider callValidate the proxy URL when building the upstream request
A model ID has no mapping, passthrough, or defaultThe request fails with ValidationExceptionResolve the model before sending the request
The provider times outThe request returns ModelTimeoutException with HTTP 408Apply the configured request timeout
The provider returns a non-success status or unusable JSONThe request returns ModelErrorException with HTTP 424Check the status and response shape before translation
Proxy InvokeModel is calledThe request is rejected instead of returning a guessed provider bodyUse Converse for proxy-backed model calls
A stream ends without a finish reason or [DONE]The client receives a started stream with an in-band model stream errorEmit modelStreamErrorException after the response starts
A guardrail name is invalid or already exists in the regionCreation fails with ValidationException or ConflictExceptionValidate the name and check existing drafts before storing the resource
A guardrail identifier is malformed or does not resolve to the regional resourceThe request fails with ValidationException or ResourceNotFoundExceptionKeep ARN-shaped input on ARN validation and check the resolved resource ARN
A guardrail version is missing or uses a non-numerical delete versionThe request fails with ResourceNotFoundException or ValidationExceptionResolve the resource and accept only numbered versions for version deletion
A referenced KMS key is missing, disabled, or pending deletionGuardrail creation or update fails with ValidationExceptionResolve the key and require a usable KMS state
An application profile source is not a same-region foundation model or system profileProfile creation fails with ValidationExceptionValidate the source ARN and expand only supported regional sources
A profile ARN belongs to another accountThe request fails with AccessDeniedExceptionCheck the profile account before reading or deleting it
A resource policy contains an unsupported action, principal, resource, or conditionThe request fails with ValidationExceptionValidate the policy against the resource-specific Bedrock policy rules
A tag entry has the wrong shape or invalid key/valueThe request fails with ValidationExceptionValidate the Bedrock tag list before parsing it
A tag request would exceed the resource tag limitThe tag change fails with TooManyTagsExceptionCount merged tags after replacements before storing them

Key files

FileWhy to read it
src/…/BedrockController.javaDefines the Bedrock control-plane routes, region boundary, model catalog, inference profile, policy, tag, and response shapes
src/…/BedrockService.javaDefines guardrail storage, versioning, model and profile lookup, resource policies, KMS checks, ARN handling, discovery, and tag behavior
src/…/BedrockTagValidator.javaDefines validation for Bedrock array-shaped tags
src/…/Guardrail.javaDefines the resource data shared by guardrail actions and responses
src/…/ApplicationInferenceProfile.javaDefines the stored application inference profile data and its regional identity
src/…/BedrockRuntimeController.javaDefines the Bedrock Runtime request surface and validation boundary
src/…/BedrockRuntimeService.javaShows configuration-based backend selection
src/…/BedrockBackend.javaDefines the shared contract for normal and streaming operations
src/…/StubBackend.javaShows the deterministic no-network emulation
src/…/ProxyBackend.javaShows model resolution, provider calls, time limits, and error mapping
src/…/BedrockOpenAiTranslator.javaShows the Bedrock and OpenAI request, tool, response, and stream boundary
src/…/BedrockStreamEncoder.javaShows the Bedrock event-stream framing boundary
src/…/BedrockAgentCoreTagValidation.javaShows the shared tag key and value rules used by AgentCore tag objects