Skip to content

Bedrock Features

The Amazon Bedrock capabilities the gateway turns on for you, and the ARNs it is allowed to invoke. Part of the Configuration Guide.

Settings Summary

Bedrock Advanced

Variable Default Description
AWS_BEDROCK_CROSS_REGION_INFERENCE true Allow automatic model routing to other configured regions
AWS_BEDROCK_CROSS_REGION_INFERENCE_GLOBAL true Allow global cross-region inference routing to any region worldwide (disable for GDPR compliance)
AWS_BEDROCK_MODEL_REGION_RESTRICT {} Restrict a model to specific region(s) only (e.g. for region-specific features like Nova grounding)
AWS_BEDROCK_LEGACY false Allow usage of deprecated/legacy Bedrock models
AWS_BEDROCK_DEPRECATED_MODEL_FALLBACK true Transparently reroute requests using a deprecated model ID to its recommended replacement
AWS_BEDROCK_DEPRECATED_MODELS {} Additional deprecated model mappings merged with the built-in registry at startup
AWS_BEDROCK_MARKETPLACE_AUTO_SUBSCRIBE true Allow automatic subscription to new models in AWS Marketplace
AWS_BEDROCK_MARKETPLACE_ENDPOINTS_ENABLED false Publish Amazon Bedrock Marketplace model endpoints deployed in this account as chat models
AWS_BEDROCK_MARKETPLACE_ENDPOINT_REGIONS All AWS_BEDROCK_REGIONS Regions searched for Marketplace model endpoints; each must also be in AWS_BEDROCK_REGIONS
AWS_BEDROCK_ALLOW_MARKETPLACE_ENDPOINT_ARN false Allow users to pass a Marketplace model endpoint ARN directly as a model ID
AWS_SAGEMAKER_ENDPOINTS {} Amazon SageMaker AI endpoints published as chat models, keyed by model ID
AWS_SAGEMAKER_WARMUP_TIMEOUT 600 Seconds a request waits for a SageMaker AI endpoint scaled to zero to come back up (0 disables)
AWS_SAGEMAKER_ENDPOINT_URL Resolved Override for the SageMaker AI runtime endpoint URL (VPC endpoint or proxy)
AWS_BEDROCK_ALLOW_CROSS_REGION_INFERENCE_PROFILE_ARN false Allow users to pass cross-region inference profile ARNs directly as model IDs
AWS_BEDROCK_ALLOW_APPLICATION_INFERENCE_PROFILE_ARN false Allow users to pass application inference profile ARNs directly as model IDs
AWS_BEDROCK_ALLOW_PROMPT_ROUTER_ARN false Allow users to pass prompt router ARNs directly as model IDs
AWS_BEDROCK_ALLOW_PROMPT_ARN false Allow users to reference Prompt Management prompt ARNs in the Responses API prompt parameter
AWS_BEDROCK_MODEL_ARN_MAPPING {} Map model IDs to custom inference profile or prompt router ARNs (server-controlled routing)
AWS_BEDROCK_GUARDRAIL_IDENTIFIER None Bedrock Guardrails ID for content filtering and safety controls
AWS_BEDROCK_GUARDRAIL_VERSION None Bedrock Guardrails version number (required with identifier)
AWS_BEDROCK_GUARDRAIL_TRACE None Guardrails trace level: disabled, enabled, or enabled_full
AWS_BEDROCK_ALLOW_GUARDRAIL_OVERRIDE false Allow users to override global guardrail configuration via request headers (security: default off)
AWS_BEDROCK_SESSION_ENCRYPTION_KEY_ARN None KMS key ARN encrypting Amazon Bedrock session storage (Responses API store=true)
AWS_BEDROCK_BATCH_ROLE_ARN None Service role Amazon Bedrock assumes to run batch inference jobs; unset disables the Batch APIs
AWS_BEDROCK_USER_ROLE_ARN None Run each end user's model calls under a role session of their own, so AWS reports their spend separately
AWS_BEDROCK_USER_ROLE_SESSION_DURATION 3600 Lifetime in seconds of a per-end-user role session (900–3600)
AWS_BEDROCK_USER_ROLE_TAG_KEY user Session tag key carrying the end user identity, for cost allocation and access policies
AWS_BEDROCK_USER_ROLE_REQUIRE_IDENTITY false Reject a model request that identifies no end user instead of billing it to the server

Bedrock Guardrails

Amazon Bedrock Guardrails add content filtering and safety controls to model inputs and outputs. The configured guardrail also powers the OpenAI-compatible Moderations API (POST /v1/moderations); without one, that API falls back to inline guardrail checks in supported regions, then Amazon Comprehend.

Configuration Options

Guardrails can be configured in three ways:

  1. Global - Via environment variables
  2. Per-request - Via HTTP headers
  3. Request body - Via amazon-bedrock-guardrailConfig object

Route Coverage

The configured guardrail applies to every route that serves a request directly. The Batch API is the exception: Amazon Bedrock batch inference cannot apply a guardrail, so a batch a configured guardrail would cover is refused rather than run unchecked. Chat routes use the native Bedrock integration; routes whose AWS backend has no guardrail mechanism enforce it through the ApplyGuardrail API: client-supplied text is checked as INPUT before the backend call and generated text as OUTPUT after it. On the Realtime API, where content streams both ways for as long as the session is open, the check runs per turn and an intervention ends the session — see Guardrail coverage for what that does and does not catch.

Routes Mechanism Checked content
Chat Completions, Responses, Completions, Anthropic Messages Native (Converse guardrailConfig / InvokeModel) Model input and output
Moderations ApplyGuardrail (classification) Submitted text and images
Embeddings (OpenAI and Cohere v1/v2) ApplyGuardrail INPUT — each text input
Rerank (Cohere v1/v2) ApplyGuardrail INPUT — query and each document text
Images Generations / Edits ApplyGuardrail INPUT — prompt (Variations has no text to check)
Videos ApplyGuardrail INPUT — prompt
Audio Speech ApplyGuardrail INPUT — text to synthesize
Audio Transcriptions (including streaming) ApplyGuardrail OUTPUT — transcript
Audio Translations ApplyGuardrail OUTPUT — translated text
Realtime ApplyGuardrail INPUT — each written item before it reaches the model, and each transcribed caller turn; OUTPUT — each completed answer

Cost Tracking

AWS bills the guardrail on every route it applies to, but only the ApplyGuardrail-enforced ones report the units consumed. The mechanism a route uses therefore decides whether its guardrail cost is visible.

Mechanism Guardrail cost in usage logs
ApplyGuardrail Tracked — the response returns the units each policy consumed
Native (Converse / InvokeModel) Not tracked — the response reports no guardrail units

On ApplyGuardrail routes, the units AWS reports appear as text_units and input_images under one amazon.bedrock-runtime-guardrail-* model per applied policy, each priced at that policy's own rate; see Moderations billing. A route that checks both INPUT and OUTPUT calls the API twice, so it records two sets of units for one request.

On native routes the guardrail still runs and AWS still charges for it, but the Converse and InvokeModel responses carry no unit counts for the gateway to record. Reported costs on these routes are lower than the AWS bill by the guardrail's share. Deriving the units from text length instead would be a guess, not a measurement, so none is made.

Intervention Behavior

On ApplyGuardrail-enforced routes, a blocking intervention fails the request with HTTP 400 and error code content_filter (the same code chat routes report as their finish reason), carrying the guardrail's configured blocked messaging. A masking-only intervention (sensitive-information anonymization) substitutes the masked text — input masking reaches the backend model, and a masked transcript or translation is returned on the plain json/text formats. Response formats that cannot carry masked text (srt, vtt, verbose_json, diarized_json) fail with the same content_filter error instead of leaking the unmasked content.

Global Configuration

AWS_BEDROCK_GUARDRAIL_IDENTIFIER

Purpose : ID of the Bedrock Guardrail to apply

Required : Yes (together with AWS_BEDROCK_GUARDRAIL_VERSION)

export AWS_BEDROCK_GUARDRAIL_IDENTIFIER=abc123def456

AWS_BEDROCK_GUARDRAIL_VERSION

Purpose : Version of the Bedrock Guardrail

Required : Yes (together with AWS_BEDROCK_GUARDRAIL_IDENTIFIER)

export AWS_BEDROCK_GUARDRAIL_VERSION=1

AWS_BEDROCK_GUARDRAIL_TRACE

Purpose : Trace level for guardrail evaluation

Options : disabled, enabled, enabled_full

Default : None (optional)

export AWS_BEDROCK_GUARDRAIL_TRACE=enabled

AWS_BEDROCK_ALLOW_GUARDRAIL_OVERRIDE

Purpose : Control whether users can override the global guardrail configuration at request level via HTTP headers

Default : false (disabled for security)

Security Consideration : When set to false (default) and a global guardrail is configured, only the global configuration is enforced, preventing users from bypassing or modifying safety controls. Set to true if you need to allow per-request guardrail customization to override the global configuration.

Auto-Enable Behavior : If no guardrail is configured at all — both AWS_BEDROCK_GUARDRAIL_IDENTIFIER and AWS_BEDROCK_GUARDRAIL_VERSION unset, and no model alias carrying one — this setting is automatically set to true at startup, allowing per-request guardrails when no policy is enforced.

export AWS_BEDROCK_ALLOW_GUARDRAIL_OVERRIDE=true

Per-Alias Guardrails

A model alias can carry its own guardrail, applied to the requests naming it and overriding the global one. That is how a single deployment publishes the same model under a strictly guarded name and an unguarded one.

Complete Guardrail Configuration

export AWS_BEDROCK_GUARDRAIL_IDENTIFIER=abc123def456
export AWS_BEDROCK_GUARDRAIL_VERSION=1
export AWS_BEDROCK_GUARDRAIL_TRACE=enabled
export AWS_BEDROCK_ALLOW_GUARDRAIL_OVERRIDE=false  # Default: prevent overrides

Per-Request Guardrail Configuration

Header Usage Behavior

Request headers can be used when AWS_BEDROCK_ALLOW_GUARDRAIL_OVERRIDE is true:

  • No global guardrail configured: Setting is automatically true at startup, enabling per-request guardrails
  • Global guardrail configured: Setting defaults to false for security; set to true to allow overrides

This prevents users from bypassing configured safety controls while still allowing flexibility when no global policy exists.

Refused on a Mantle-served model

Amazon Bedrock Mantle has no guardrail parameter, so a guardrail cannot be applied to a model served through it. Whether a request carries these headers is not known until it arrives, so this cannot be caught at startup the way a global or alias guardrail combined with AWS_BEDROCK_MANTLE_PREFERRED_MODELS is. Such a request is refused with 400 rather than served unguarded: a caller who asked to be guarded is never answered as though the guardrail had run. The same refusal covers a deployment-wide guardrail meeting a Mantle-only model. Clear AWS_BEDROCK_MANTLE_PREFERRED_MODELS for a deployment that needs per-request guardrails to apply to these models.

Use HTTP headers to specify guardrail settings per request:

Header Purpose Valid Values
X-Amzn-Bedrock-GuardrailIdentifier Guardrail ID Your guardrail identifier
X-Amzn-Bedrock-GuardrailVersion Guardrail version Version number (e.g., 1)
X-Amzn-Bedrock-Trace Trace level disabled, enabled, enabled_full
X-Amzn-Bedrock-GuardrailStreamProcessingMode Guardrail assessment timing for streaming requests (stripped from non-streaming requests) sync, async
Example cURL Request
curl -X POST https://api.example.com/v1/chat/completions \
  -H "Authorization: Bearer sk-..." \
  -H "X-Amzn-Bedrock-GuardrailIdentifier: abc123def456" \
  -H "X-Amzn-Bedrock-GuardrailVersion: 1" \
  -H "X-Amzn-Bedrock-Trace: enabled" \
  -d '{"model": "anthropic.claude-sonnet-5", "messages": [...]}'

Request Body Configuration

The amazon-bedrock-guardrailConfig object in the request body is supported for OpenAI Chat Completions compatibility.

Compatibility Note

Only fields compatible with Bedrock Converse API are honored. The tagSuffix field is documented in AWS but not supported in this implementation.


Bedrock Session Storage

Requests with store=true on the Responses and Chat Completions APIs persist generations in Amazon Bedrock sessions. No environment variable is needed to enable this — it requires the Bedrock Session Storage IAM permissions.

Not available in every region

Amazon Bedrock session storage covers fewer regions than model inference. When the primary Bedrock region — the first entry of AWS_BEDROCK_REGIONS, which is where all sessions are created — does not provide it, store=true is ignored: the generation is still returned, and a warning is recorded in the request log stating that the session storage endpoint was unreachable or timed out and that session storage is offered in fewer regions than model inference. Retrieving a stored object then returns 404. A missing bedrock:CreateSession permission produces a distinct AccessDenied warning pointing at the IAM permissions instead.

Nothing fails and no request is lost, but stored responses and stored chat completions are simply unavailable. To rely on them, make the primary Bedrock region one that offers session storage — check the Amazon Bedrock session management endpoints for current coverage.

AWS_BEDROCK_SESSION_ENCRYPTION_KEY_ARN

Purpose : KMS key ARN encrypting the Amazon Bedrock sessions that back stored responses and stored chat completions (store=true)

Default : None — sessions are encrypted with the AWS-managed key

Validation : Checked at startup: must be a KMS key ARN (arn:<partition>:kms:<region>:<account-id>:key/<key-id>).

export AWS_BEDROCK_SESSION_ENCRYPTION_KEY_ARN=arn:aws:kms:us-east-1:123456789012:key/abcd-...

Shared Visibility Across Deployments

Stored responses and chat completions are namespaced by AWS account and region, not by stdapi.ai deployment. Multiple deployments sharing the same account and region can list, retrieve, and delete each other's stored objects. Use a dedicated AWS account per deployment when isolation matters, or accept this shared visibility as a deliberate trade-off.

Orphaned Session Cleanup

A session is created independently of the generation it will hold — before it for the Responses API, concurrently with it for Chat Completions — so a crash before the generation is written leaves an empty, orphaned session. Bedrock sessions have no TTL and persist until deleted, so periodically clean up stale sessions (aws bedrock-agent-runtime list-sessions plus delete-session, or an operator-managed lifecycle policy).

AWS_BEDROCK_BATCH_ROLE_ARN

Purpose : AWS IAM service role that Amazon Bedrock batch inference assumes to read a batch's requests and write its results — required to enable the Batch API and the Message Batches API

Type : String — an IAM role ARN

Default : None — the batch endpoints answer 503 (529 on the Anthropic-compatible routes) and the server reports the disabled feature in its startup log

Behavior : The server passes this role when it submits a batch; Amazon Bedrock then reads the requests and writes the results with it. The role must be able to read and write every bucket configured with AWS_S3_BUCKET and AWS_S3_REGIONAL_BUCKETS, under AWS_S3_BATCHES_PREFIX.

Validation : Checked at startup: must be an IAM role ARN (arn:<partition>:iam::<account-id>:role/<name>). Leaving it unset is reported as a startup warning, never a failure.

export AWS_BEDROCK_BATCH_ROLE_ARN=arn:aws:iam::123456789012:role/stdapi-ai-batch

The role and two IAM policies come first

The role's trust policy must allow bedrock.amazonaws.com to assume it, and the server's own role needs iam:PassRole on this ARN. See IAM Permissions for copyable policies.

AWS_BEDROCK_USER_ROLE_ARN

Purpose : Run each end user's model calls under an AWS IAM role session of their own, so AWS reports Amazon Bedrock model usage per end user in Cost Explorer and in the Cost and Usage Report

Type : String — an IAM role ARN

Default : None — every request runs under the server's own identity, and AWS reports all model usage under it

Behavior : The server opens one short-lived session of this role per end user, caches it, and signs that user's model invocations with it. The identity is the authenticated caller when authentication is enabled, otherwise the identifier the request declares (safety_identifier or user on the OpenAI-compatible APIs, metadata.user_id on the Anthropic Messages API). Only model invocations are covered — guardrail evaluations, video generation, speech, transcription and translation keep the server's identity. A session that cannot be opened fails the request rather than falling back to the server's identity.

Validation : Checked at startup: must be an IAM role ARN (arn:<partition>:iam::<account-id>:role/<name>). The server also tries to assume it at startup and reports a warning — not a failure — when it cannot.

export AWS_BEDROCK_USER_ROLE_ARN=arn:aws:iam::123456789012:role/stdapi-ai-end-user

The role and two IAM policies come first

The role's trust policy must allow this server's own role to call both sts:AssumeRole and sts:TagSession on it, and the server's role needs the same two actions on this role ARN. See IAM Permissions for copyable policies, including the model ARNs a cross-region inference profile requires.

AWS_BEDROCK_USER_ROLE_SESSION_DURATION

Purpose : Lifetime of a per-end-user role session, in seconds

Type : Integer — 900 to 3600

Default : 3600

Behavior : Sessions are cached per end user and reopened shortly before they expire, so a longer lifetime means fewer AWS STS calls. The upper bound is imposed by AWS: the server itself runs under an assumed role, and a role session obtained from another role session cannot last longer than one hour, whatever the role's maximum session duration.

export AWS_BEDROCK_USER_ROLE_SESSION_DURATION=1800

AWS_BEDROCK_USER_ROLE_TAG_KEY

Purpose : Session tag key carrying the end user identity on each per-end-user role session

Type : String, or null to send no session tag

Default : user

Behavior : Activate this key as a cost allocation tag — in the AWS Billing console, under Cost allocation tags filtered by type IAM principal — to group Bedrock costs by end user in Cost Explorer. The same tag is testable in IAM policies as aws:PrincipalTag/<key>, so the role can be restricted per user. With no tag, end users are still distinguished by their role session name in the Cost and Usage Report.

Validation : Checked at startup: 1 to 128 characters over letters, digits, spaces and _ . : / = + - @; keys beginning with aws: are reserved by AWS and rejected.

export AWS_BEDROCK_USER_ROLE_TAG_KEY=end-user

AWS_BEDROCK_USER_ROLE_REQUIRE_IDENTITY

Purpose : Reject a model request that identifies no end user, instead of running it under the server's own identity

Type : Boolean

Default : false — such requests run under the server's identity, and their usage is reported under it

Behavior : Enable it so that no model usage escapes per-user attribution: a request carrying neither an authenticated caller nor an end user identifier is answered 400. Clients that never send one stop working, so enable it only once every client identifies its user — and note that some APIs, audio transcription among them, have no end user field at all, so on those it takes an authenticated caller. A real-time speech-to-speech session keeps for its whole life the identity it opened with, so while this is enabled it is refused rather than attributed to the server. Requires AWS_BEDROCK_USER_ROLE_ARN.

export AWS_BEDROCK_USER_ROLE_REQUIRE_IDENTITY=true

Two Backends Cannot Assume the Per-User Role

A Bedrock Mantle request and an Amazon SageMaker AI endpoint invocation are signed with the server's own credentials, so a model served there never runs under the per-end-user role and the aws:PrincipalTag conditions written on that role are never evaluated. The 400 still holds on both — a request identifying no end user is refused the same way, whichever backend serves the model — but the access policy does not.

For Mantle that is decidable ahead of time, so routing a dual-homed model there with a non-empty AWS_BEDROCK_MANTLE_PREFERRED_MODELS, which is the default, stops the server at startup; clear that setting to keep both. Mantle-only models and SageMaker AI endpoints have no classic endpoint to fall back to — nothing is refused at startup for them, and an identified request is served under the server's own role.


Bedrock Service Tier and Performance Configuration

Amazon Bedrock service tiers and performance configurations allow you to optimize AI workload performance and cost trade-offs. Configure latency optimization and throughput priority for your inference requests.

AWS Documentation

For detailed information about service tiers, see:

Service Tiers

Service tiers help you match AI workload performance with cost by selecting the appropriate throughput and latency characteristics:

  • priority - Highest priority processing with guaranteed capacity and fastest response times. Best for latency-sensitive applications.
  • default - Standard processing with balanced performance and cost. Suitable for most production workloads.
  • flex - Cost-optimized processing with flexible scheduling. Best for batch jobs and non-time-sensitive workloads.
  • reserved - Dedicated reserved capacity with a throughput commitment (requires an AWS contract). Best for predictable workloads needing an uptime guarantee.

Performance Configuration

Performance configuration allows you to optimize for latency:

  • standard - Standard latency profile with balanced performance
  • optimized - Optimized for lowest possible latency

Per-Request Service Tier Configuration

Configure service tier and performance settings per request using HTTP headers. These headers are available on all Bedrock-based routes (Chat Completions, Embeddings, Images). Server-side per-model defaults can be set with DEFAULT_MODEL_SERVICE_TIERS.

Header Purpose Valid Values
X-Amzn-Bedrock-Service-Tier Service tier selection priority, default, flex, reserved
X-Amzn-Bedrock-PerformanceConfig-Latency Latency optimization standard, optimized

The tier header is subject to the override gate

When AWS_BEDROCK_ALLOW_SERVICE_TIER_OVERRIDE is false, X-Amzn-Bedrock-Service-Tier — like the service_tier request parameter — is ignored for any model that has a tier configured, by DEFAULT_MODEL_SERVICE_TIERS or by the alias the request names. A model with no configured tier honors the header in either case. The response's service_tier field keeps echoing the request's own value; usage and cost reporting record the tier that actually served the call.

Configured tiers, the header and this gate all apply to models served through the Bedrock Converse and InvokeModel APIs. On a Bedrock Mantle-served model, the request's own service_tier parameter is what applies — the header is not read, no configured tier is added, and the response reports the tier that model returns.

Example: Chat Completions with Priority Tier and Optimized Latency
curl -X POST https://api.example.com/v1/chat/completions \
  -H "Authorization: Bearer sk-..." \
  -H "X-Amzn-Bedrock-Service-Tier: priority" \
  -H "X-Amzn-Bedrock-PerformanceConfig-Latency: optimized" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic.claude-sonnet-5",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
Example: Embeddings with Flex Tier for Batch Processing
curl -X POST https://api.example.com/v1/embeddings \
  -H "Authorization: Bearer sk-..." \
  -H "X-Amzn-Bedrock-Service-Tier: flex" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "amazon.nova-2-multimodal-embeddings-v1:0",
    "input": ["text 1", "text 2", "text 3"]
  }'
Example: Image Generation with Default Tier
curl -X POST https://api.example.com/v1/images/generations \
  -H "Authorization: Bearer sk-..." \
  -H "X-Amzn-Bedrock-Service-Tier: default" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "amazon.nova-canvas-v1:0",
    "prompt": "A serene mountain landscape"
  }'

When to Use Each Tier

Priority Tier:

  • Real-time customer-facing applications
  • Interactive chatbots and assistants
  • Applications requiring guaranteed low latency
  • Production workloads with strict SLAs

Default Tier:

  • Standard production workloads
  • General-purpose API usage
  • Applications with moderate latency requirements

Flex Tier:

  • Batch processing and bulk operations
  • Offline content generation
  • Data processing pipelines
  • Non-time-sensitive workloads
  • Cost-optimized inference at scale

Audio and Text-to-Speech

DEFAULT_TTS_MODEL

Purpose : Default text-to-speech model when not specified in requests

Default : amazon.polly-standard

Model Description Quality
amazon.polly-standard Standard Polly voices Classic quality
amazon.polly-neural Neural Polly voices Higher quality, more natural
amazon.polly-long-form Long-form content Optimized for long content
amazon.polly-generative Generative AI voices Latest technology
export DEFAULT_TTS_MODEL=amazon.polly-neural

DEFAULT_TTS_LANGUAGE

Purpose : Default language code for text-to-speech synthesis when using OpenAI voice names

Default : None (automatic language detection via Amazon Comprehend)

Behavior : When specified, this language is used instead of automatic detection. When not set, Amazon Comprehend detects the language automatically from the input text.

Valid Language Codes: Any Amazon Polly language code (e.g., en-US, fr-FR, es-ES, de-DE, ja-JP)

# Use English (US) for all TTS requests
export DEFAULT_TTS_LANGUAGE=en-US

# Use French for all TTS requests
export DEFAULT_TTS_LANGUAGE=fr-FR

Performance Benefits

Setting a default language improves performance by:

  • Faster responses: Skips language detection API call to Amazon Comprehend
  • Reduced costs: No Amazon Comprehend charges for language detection
  • Predictable voice selection: Always uses voices from the specified language

When to Use

Consider setting a default language when:

  • Your application primarily serves content in a single language
  • You want to optimize response times and reduce AWS service calls
  • You prefer predictable voice selection over automatic language matching

Interaction with Voice Selection

This setting only affects automatic language detection when using OpenAI voice names (like alloy, echo, nova). If you specify a Polly voice ID directly (like Joanna, Matthew), language detection is already skipped.


Realtime API

REALTIME_CLIENT_SECRET_KEY

Purpose : Secret the Realtime API's ephemeral client secrets (POST /v1/realtime/client_secrets) are signed with

Type : String (any value)

Default : None — a signing key is derived from the configured API key instead

Behavior : Ephemeral client secrets are stateless: nothing is stored server-side, so any instance behind a load balancer verifies a secret minted by any other, as long as they all sign with the same key. By default that key is derived from the deployment's own API key, which is already shared across every instance — so this setting has nothing to add on a deployment that already configures one.

Set it explicitly on a deployment that runs with **no API key configured at all**: without either one, each instance falls back to a random key generated **per process**, and a client secret minted by one instance then fails to verify on any other — the symptom is an ephemeral secret rejected intermittently on a multi-instance deployment. Any value works, as long as every instance shares it.
export REALTIME_CLIENT_SECRET_KEY=a-value-shared-by-every-instance

Changing it invalidates outstanding secrets

A secret minted with one key does not verify against another. Rotating this setting (or the API key it would otherwise derive from) invalidates every client secret minted before the change — they simply stop working once their bearer tries to open a session, the same as if they had expired.

REALTIME_ALLOW_SESSION_OVERRIDE

Purpose : Whether a client connecting with an ephemeral client secret may override the session configuration that secret carries

Type : Boolean

Default : true — the upstream behavior: the carried configuration is a default the client may change

Behavior : A minted secret carries a session configuration, and by default a client opening a session with it may name another model on the ?model= query string and replace any of that configuration with its own session.update — exactly as it can against the upstream API.

Set to `false` on a multi-tenant deployment, where the secret is the only thing constraining an untrusted browser or mobile client. The `model`, the `instructions` and `max_output_tokens` the secret was minted with are then final: connecting with a `?model=` naming a different model is refused before the session opens, and a `session.update` changing any of the three answers an `error` event. Everything else — voice, audio formats, turn detection, transcription — stays under the client's control.
export REALTIME_ALLOW_SESSION_OVERRIDE=false

REALTIME_WEBRTC_ENABLED

Purpose : Serve WebRTC calls on POST /v1/realtime/calls, terminating the media path — ICE, DTLS-SRTP, Opus — in the server process

Type : Boolean

Default : false — the endpoint answers 404 and only the WebSocket transport is served

Behavior : Enabling it requires the webrtc optional dependencies (stdapi[webrtc], shipped in the container images; glibc only — aiortc publishes no musl wheels) and the server refuses to start without them. It also requires a network path the default deployment does not have: WebRTC media is UDP on ephemeral ports, negotiated directly to the instance that answered the SDP offer, which no HTTP(S) load balancer can carry. See the deployment section for what the Terraform module's media mode provisions, and the transport documentation for the call-control and duration limits that come with it.

export REALTIME_WEBRTC_ENABLED=true

REALTIME_WEBRTC_STUN_SERVER

Purpose : STUN server the gateway queries to discover its public address, which is then advertised to WebRTC callers as an ICE candidate

Type : String — a STUN URI, e.g. stun:stun.l.google.com:19302

Default : None — only the host's own addresses are advertised

Behavior : Required whenever the server sits behind 1:1 NAT, which is exactly the shape of an ECS task with a public IP: the task sees only its private address, so without STUN the SDP answer advertises addresses no caller can reach — the exchange succeeds and the call carries no audio. Any public STUN server works; the queried server learns nothing but the deployment's public address.

export REALTIME_WEBRTC_STUN_SERVER="stun:stun.l.google.com:19302"

REALTIME_WEBRTC_TURN_SERVER

Purpose : TURN relay advertised to WebRTC callers, carrying the media of callers whose networks block UDP to arbitrary ports

Type : String — a TURN URI, e.g. turn:turn.example.com:3478?transport=udp, with REALTIME_WEBRTC_TURN_USERNAME and REALTIME_WEBRTC_TURN_PASSWORD carrying its long-term credentials (all three together, or none)

Default : None — callers on UDP-blocking networks cannot establish media

Behavior : The relay is yours to run — coturn is the usual choice — because AWS offers no managed TURN service. It needs its own public address and its own always-on capacity, which is part of why a media framework in front remains the recommended shape for demanding audiences.

export REALTIME_WEBRTC_TURN_SERVER="turn:turn.example.com:3478?transport=udp"
export REALTIME_WEBRTC_TURN_USERNAME="stdapi"
export REALTIME_WEBRTC_TURN_PASSWORD="..."

REALTIME_WEBRTC_ALLOW_PRIVATE_CANDIDATES

Purpose : Accept the ICE candidates a WebRTC caller offers on addresses that are not globally routable — private (RFC 1918), shared (RFC 6598), loopback and link-local ones

Type : Boolean

Default : false — those candidates are dropped from the offer, and an offer left with no candidate at all is refused with invalid_offer

Behavior : An SDP offer names the addresses the server sends its ICE connectivity checks to, and the caller posting it holds nothing more than an ephemeral client secret. Screening the offer is what keeps an untrusted caller from aiming those UDP probes at addresses inside the deployment's own VPC. Enable this only where callers legitimately share that network — a same-VPC service, an on-premises deployment, a LAN — and the exchange otherwise succeeds with no media path. Hostname and mDNS (.local) candidates are dropped either way, whatever this is set to: resolving one is itself a lookup on the deployment's network, and a browser that offers only mDNS candidates cannot establish media with this gateway regardless.

export REALTIME_WEBRTC_ALLOW_PRIVATE_CANDIDATES=true

ARN Access Controls

Which Amazon Bedrock ARNs a request may name as its model, and how an ARN is mapped onto a model identifier.

AWS_BEDROCK_ALLOW_CROSS_REGION_INFERENCE_PROFILE_ARN

Purpose : Allow users to pass cross-region inference profile ARNs directly as model IDs in API requests

Type : Boolean

Default : false

Behavior : When enabled, users can use cross-region inference profile ARNs instead of model IDs in the model parameter. Cross-region inference profiles enable routing to multiple regions for better availability

IAM Permissions Required : bedrock:GetInferenceProfile (see IAM Permissions)

# Disabled (default) - users can only use standard model IDs
# No environment variable needed

# Enable cross-region inference profile ARN support
export AWS_BEDROCK_ALLOW_CROSS_REGION_INFERENCE_PROFILE_ARN=true

Additional IAM Permissions Required

Enabling this setting requires adding the bedrock:GetInferenceProfile IAM permission to your role/user. Without this permission, API requests using inference profile ARNs will fail with authorization errors.

See the Bedrock Inference Profiles and Prompt Routers IAM section for the complete policy configuration.

Example ARN

arn:aws:bedrock:us-east-1:123456789012:inference-profile/us.anthropic.claude-sonnet-5

Automatic Cross-Region Routing (Default Behavior)

By default, stdapi.ai automatically determines and uses the best cross-region inference profile for each model, based on AWS_BEDROCK_REGIONS, AWS_BEDROCK_CROSS_REGION_INFERENCE, and AWS_BEDROCK_CROSS_REGION_INFERENCE_GLOBAL. Manually passing cross-region inference profile ARNs is only needed in rare cases to override that selection — for most deployments, leave this disabled. See Using Inference Profile and Prompt Router ARNs for details.

AWS_BEDROCK_ALLOW_APPLICATION_INFERENCE_PROFILE_ARN

Purpose : Allow users to pass application inference profile ARNs directly as model IDs in API requests

Type : Boolean

Default : false

Behavior : When enabled, users can use application inference profile ARNs instead of model IDs in the model parameter. Application inference profiles are custom routing configurations for specific use cases

IAM Permissions Required : bedrock:GetInferenceProfile (see IAM Permissions)

# Disabled (default) - users can only use standard model IDs
# No environment variable needed

# Enable application inference profile ARN support
export AWS_BEDROCK_ALLOW_APPLICATION_INFERENCE_PROFILE_ARN=true

Additional IAM Permissions Required

Enabling this setting requires adding the bedrock:GetInferenceProfile IAM permission to your role/user. Without this permission, API requests using application inference profile ARNs will fail with authorization errors.

See the Bedrock Inference Profiles and Prompt Routers IAM section for the complete policy configuration.

Example ARN

arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc123xyz

What are Application Inference Profiles?

Application inference profiles are custom routing configurations that you create in your AWS account. They allow you to define specific routing behavior, region preferences, and failover strategies tailored to your application's needs.

When to Enable

Enable this setting when:

  • You have custom application inference profiles configured in your AWS account
  • You need application-specific routing configurations
  • You want to give users access to custom profiles you've created

AWS_BEDROCK_ALLOW_PROMPT_ROUTER_ARN

Purpose : Allow users to pass prompt router ARNs directly as model IDs in API requests

Type : Boolean

Default : false

Behavior : When enabled, users can use prompt router ARNs instead of model IDs in the model parameter. Prompt routers enable dynamic model selection based on prompt characteristics

IAM Permissions Required : bedrock:GetPromptRouter (see IAM Permissions)

# Disabled (default) - users can only use standard model IDs
# No environment variable needed

# Enable prompt router ARN support
export AWS_BEDROCK_ALLOW_PROMPT_ROUTER_ARN=true

Additional IAM Permissions Required

Enabling this setting requires adding the bedrock:GetPromptRouter IAM permission to your role/user. Without this permission, API requests using prompt router ARNs will fail with authorization errors.

See the Bedrock Inference Profiles and Prompt Routers IAM section for the complete policy configuration.

Example ARN

arn:aws:bedrock:us-east-1:123456789012:default-prompt-router/my-router

What are Prompt Routers?

Prompt routers are intelligent routing systems that analyze prompt characteristics (length, complexity, language) and dynamically select the most appropriate model. This enables cost optimization and performance tuning based on request patterns.

When to Enable

Enable this setting when:

  • You have prompt routers configured in your AWS account
  • You want intelligent cost optimization through dynamic model selection
  • You need automatic model selection based on prompt complexity

AWS_BEDROCK_ALLOW_PROMPT_ARN

Purpose : Allow users to reference an Amazon Bedrock Prompt Management prompt ARN in the OpenAI Responses API prompt parameter

Type : Boolean

Default : false

Behavior : When enabled, prompt.id accepts a prompt ARN (with an optional prompt.version) and prompt.variables fill in the template. Amazon Bedrock renders the stored prompt, and the model it is bound to serves the request. When disabled, any prompt parameter is rejected with a 400 error

IAM Permissions Required : bedrock:GetPrompt (resolve the prompt's model) and bedrock:RenderPrompt (invoke it)

# Disabled (default) - the Responses API `prompt` parameter returns 400
# No environment variable needed

# Enable Prompt Management prompt ARN support
export AWS_BEDROCK_ALLOW_PROMPT_ARN=true

Additional IAM Permissions Required

Enabling this setting requires adding the bedrock:GetPrompt and bedrock:RenderPrompt IAM permissions, scoped to the prompt resources you want to expose. Without them, requests using a prompt ARN fail with authorization errors.

Example ARN

arn:aws:bedrock:us-east-1:123456789012:prompt/ABCDE12345:1

Scope and Limitations

  • Only TEXT prompts are supported, and the request's model must be the model the prompt is bound to.
  • Prompt variable values must be plain strings.
  • input, instructions, tools, text, previous_response_id and inference parameters cannot be combined with prompt.

See Managed Prompt Templates for the full request contract.

AWS_BEDROCK_MODEL_ARN_MAPPING

Purpose : Map standard model IDs to custom inference profile or prompt router ARNs for server-controlled routing

Format : JSON object with model IDs as keys and ARNs as values

Default : {} (empty, no mappings)

Behavior : When configured, the mapped ARN is used instead of the default cross-region inference profile when clients request the model by its standard ID. This provides centralized control over model routing without requiring client changes

export AWS_BEDROCK_MODEL_ARN_MAPPING='{
  "anthropic.claude-sonnet-5": "arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/my-custom-profile",
  "anthropic.claude-haiku-4-5-20251001-v1:0": "arn:aws:bedrock:us-east-1:123456789012:default-prompt-router/my-router"
}'

What is Model ARN Mapping?

Model ARN mapping allows server administrators to override the default routing behavior for specific models. When a client requests a model using its standard ID (e.g., anthropic.claude-sonnet-5), the server automatically uses the mapped ARN for routing instead.

Supported ARN Types:

  • Cross-region inference profiles - AWS-managed multi-region routing
  • Application inference profiles - Custom routing configurations
  • Prompt routers - Intelligent dynamic model selection

Key Benefits

  • Centralized Control - Change routing behavior without modifying client code
  • Transparent to Clients - Clients use standard model IDs, server handles routing
  • Easy Migration - Switch between routing strategies by updating server config
  • Environment-Specific - Different mappings for dev/staging/production environments

Use Cases

Cost Optimization with Prompt Router:

export AWS_BEDROCK_MODEL_ARN_MAPPING='{
  "anthropic.claude-sonnet-5": "arn:aws:bedrock:us-east-1:123456789012:default-prompt-router/cost-optimizer"
}'
Automatically route simple prompts to cheaper models, complex prompts to premium models.

Custom Application Profile:

export AWS_BEDROCK_MODEL_ARN_MAPPING='{
  "anthropic.claude-sonnet-5": "arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/production-profile"
}'
Use your custom inference profile with specific region preferences and failover behavior.

Environment-Specific Routing:

# Production: Use cost-optimized prompt router
export AWS_BEDROCK_MODEL_ARN_MAPPING='{"anthropic.claude-sonnet-5": "arn:aws:bedrock:us-east-1:123456789012:default-prompt-router/prod-router"}'

# Development: Use standard cross-region profile
export AWS_BEDROCK_MODEL_ARN_MAPPING='{}'

Best Practices

  • Test mappings in development before deploying to production
  • Document your ARN mappings and their purposes
  • Keep ARN mappings in version control alongside other configuration
  • Monitor routing behavior after updating mappings

Startup Warning

If any model IDs in AWS_BEDROCK_MODEL_ARN_MAPPING are not found among available Bedrock models, a warning listing the affected entries is logged at startup. This typically means the model is not enabled in your configured regions or the model ID contains a typo.

Using Inference Profile and Prompt Router ARNs

stdapi.ai supports passing ARNs directly as model IDs in API requests, enabling advanced routing capabilities beyond standard model selection.

Simplify ARNs with Model Aliases

Instead of using long ARNs directly in API requests, you can create Model Aliases that map friendly names to ARNs. This provides shorter, easier-to-use naming for your API users.

Overview

Instead of using standard model IDs like anthropic.claude-sonnet-5, you can pass ARNs that reference:

  • Cross-Region Inference Profiles - AWS-managed multi-region routing
  • Application Inference Profiles - Your custom routing configurations
  • Prompt Routers - Intelligent dynamic model selection

Automatic Cross-Region Routing

stdapi.ai automatically handles cross-region routing by default. When you use standard model IDs, the application automatically selects and uses the optimal AWS-managed cross-region inference profile based on your configured AWS_BEDROCK_REGIONS.

You typically do not need to manually pass cross-region inference profile ARNs. The automatic selection handles routing across your configured regions for best availability and latency.

Manual ARN passing is primarily useful for:

  • Application inference profiles - Your custom routing configurations
  • Prompt routers - Intelligent cost optimization and dynamic model selection
  • Rare cases - When you need to override automatic cross-region profile selection

Enabling ARN Support

By default, users can only pass standard model IDs. To allow ARN usage, enable the appropriate settings:

# Allow cross-region inference profile ARNs
export AWS_BEDROCK_ALLOW_CROSS_REGION_INFERENCE_PROFILE_ARN=true

# Allow application inference profile ARNs
export AWS_BEDROCK_ALLOW_APPLICATION_INFERENCE_PROFILE_ARN=true

# Allow prompt router ARNs
export AWS_BEDROCK_ALLOW_PROMPT_ROUTER_ARN=true

Security Consideration

These settings are disabled by default. Only enable them when you want to give users explicit control over ARN-based routing. For centralized server-controlled routing, use AWS_BEDROCK_MODEL_ARN_MAPPING instead.

Using ARNs in API Requests

Once enabled, users can pass ARNs directly in the model parameter:

Cross-Region Inference Profile Example:

curl -X POST https://api.example.com/v1/chat/completions \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "arn:aws:bedrock:us-east-1:123456789012:inference-profile/us.anthropic.claude-sonnet-5",
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'

Application Inference Profile Example:

curl -X POST https://api.example.com/v1/chat/completions \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/my-custom-profile",
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'

Prompt Router Example:

curl -X POST https://api.example.com/v1/chat/completions \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "arn:aws:bedrock:us-east-1:123456789012:default-prompt-router/my-router",
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'

Use Case Comparison

Approach Best For Configuration
Standard Model IDs Most common use case, simple routing No special configuration needed
Server-Side ARN Mapping Centralized control, transparent to clients AWS_BEDROCK_MODEL_ARN_MAPPING
Client-Side ARN Passing User-controlled routing, advanced use cases Enable AWS_BEDROCK_ALLOW_*_ARN settings

Best Practices

Recommended Approach

For most deployments, use server-side ARN mapping (AWS_BEDROCK_MODEL_ARN_MAPPING):

  • Centralized control over routing behavior
  • Transparent to API clients
  • Easy to change routing without modifying client code
  • Better security (server controls which ARNs are used)

When to Allow Client-Side ARNs

Enable AWS_BEDROCK_ALLOW_*_ARN settings when:

  • Clients need fine-grained control over routing
  • Different clients require different routing strategies
  • Advanced users managing their own inference profiles
  • Testing and comparing different routing configurations

Security and Governance

When enabling client-side ARN passing:

  • Clients can bypass server-configured routing
  • Monitor usage to prevent unexpected costs
  • Ensure appropriate IAM permissions are in place
  • Track ARN usage through logs and monitoring

Required IAM Permissions

When using ARN-based routing, ensure your IAM role/user has the appropriate permissions:

{
  "Sid": "BedrockARNRouting",
  "Effect": "Allow",
  "Action": [
    "bedrock:GetInferenceProfile",
    "bedrock:GetPromptRouter"
  ],
  "Resource": "*"
}

See the IAM Permissions page for complete policy examples.