Reference keel-llm-protocol adapter for Anthropic's Messages API — the divergent-provider grounding for the standard.
Project description
keel-llm-adapter-anthropic
A reference
keel-llm-protocoladapter for Anthropic's Messages API (Claude).
This package is the divergent-provider grounding for the protocol standard. Where keel-llm-adapter-openai proves the standard against the OpenAI-compatible family, this proves it against an API that diverges on purpose — and the protocol absorbs every difference in the adapter, without changing the standard. That is the standard generalizing.
Install
pip install keel-llm-adapter-anthropic # pulls in keel-llm-protocol + httpx
Use
from keel_llm_adapter_anthropic import AnthropicAdapter
from keel_llm_protocol import system, user
adapter = AnthropicAdapter(model="claude-sonnet-4-5", api_key="...", provider="anthropic")
resp = await adapter.generate([system("Be terse."), user("What is a circuit breaker?")])
print(resp.text, resp.usage.total_tokens, resp.finish_reason)
Same keel-llm-protocol types as every other adapter — swap AnthropicAdapter for OpenAIAdapter and your code is unchanged. It implements ModelAdapter, StreamingModelAdapter, and ToolCallingModelAdapter.
How Anthropic diverges — and where it's handled
Every divergence below is absorbed inside the adapter; the protocol's types are untouched:
| Anthropic divergence | Protocol stays the same because… |
|---|---|
System prompt is a top-level system field, not a message |
the adapter lifts Message(role="system") into the system param |
Only user / assistant roles exist |
tool messages → tool_result content blocks; assistant tool_calls → tool_use blocks |
Tool input arrives as a parsed dict |
the adapter json.dumps it into ToolCall.arguments (a JSON string) |
Tools use input_schema + tool_choice: {type: auto|any|tool} |
the adapter maps ToolSpec / tool_choice accordingly |
max_tokens is required |
the adapter supplies default_max_tokens (4096) when unset |
Distinct SSE events (message_start / content_block_delta / message_delta) |
the adapter maps them onto StreamChunk |
529 overloaded status |
mapped to retryable TransientError |
{"type":"error","error":{...}} envelope + stop_reason values |
mapped to the standard error taxonomy + FinishReason |
Known limitation
Anthropic has no native response_format parameter — structured output is done via tools or prompt instructions. This adapter therefore treats ResponseFormat as a best-effort hint and does not enforce it. (A finding worth keeping: in the standard, response_format is a request, not a guarantee — provider support varies.)
Status
0.1.1 — 0.x while the API stabilizes through year one (breaking changes possible at minor bumps, documented in the CHANGELOG; pin exact versions).
The Keel toolkit
Composable, vendor-neutral LLM reliability libraries on PyPI:
keel-llm-reliability · keel-llm-protocol · keel-llm-adapter-openai · keel-llm-adapter-anthropic · keel-llm-adapter-google · keel-circuit-breaker
MIT licensed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file keel_llm_adapter_anthropic-0.1.1.tar.gz.
File metadata
- Download URL: keel_llm_adapter_anthropic-0.1.1.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
279f1fed54ce403884cffef4558cd20e959d5a9c9516e62b676b77b6d463ed53
|
|
| MD5 |
dd204e60cfef92e22e9f98cebf495e47
|
|
| BLAKE2b-256 |
cfcb453b76e0fa68f4880990d6fa9ccc6daaaa4526e92db35c4fa4ba3f461178
|
Provenance
The following attestation bundles were made for keel_llm_adapter_anthropic-0.1.1.tar.gz:
Publisher:
publish-py.yml on keelplatform/keel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keel_llm_adapter_anthropic-0.1.1.tar.gz -
Subject digest:
279f1fed54ce403884cffef4558cd20e959d5a9c9516e62b676b77b6d463ed53 - Sigstore transparency entry: 1609094657
- Sigstore integration time:
-
Permalink:
keelplatform/keel@062ed6357062a6b9029f819cd30b5c17c9db6119 -
Branch / Tag:
refs/tags/py-llm-adapter-anthropic-v0.1.1 - Owner: https://github.com/keelplatform
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-py.yml@062ed6357062a6b9029f819cd30b5c17c9db6119 -
Trigger Event:
push
-
Statement type:
File details
Details for the file keel_llm_adapter_anthropic-0.1.1-py3-none-any.whl.
File metadata
- Download URL: keel_llm_adapter_anthropic-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6b614d1c52de4f36c39ca3317d64e1fc6981f07f938c95aa5a37a3c92c9f509
|
|
| MD5 |
be07be3cc37d64f33a805f041d674f8c
|
|
| BLAKE2b-256 |
7f0109d467ab8a6e640bfec66a9c0f23b7d842f7fbb92ec40c73afe29e940b7d
|
Provenance
The following attestation bundles were made for keel_llm_adapter_anthropic-0.1.1-py3-none-any.whl:
Publisher:
publish-py.yml on keelplatform/keel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keel_llm_adapter_anthropic-0.1.1-py3-none-any.whl -
Subject digest:
a6b614d1c52de4f36c39ca3317d64e1fc6981f07f938c95aa5a37a3c92c9f509 - Sigstore transparency entry: 1609095210
- Sigstore integration time:
-
Permalink:
keelplatform/keel@062ed6357062a6b9029f819cd30b5c17c9db6119 -
Branch / Tag:
refs/tags/py-llm-adapter-anthropic-v0.1.1 - Owner: https://github.com/keelplatform
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-py.yml@062ed6357062a6b9029f819cd30b5c17c9db6119 -
Trigger Event:
push
-
Statement type: