Chat Completions API
The OpenAI Chat Completions API generates conversational responses using Amazon Bedrock models.
Use the bedrock-runtime endpoint for new applications. Use
bedrock-mantle only when a model or capability that you require isn't
available on bedrock-runtime. For complete API details, see the OpenAI
Chat Completions documentation
| Endpoint | Base URL | Authentication |
|---|---|---|
bedrock-runtime (recommended) |
https://bedrock-runtime.{region}.amazonaws.com/openai/v1/chat/completions |
AWS credentials (SigV4) or Amazon Bedrock API key |
bedrock-mantle (compatibility) |
https://bedrock-mantle.{region}.api.aws/v1/chat/completions |
Amazon Bedrock API key or AWS credentials |
Note
On bedrock-mantle, the path prefix varies by model. Most models are served
under /v1, as shown in the preceding table, but some are served under
/openai/v1 instead. A request that uses the wrong prefix for a model is
rejected with model `<model-id>` isn't supported on this
route. To confirm the base URL for a specific model, see the
Programmatic Access table on its card in
Models at a glance.
Each endpoint has its own per-model token quotas. For details on the quotas applied to traffic on each endpoint, see Quotas for the bedrock-runtime endpoint and Quotas for the bedrock-mantle endpoint.
Chat Completions with the bedrock-runtime endpoint
The bedrock-runtime endpoint supports AWS SigV4 authentication and Amazon Bedrock API key authentication.
Choose a model
Important
bedrock-runtime doesn't implement the OpenAI-compatible
GET /models operation, so client.models.list() and
GET /openai/v1/models don't work on this endpoint. Use
ListFoundationModels,
ListInferenceProfiles,
and the endpoint-specific tables in Models at a glance. For examples,
see Get list of models.
Note
The following examples use openai.gpt-oss-120b-1:0. GPT OSS
models support Chat Completions on bedrock-runtime, but don't
support the Responses API there. To use both OpenAI-compatible APIs on
bedrock-runtime, choose a model whose model card lists both APIs
as supported.
Create a chat completion
To create a chat completion, choose the tab for your preferred method, and then follow the steps:
Chat Completions with the bedrock-mantle endpoint
Use bedrock-mantle as a compatibility option when a model or feature that
you require isn't available on bedrock-runtime. The endpoint supports
Amazon Bedrock API key authentication, AWS credentials, and the OpenAI SDK.
The examples in this section read the OPENAI_BASE_URL and
OPENAI_API_KEY environment variables. Set them to the
bedrock-mantle base URL and your Amazon Bedrock API key:
OPENAI_BASE_URL="https://bedrock-mantle.<your-region>.api.aws/v1" OPENAI_API_KEY="<provide your Bedrock API key>"
Important
Point OPENAI_BASE_URL at bedrock-mantle for these
examples. Model cards set it to the bedrock-runtime base URL
(https://bedrock-runtime.{region}.amazonaws.com/openai/v1), and
bedrock-runtime doesn't implement the Models API, so listing models
against that base URL returns
404 UnknownOperationException.
List available models
The OpenAI-compatible Models API is available only on
bedrock-mantle. To list models available on this endpoint,
choose the tab for your preferred method, and then follow the steps:
Create a chat completion
Choose the tab for your preferred method, and then follow the steps:
Streaming
To receive responses incrementally, choose the tab for your preferred method, and then follow the steps:
Include a guardrail in a chat completion
To include safeguards in model input and responses, apply a guardrail when running model invocation by including the following extra parameters
-
extra_headers– Maps to an object containing the following fields, which specify extra headers in the request:-
X-Amzn-Bedrock-GuardrailIdentifier(required) – The ID of the guardrail. -
X-Amzn-Bedrock-GuardrailVersion(required) – The version of the guardrail. -
X-Amzn-Bedrock-Trace(optional) – Whether or not to enable the guardrail trace.
-
-
extra_body– Maps to an object. In that object, you can include theamazon-bedrock-guardrailConfigfield, which maps to an object containing the following fields:-
tagSuffix(optional) – Include this field for input tagging.
-
For more information about these parameters in Amazon Bedrock Guardrails, see Test your guardrail.
To see examples of using guardrails with OpenAI chat completions, choose the tab for your preferred method, and then follow the steps: