← Back to documentation

Amazon Bedrock API: GPT and Claude integration

Configure Runtime and Mantle, verify access, send SDK/HTTP requests and handle streaming, errors, cost and data retention.

What this guide verifies

This reference covers OpenAI GPT and Anthropic Claude access through Amazon Bedrock. Official documentation was checked on 17 October 2026. The examples were not sent to a cloud API. They do not establish that a particular account has model access, quota or an approved deployment.

All credential, Region, model/profile and account values in executable examples come from placeholders or environment variables. Have the account administrator verify them in the Bedrock console and current model card before use. Keep credentials on the server, use an approved secret store or workload identity, and never include them in browser bundles, screenshots or logs.

1. Choose the complete connection configuration

The endpoint, API, model identifier and Region are a single configuration. Changing only the base URL can produce an invalid request or change where data is processed. AWS recommends Runtime for new applications when the required model and features are supported.

Path Base URL for the SDK Identifier examples from current AWS cards
GPT-6.1 Sol, Runtime Responses/Chat https://bedrock-runtime.{region}.amazonaws.com/openai/v1 us.openai.gpt-6.1-sol or global.openai.gpt-6.1-sol; a supported source Region is required
GPT-6.1 Sol, Mantle Responses/Chat https://bedrock-mantle.us-east-1.api.aws/openai/v1 openai.gpt-6.1-sol; in-Region access in N. Virginia
Claude Sonnet 5, Runtime Messages https://bedrock-runtime.{region}.amazonaws.com/anthropic us.anthropic.claude-sonnet-5, other supported geographic profiles, or global.anthropic.claude-sonnet-5
Claude Sonnet 5, Mantle Messages https://bedrock-mantle.{region}.api.aws/anthropic anthropic.claude-sonnet-5; verify its supported Mantle Region

These are documented identifier examples, not proof of access. GPT-6.1 Sol and Claude Sonnet 5 do not support direct in-Region invocation on Runtime; use the supported profile. Geographic routing and Global routing have different processing boundaries. Confirm source and destination Regions for the chosen profile instead of treating the source endpoint as the processing location.

Bedrock supports proprietary GPT models as well as open-weight gpt-oss models. They are different model families and cannot share every configuration. GPT OSS supports Chat Completions, Converse and Invoke on Runtime; its Responses access requires Mantle. Mantle's path prefix also varies: GPT-6.1 Sol uses /openai/v1, while some models use /v1. Use the individual card's Programmatic Access section.

2. Prepare access and least privilege

Confirm an AWS account, supported Region, payment/terms prerequisites and model availability. Some third-party activation requires AWS Marketplace permissions; an administrator can activate the model once without giving subscription permissions to every runtime caller. Account-level access can still differ after activation.

Anthropic first use through Runtime requires the use-case form; the current model-access documentation exempts the Mantle path from this requirement. Check agreement status when activation succeeds but invocation remains denied. Do not solve access failures by switching to an unapproved account or region.

Authentication does not grant authorization. Runtime inference requires bedrock:InvokeModel; streaming requires bedrock:InvokeModelWithResponseStream. Runtime Responses additionally authorizes the account's default Project. Reading, cancelling or deleting stored responses has separate actions. Mantle inference uses bedrock-mantle:CreateInference. Scope policies to the actual targets and check inference-profile destination permissions and organizational policies.

Use AWS credential-chain signing or short-term Bedrock bearer credentials for production where supported. A Bedrock API key is not an OpenAI or Anthropic direct-service key. Short-term Bedrock keys inherit IAM permissions and expire; long-term keys are intended for exploration and are Region-specific. Do not print generated tokens. The examples below assume an already authorized server environment.

3. Minimal GPT request with the OpenAI SDK

Install the OpenAI SDK in your application environment. Set BEDROCK_BASE_URL, BEDROCK_MODEL_ID and AWS_BEARER_TOKEN_BEDROCK through your approved configuration process. BEDROCK_MODEL_ID is a verified profile for Runtime or a verified foundation-model ID for Mantle; it is never an arbitrary OpenAI direct-service ID.

import os
from openai import OpenAI

# Replace environment placeholders after checking the console/model card.
client = OpenAI(
    base_url=os.environ["BEDROCK_BASE_URL"],
    api_key=os.environ["AWS_BEARER_TOKEN_BEDROCK"],
)
response = client.responses.create(
    model=os.environ["BEDROCK_MODEL_ID"],
    input="Explain the difference between input and output tokens.",
    max_output_tokens=512,
    store=False,
)
print(response.output_text)

The matching HTTP contract is POST <BEDROCK_BASE_URL>/responses, with Content-Type: application/json and Authorization: Bearer <BEDROCK_API_KEY>. The JSON body has model, input, max_output_tokens and store. For example:

# Replace the model placeholder; BASE_URL/key must already be configured securely.
curl --fail-with-body "$BEDROCK_BASE_URL/responses" \
  -H "Authorization: Bearer $AWS_BEARER_TOKEN_BEDROCK" \
  -H "Content-Type: application/json" \
  --data '{"model":"<VERIFIED_MODEL_OR_PROFILE_ID>","input":"Say hello.","max_output_tokens":512,"store":false}'

For Chat Completions, use /chat/completions, a messages array, and read choices[].message. Do not send a Responses input body to Chat Completions. GPT-6.1 Sol tool use should be designed against its current Responses support rather than assuming an identical Chat contract.

4. Streaming is an event protocol

For GPT Responses set stream=True. Text arrives as response.output_text.delta; response.completed identifies a completed response. Handle error/failed/incomplete outcomes and an unexpectedly closed stream. Do not treat receipt of the first token as task completion.

# Uses the same verified client and model configuration as the previous example.
completed = False
for event in client.responses.create(
    model=os.environ["BEDROCK_MODEL_ID"],
    input="Explain token budgeting briefly.",
    max_output_tokens=512, store=False, stream=True,
):
    if event.type == "response.output_text.delta":
        print(event.delta, end="", flush=True)
    elif event.type == "response.completed":
        completed = True
    elif event.type in {"error", "response.failed", "response.incomplete"}:
        raise RuntimeError("Generation did not complete")
if not completed:
    raise RuntimeError("Stream ended without completion")

Chat Completions uses choices[].delta chunks, not Responses event objects. Claude Messages uses content-block events; AWS ConverseStream uses a different AWS event structure. Keep each parser tied to its API. For raw HTTP streaming, request "stream":true and use an SSE-aware client; curl -N only disables display buffering and does not implement error recovery.

5. Claude: native Messages or Bedrock Invoke/Converse

The Anthropic SDK uses the base URL ending in /anthropic; it adds /v1/messages. Both Runtime and Mantle can expose that route for supported Claude models.

import os
from anthropic import Anthropic

# BASE_URL ends in /anthropic; MODEL_ID is verified for this endpoint/Region.
claude = Anthropic(
    base_url=os.environ["BEDROCK_ANTHROPIC_BASE_URL"],
    api_key=os.environ["AWS_BEARER_TOKEN_BEDROCK"],
)
with claude.messages.stream(
    model=os.environ["BEDROCK_CLAUDE_MODEL_ID"],
    max_tokens=512,
    messages=[{"role":"user", "content":"Explain token budgeting briefly."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
    final_message = stream.get_final_message()

The native HTTP request is POST <.../anthropic>/v1/messages. It uses x-api-key: <BEDROCK_API_KEY>, anthropic-version: 2023-06-01, and a body containing model, messages, max_tokens and optional stream.

When using boto3 invoke_model instead, the model/profile is the modelId argument and the JSON body must include "anthropic_version":"bedrock-2023-05-31". This body field is not the native Messages HTTP version header. Converse has another request format, with messages[].content[].text; do not interchange these payloads.

import json, os, boto3

# The approved AWS credential chain supplies signing credentials; no embedded keys.
runtime = boto3.client("bedrock-runtime", region_name=os.environ["AWS_REGION"])
result = runtime.invoke_model(
    modelId=os.environ["BEDROCK_CLAUDE_MODEL_ID"],
    contentType="application/json", accept="application/json",
    body=json.dumps({
        "anthropic_version":"bedrock-2023-05-31",
        "max_tokens":512,
        "messages":[{"role":"user", "content":"Say hello."}],
    }),
)
body = json.loads(result["body"].read())
print(body["content"])

6. Diagnose errors by layer

Symptom Check first Response
400 or unsupported route/model Path prefix, API body, profile and feature support Correct configuration before retrying
403 / AccessDenied IAM, Project, Marketplace/agreement, FTU and account access Resolve the missing permission or activation with the administrator
Invalid/expired credential or Region-scope message Credential expiry, credential Region and signed request context Refresh through the approved identity path
429 / throttling Account/model quota, concurrency and combined token demand Reduce load; bounded backoff with jitter
503 / 529 overload Serving capacity, response headers and service health Bounded backoff; honor Retry-After when returned
Timeout or stream closes early Client/proxy deadlines, network idle timeouts and terminal event Record incomplete status and inspect outcome before retry

Record request ID, timestamp, endpoint, model/profile, status and sanitized usage. Do not log credentials or full sensitive prompts by default. Bound retries and total elapsed time; a lost response does not prove that no tokens were consumed. Business writes triggered by tools need their own operation ID and duplicate protection.

7. Estimate cost and review data handling

Use AWS pricing for the exact model, routing option and service tier. Calculate separate billed input, output, cache-read and cache-write categories, then add applicable retrieval, embedding, storage, networking and tool resources. Avoid double-counting cache categories already included in a total. GPT-6.1 Sol has specific long-context thresholds, cache rates and Standard/Ultrafast pricing; do not copy a direct OpenAI price into an AWS estimate without checking those conditions.

Responses defaults to store:true and retains conversation input/output for 30 days. These examples use store:false, so they cannot continue with previous_response_id. Review application logs and invocation logging separately. With Runtime cross-Region inference, stored responses reside in the Region that processed the request, which can differ from the source Region.

Runtime Responses requires model on every request and supports only the default Project; background:true is rejected. It does not support application inference profiles. Runtime does not expose OpenAI-compatible GET /models; use Bedrock control-plane discovery and model cards. Mantle feature and retention behavior differs.

Model-specific restrictions take precedence over broad compatibility assumptions. The GPT-6.1 Sol card says integrated Guardrails is unavailable with Responses and lists other unsupported features. Claude structured-output support also differs by API/endpoint. Do not claim that an SDK-compatible request automatically receives every Bedrock control.

Before production, verify an authorized request, an unauthorized request, an unsupported configuration, a complete stream and a simulated dependency failure. Deliver sanitized evidence, usage observations and a rollback configuration. This guide is based on documentation; it does not claim that a live account was used or that end-to-end cloud acceptance testing was performed.

Official references — checked 17 October 2026