# Anthropic Messages

Connect the Messages protocol through Kastra and handle policy outcomes.

Updated: 2026-09-22

Canonical: https://docs.kastra.ai/proxy/anthropic

## Prepare the body

Set `KASTRA_API_KEY` and `ANTHROPIC_API_KEY` on your server. Create `request.json`, replacing the model with one available to your provider account:

```json
{
  "model": "REPLACE_WITH_YOUR_ANTHROPIC_MODEL",
  "max_tokens": 128,
  "messages": [{"role": "user", "content": "Reply with a short greeting."}],
  "stream": false
}
```

```sh
curl -i https://api.kastra.ai/v1/messages \
  -H "Authorization: Bearer $KASTRA_API_KEY" \
  -H "X-Upstream-API-Key: $ANTHROPIC_API_KEY" \
  -H 'Content-Type: application/json' \
  -H 'X-Jurisdiction: US' \
  --data-binary @request.json
```

Kastra authenticates the caller with its own key and sends the upstream provider credential through the provider adapter. The provider API version is configured by that adapter; do not assume every incoming provider header is forwarded unchanged.

## Test policy behavior

Confirm a normal response, then exercise a narrow test denial. If your application executes `tool_use` output, test the post-inference policy before connecting a real side-effecting tool. Review policy headers and structured errors instead of relying only on HTTP success.

## Streaming and approvals

Enable streaming only after your client handles the non-streaming outcomes. The adapter filters supported output and may emit a structured stream error. [Streaming and output](https://docs.kastra.ai/proxy/streaming) explains the boundary; [proxy approvals](https://docs.kastra.ai/proxy/approvals) explains waiting and resubmission.

Traffic sent directly to Anthropic and provider-side tool execution outside a governed path remain outside Kastra's control.
