Skip to main content

keel-llm-adapter-anthropic

A reference keel-llm-protocol adapter 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.

Is this for you?

Adopt when — you're consuming via keel-llm-protocol / keel-llm-reliability and want Claude calls mapped to the typed taxonomy (with Anthropic's divergences absorbed at the adapter layer). Skip when — you're calling Anthropic directly in a simple app — the official anthropic SDK has a wider surface (batches, files, prompt caching…); this adapter covers chat / streaming / tools.

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.2 — 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.

Metadata

Release files for keel-llm-adapter-anthropic 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for keel-llm-adapter-anthropic 0.1.2
File Size Uploaded Provenance
keel_llm_adapter_anthropic-0.1.2.tar.gz 10.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for keel-llm-adapter-anthropic 0.1.2
File Interpreter ABI Platform
keel_llm_adapter_anthropic-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 17.7 kB

Release files / keel_llm_adapter_anthropic-0.1.2.tar.gz

Download URL keel_llm_adapter_anthropic-0.1.2.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
20f5fa5dcf04c903aa54216194299bbc106fea286b47fd794422c7cfb868c27d
BLAKE2b-256 checksum
How to use checksums
f8908ed210e50feefe6db4f6cca126a9530ff668152f3191a1eab42c27cda2a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 23, 2026.

Transparency log

Release files / keel_llm_adapter_anthropic-0.1.2-py3-none-any.whl

Download URL keel_llm_adapter_anthropic-0.1.2-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3197c4728841f78fcb6b4c1ff9129f96d38e5981b14c2d5c51ca66c984805a1c
BLAKE2b-256 checksum
How to use checksums
69793bf95c0668edc7f12ac107ff637b3465d562c5a022e035da52a3bbc0e75d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 23, 2026.

Transparency log

Security for keel-llm-adapter-anthropic 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for keel_llm_adapter_anthropic-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page