> ## 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.

# Anthropic

> Client-mode REST API connector for Anthropic Claude Messages and Message Batches — MQTT into shift-log summarization and nightly batches

Technical Preview

## Overview

A client-mode connector for a **curated** slice of the [Anthropic Claude API](https://docs.anthropic.com/en/api/getting-started) focused on IIoT / edge ops text into Claude:

| Catalog connector event | Entity / path | Notes |
| - | - | - |
| POST messages | `POST /v1/messages` | Messages API — summarize shift log; extract fields with tools |
| POST messages/batches | `POST /v1/messages/batches` | Message Batches — nightly / async batch (up to 24h) |
| (supporting) GET models | `GET /v1/models` | List models (auth smoke) |
| (supporting) GET model | `GET /v1/models/{model}` | Retrieve one model |

Default `BASE_ADDRESS` is `https://api.anthropic.com` (no trailing slash). Topics use `ai/anthropic/<object>/<verb>`.

See the base guide: [REST API Connectors](/latest/lot-language/routes/rest-api-routes).

> [!NOTE]
>
> **Auth:** `x-api-key: &lt;Anthropic API key&gt;` **and** `anthropic-version: 2023-06-01` on every request. Prefer Hub secrets (`GET SECRET "ANTHROPIC_API_KEY"`) mapped into MQTT `api_token`. Never commit real `sk-ant-...` keys.

> [!NOTE]
>
> Factory live smoke is **blocked** until an Anthropic API key is supplied. Point secrets / MQTT JSON at your project before production use.

## Basic Syntax

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
# Coreflux REST_API template — Anthropic
# Auth: x-api-key {value.json.api_token} + anthropic-version 2023-06-01
# BASE_ADDRESS: https://api.anthropic.com

DEFINE ROUTE AnthropicRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://api.anthropic.com"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT PostMessages
        WITH SOURCE_TOPIC "ai/anthropic/messages/post"
        WITH DESTINATION_TOPIC "ai/anthropic/messages/post/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/v1/messages"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "x-api-key" "{value.json.api_token}"
            ADD "anthropic-version" "2023-06-01"
        WITH BODY "{payload}"
    ADD EVENT PostMessagesBatches
        WITH SOURCE_TOPIC "ai/anthropic/messages/batches/post"
        WITH DESTINATION_TOPIC "ai/anthropic/messages/batches/post/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/v1/messages/batches"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "x-api-key" "{value.json.api_token}"
            ADD "anthropic-version" "2023-06-01"
        WITH BODY "{payload}"
```

Full deployable file: `AnthropicRestApi.lot` in the factory package (no `ADD METADATA`).

## Topics

| Event | Source topic | Destination topic |
| - | - | - |
| PostMessages | `ai/anthropic/messages/post` | `…/response` |
| PostMessagesBatches | `ai/anthropic/messages/batches/post` | `…/response` |
| GetModels | `ai/anthropic/models/list` | `…/response` |
| GetModel | `ai/anthropic/models/get` | `…/response` |

## Configuration

1. Set `BASE_ADDRESS` to `https://api.anthropic.com`.
2. Store an Anthropic API key in Hub secrets (`ANTHROPIC_API_KEY`); map into MQTT `api_token`.
3. Always send `anthropic-version: 2023-06-01` (already on every event in the template).
4. For shift-log summarization / tool use: publish to `ai/anthropic/messages/post` with a Messages body (`model`, `max_tokens`, `messages`, optional `tools`).
5. For nightly batches: publish to `ai/anthropic/messages/batches/post` with a `requests` array of `{custom_id, params}`.
6. Use `GetModels` as a cheap auth smoke before production workloads.

## References

* [Anthropic API overview](https://docs.anthropic.com/en/api/getting-started)
* [Messages](https://docs.anthropic.com/en/api/messages)
* [Creating Message Batches](https://docs.anthropic.com/en/api/creating-message-batches)
* [Models](https://docs.anthropic.com/en/api/models)


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