Skip to main content

Anthropic Claude transport for Axio

Project description

axio-transport-anthropic

PyPI Python License: MIT

Anthropic Claude transport for axio.

Streams Claude responses over the Anthropic Messages API using aiohttp and SSE parsing. Supports prompt caching, extended thinking, and automatic retry on rate-limit and overload errors.

Features

  • All Claude models — Opus, Sonnet, Haiku; configurable via ANTHROPIC_MODELS
  • Prompt cachingcache_control: ephemeral applied automatically to the system prompt and the last tool definition
  • Extended thinkingReasoningDelta events emitted for thinking blocks
  • Retry logic — automatic backoff on 429 and all 5xx errors; honours Retry-After header
  • TUI integration — settings screen for API key and model selection

Installation

pip install axio-transport-anthropic

With the TUI settings screen:

pip install "axio-transport-anthropic[tui]"

Or as part of the full TUI bundle:

pip install "axio-tui[anthropic]"

Usage

import aiohttp
from axio.agent import Agent
from axio.context import MemoryContextStore
from axio_transport_anthropic import AnthropicTransport, ANTHROPIC_MODELS

async def main() -> None:
    async with aiohttp.ClientSession() as session:
        transport = AnthropicTransport(
            api_key="sk-ant-...",
            model=ANTHROPIC_MODELS["claude-sonnet-4-6"],
            session=session,
        )
        agent = Agent(system="You are helpful.", tools=[], transport=transport)
        ctx = MemoryContextStore()
        print(await agent.run("Hello!", ctx))

Set the API key via environment variable instead of passing it directly:

export ANTHROPIC_API_KEY="sk-ant-..."

Override the base URL (e.g. for a proxy or private endpoint):

export ANTHROPIC_BASE_URL="https://your-proxy.example.com/v1"

Models

Model ID Context Max output Notes
claude-opus-4-6 1 M 128 k Most capable
claude-sonnet-4-6 1 M 64 k Balanced (default)
claude-haiku-4-5-20251001 200 k 64 k Fastest / cheapest
claude-opus-4-5 200 k 64 k
claude-sonnet-4-5 200 k 64 k

Configuration

Parameter Default Description
api_key "" Anthropic API key
model claude-sonnet-4-6 Active model
base_url https://api.anthropic.com/v1 API base URL
max_retries 10 Max retry attempts on 429 and 5xx errors
retry_base_delay 5.0 Base delay (seconds) for exponential backoff

fetch_models()

await transport.fetch_models() resets transport.models to the built-in ANTHROPIC_MODELS registry. It does not make a network request. Override model directly to switch the active model.

Serialisation

AnthropicTransport supports JSON round-trip for storing and restoring configuration:

# Serialise
data = transport.to_dict()   # -> {"name": ..., "base_url": ..., "api_key": ..., "models": [...]}

# Restore
transport = AnthropicTransport.from_dict(data, session=session)

from_dict falls back to ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL environment variables if the stored values are empty.

Part of the axio ecosystem

axio · axio-tui · axio-transport-openai · axio-transport-codex

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

axio_transport_anthropic-0.8.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

axio_transport_anthropic-0.8.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file axio_transport_anthropic-0.8.0.tar.gz.

File metadata

  • Download URL: axio_transport_anthropic-0.8.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for axio_transport_anthropic-0.8.0.tar.gz
Algorithm Hash digest
SHA256 f3f2ef5f33e17ec8a1a59675d2819d2a21cd180b54f121da3ac2c81afa16c9b6
MD5 034b73cfa8ce1bbd0ba77e5336a4ee1d
BLAKE2b-256 448d1a2c8c77e5df31049d56c43af83926a25f607e2ba4740ca483e0e98018a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for axio_transport_anthropic-0.8.0.tar.gz:

Publisher: publish.yml on mosquito/axio-agent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file axio_transport_anthropic-0.8.0-py3-none-any.whl.

File metadata

File hashes

Hashes for axio_transport_anthropic-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6975a754dfa7c3160efa09148e3211eaea378c5b34cb7fadb1d02f4597d1fbe3
MD5 7e628c055507900c5b7f4a64326b7b27
BLAKE2b-256 b282b39426285e3792dd40450b64cac2534af154a3db1605cc668401b6861d1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for axio_transport_anthropic-0.8.0-py3-none-any.whl:

Publisher: publish.yml on mosquito/axio-agent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page