Skip to content

Support the Bedrock Mantle Anthropic Messages endpoint in @ai-sdk/amazon-bedrock #17141

Description

@gustaferiksson

Description

Recent Claude models (Opus 4.7/4.8, Sonnet 5, Haiku 4.5) are only available on bedrock-runtime through cross-region inference profiles:

$ aws bedrock get-foundation-model --model-identifier anthropic.claude-opus-4-7 \
    --query 'modelDetails.inferenceTypesSupported'
["INFERENCE_PROFILE"]

For in-region use, AWS instead serves them on the Bedrock Mantle Anthropic Messages endpoint, https://bedrock-mantle.{region}.api.aws/anthropic/v1/messages (Opus 4.7 model card, Messages API docs).

No @ai-sdk/amazon-bedrock entry point can reach this endpoint. Tested against anthropic.claude-opus-4-7 in eu-west-1:

  • bedrock(...) and bedrockAnthropic(...): Invocation of model ID anthropic.claude-opus-4-7 with on-demand throughput isn't supported
  • bedrockMantle(...): 400, The model 'anthropic.claude-opus-4-7' does not support the '/v1/chat/completions' API. Claude on Mantle only supports the Messages API, and the mantle subpath only implements the OpenAI-compatible surfaces.

This can't be worked around with provider settings: baseURL on createBedrockAnthropic still gets /model/{id}/invoke appended (the Mantle host 404s that shape), and a custom fetch can't rewrite the URL because SigV4 signing happens inside the provider before the fetch is called, so any rewrite invalidates the signature.

Proposed solution

@ai-sdk/amazon-bedrock/anthropic already has all the pieces (SigV4 and API-key fetch functions, AnthropicMessagesLanguageModel via @ai-sdk/anthropic/internal). The differences between the two endpoints are small:

bedrock-runtime (current) Mantle
Base URL https://bedrock-runtime.{region}.amazonaws.com https://bedrock-mantle.{region}.api.aws/anthropic
Request URL {base}/model/{id}/invoke[-with-response-stream] {base}/v1/messages
Versioning anthropic_version in body, model/stream stripped anthropic-version header, first-party body
Streaming Amazon eventstream framing native SSE

So an endpoint option on the existing factory would cover it:

const bedrockAnthropic = createBedrockAnthropic({ endpoint: "mantle" }) // default: "runtime"
const model = bedrockAnthropic("anthropic.claude-opus-4-7")

keyed off in getBaseURL, buildRequestUrl, and transformRequestBody. Auth, tool remapping, and error normalization are shared as-is. bedrockMantle.anthropic(...) would also work as a shape, but the anthropic subpath already owns the Messages dialect.

Current workaround

Pointing stock @ai-sdk/anthropic at the Mantle base URL with a SigV4-signing fetch. This works (verified with tool calling through an agent loop) because the endpoint speaks the exact first-party Messages dialect, only the auth differs:

import { createAnthropic } from "@ai-sdk/anthropic"
import { Sha256 } from "@aws-crypto/sha256-js"
import { fromNodeProviderChain } from "@aws-sdk/credential-providers"
import { SignatureV4 } from "@smithy/signature-v4"

async function signedFetch(input: string | URL | Request, init?: RequestInit): Promise<Response> {
    const url = new URL(input instanceof Request ? input.url : input)
    const headers = Object.fromEntries(new Headers(init?.headers).entries())
    delete headers["x-api-key"]
    const signer = new SignatureV4({
        service: "bedrock",
        region: process.env.AWS_REGION ?? "eu-west-1",
        sha256: Sha256,
        credentials: fromNodeProviderChain(),
    })
    const signed = await signer.sign({
        method: init?.method ?? "POST",
        protocol: url.protocol,
        hostname: url.hostname,
        path: url.pathname,
        headers: { ...headers, host: url.hostname },
        body: init?.body,
    })
    return fetch(url, { ...init, headers: signed.headers })
}

const mantleAnthropic = createAnthropic({
    baseURL: `https://bedrock-mantle.${process.env.AWS_REGION}.api.aws/anthropic/v1`,
    apiKey: "unused-requests-are-sigv4-signed",
    fetch: signedFetch,
})

const model = mantleAnthropic("anthropic.claude-opus-4-7")

AI SDK Version

  • ai: 6.0.222
  • @ai-sdk/amazon-bedrock: 4.0.132 (also checked 4.0.133, 5.0.17 / ai v7, and 5.0.0-canary.84: none reach the Mantle Messages endpoint)

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions