Skip to main content

Bedrock Invoke API

The Bedrock Invoke API sends a model's native request body to /model/{model}/invoke. The gateway serves this format at /bedrock/model/{model}/invoke and /invoke-with-response-stream, so applications that use InvokeModel can authenticate with a virtual key and go through the gateway. Because the body is model specific, the gateway recognises the Anthropic, Amazon Nova, Meta, Mistral and Cohere body formats and translates them for the deployment behind the public model name.

Scenario​

A data team has a pipeline that calls Bedrock's InvokeModel with Anthropic style bodies and depends on a model parameter that only the Invoke format exposes. The admin registers the model with the bedrock/invoke/ prefix so the gateway always uses Invoke, and the pipeline swaps its AWS endpoint for the gateway URL and a virtual key.

Steps​

  1. Register the model for Invoke. In the Admin UI open Models + Endpoints (/ui/models-and-endpoints), click Add Model, pick AWS Bedrock, choose Custom Model Name and type bedrock/invoke/us.anthropic.claude-sonnet-5-5, set the Public Model Name to claude-sonnet-5-5, enter the region and click Add Model.

    model_list:
    - model_name: claude-sonnet-5-5
    spanway_params:
    model: bedrock/invoke/us.anthropic.claude-sonnet-5-5
    aws_region_name: us-east-1
  2. Create a key in Virtual Keys (/ui/api-keys) and pick the model under Models.

  3. Send an Invoke request with the model's native body.

    curl -X POST "http://localhost:4000/bedrock/model/claude-sonnet-5-5/invoke" \
    -H "Authorization: Bearer $SPANWAY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
    "anthropic_version": "bedrock-2023-05-31",
    "max_tokens": 200,
    "messages": [{"role": "user", "content": "Explain a model group in one sentence."}]
    }'

    /invoke-with-response-stream returns the Bedrock binary event stream that the AWS SDKs expect.

  4. Check the log. Open Logs (/ui/logs) and find the request with its cost.

Expected result​

The response body is the model's native response, for example an Anthropic message object for Claude models, with usage reported in the model's own fields. The gateway reads the usage to record cost, and the Logs row shows the tokens and the cost like any other call.

Choosing between Converse and Invoke​

Converse gives one request format for all Bedrock models and is what the Bedrock Converse page documents. Invoke exposes every model specific parameter and is required for some model features. Without a prefix the gateway picks Converse for models that support it and Invoke for the rest. Cross region inference profiles such as us. and global. prefixed model ids are supported, and bedrock/<region>/<model> routes a deployment to a specific region. For any other Bedrock runtime path, such as knowledge base retrieval, use the Bedrock pass-through.

Credentials​

The gateway signs requests with its own AWS credentials from the environment, an IAM role, web identity or an assumed role configured on the deployment. Clients never need AWS credentials. See the AWS Bedrock provider page for every variable the integration reads.

Errors​

Errors the gateway raises itself come back in the OpenAI shape, {"error": {"message": "...", "type": "...", "param": null, "code": "403"}}. That covers a missing or wrong key, a model the key may not use, a used-up budget and a rate limit. A path the gateway cannot read answers 400 with {"detail": {"error": "..."}}. Only errors AWS itself returns keep the Bedrock shape, {"message": "..."}, and its exception name.

StatusWhat it meansFix
400 ValidationExceptionThe body does not match the model's native format, for example a Converse style body sent to Invoke.Use the model family's own body format.
401The virtual key is missing, wrong or expired.Send Authorization: Bearer <key>.
403The key may not call the model. The message reads The requested model '<model>' is not available for this API key, or the model name is invalid.Add the model to the key in Virtual Keys.
403 AccessDeniedExceptionAWS refused the gateway's credentials for this model.Fix the IAM policy of the gateway's role.
404 ResourceNotFoundExceptionThe public model name is unknown, or the model is not enabled in the region.Check Models + Endpoints and the model access in the AWS console.
422The key, team or user has spent its budget (Budget has been exceeded!).Raise the budget or wait for it to reset.
429The key or team is over its rate limit, or Bedrock is throttling (ThrottlingException).Raise the key's limit, or add a deployment in another region and keep retries on.

Providers​

The gateway's endpoint support matrix marks 1 provider integration as supporting this endpoint:

AWS - Bedrock.