> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Amazon Bedrock Runtime

> Use the LoT Amazon Bedrock Runtime connector to call Converse and InvokeModel, count tokens and apply guardrails from MQTT with a Bedrock API key

Technical Preview

## Overview

Client-mode REST API connectors for Amazon Bedrock: triage alarms and summarize shift logs with the Converse API, create Titan embeddings with InvokeModel, count tokens, screen text with a guardrail, and list foundation models and inference profiles, all with a Bedrock API key.

This is one of the templates in the Amazon Bedrock REST API app (`amazon-bedrock`). Deploy it alongside the other connectors of that app when they depend on each other (for example a token connector plus an API connector).

## Auth

Amazon Bedrock API key as Authorization: Bearer \{value.json.api\_key} (long-term ABSK..., short-term bedrock-api-key-...). Hub secret suggested AWS\_BEARER\_TOKEN\_BEDROCK + GET SECRET. Alternative: AWS SigV4 (service bedrock) computed outside the broker, documented in comments. Never commit keys.

Auth headers used by the template: `Authorization: Bearer {value.json.api_key}`.

## Template parameters

| Placeholder | Type | Description | Required |
| - | - | - | - |
| `RouteName` | string | Name of the Amazon Bedrock Runtime connector | no |
| `BaseUrl` | string | Amazon Bedrock Runtime base URL without trailing slash (e.g. [https://bedrock-runtime.eu-west-1.amazonaws.com](https://bedrock-runtime.eu-west-1.amazonaws.com)) | yes |

`BASE_ADDRESS` default: `https://bedrock-runtime.eu-west-1.amazonaws.com`.

## Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `Converse` | POST | `/model/{value.json.model_id}/converse` | `ai/bedrock/converse/send` | `ai/bedrock/converse/send/response` | `api_key`, `body`, `model_id` |
| `InvokeModel` | POST | `/model/{value.json.model_id}/invoke` | `ai/bedrock/model/invoke` | `ai/bedrock/model/invoke/response` | `api_key`, `body`, `model_id` |
| `CountTokens` | POST | `/model/{value.json.model_id}/count-tokens` | `ai/bedrock/tokens/count` | `ai/bedrock/tokens/count/response` | `api_key`, `body`, `model_id` |
| `ApplyGuardrail` | POST | `/guardrail/{value.json.guardrail_id}/version/{value.json.guardrail_version}/apply` | `ai/bedrock/guardrail/apply` | `ai/bedrock/guardrail/apply/response` | `api_key`, `body`, `guardrail_id`, `guardrail_version` |

## Deploy

Get the template card (JSON with `template` and `metadata`) from the broker, then deploy the connector:

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
mosquitto_pub -t '$SYS/Coreflux/Command' -m "-connectorCode AMAZON_BEDROCK_RUNTIME"
```

The deployable connector from the REST API app, with `BASE_ADDRESS` already filled in:

```lot theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
DEFINE CONNECTOR AmazonBedrockRuntime WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://bedrock-runtime.eu-west-1.amazonaws.com"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '120'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT Converse
        WITH SOURCE_TOPIC "ai/bedrock/converse/send"
        WITH DESTINATION_TOPIC "ai/bedrock/converse/send/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/model/{value.json.model_id}/converse"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.api_key}"
        WITH BODY "{value.json.body}"
    ADD EVENT InvokeModel
        WITH SOURCE_TOPIC "ai/bedrock/model/invoke"
        WITH DESTINATION_TOPIC "ai/bedrock/model/invoke/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/model/{value.json.model_id}/invoke"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.api_key}"
        WITH BODY "{value.json.body}"
    ADD EVENT CountTokens
        WITH SOURCE_TOPIC "ai/bedrock/tokens/count"
        WITH DESTINATION_TOPIC "ai/bedrock/tokens/count/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/model/{value.json.model_id}/count-tokens"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.api_key}"
        WITH BODY "{value.json.body}"
    ADD EVENT ApplyGuardrail
        WITH SOURCE_TOPIC "ai/bedrock/guardrail/apply"
        WITH DESTINATION_TOPIC "ai/bedrock/guardrail/apply/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/guardrail/{value.json.guardrail_id}/version/{value.json.guardrail_version}/apply"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.api_key}"
        WITH BODY "{value.json.body}"
```

Deploy it with `-addConnector` (do not include `ADD METADATA`).

## Usage example

Call `Converse` by publishing a JSON payload to its request topic, and read the reply on the response topic:

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
mosquitto_sub -t 'ai/bedrock/converse/send/response' &
mosquitto_pub -t 'ai/bedrock/converse/send' -m '{"api_key": "<api_key>", "body": {}, "model_id": "<model_id>"}'
```

## Related

* [REST API Connectors](https://docs.coreflux.org/latest/connectors/rest-api/overview)
* [REST API Apps catalog](https://docs.coreflux.org/latest/connectors/rest-api-apps)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.