axio-transport-anthropic¶
Anthropic Claude transport for axio.
Streams Claude responses over the Anthropic Messages API using aiohttp and
SSE parsing. Supports direct API, Vertex AI, prompt caching, extended thinking,
and automatic retry on rate-limit and overload errors.
Features¶
All Claude models — Opus, Sonnet, Haiku; configurable via
ANTHROPIC_MODELSVertex AI — use Claude via Google Cloud with ADC authentication
Prompt caching —
cache_control: ephemeralapplied automatically to the system prompt and the last tool definitionExtended thinking —
ReasoningDeltaevents emitted for thinking blocksRetry logic — automatic backoff on 429 / 529; honours
Retry-AfterheaderTUI 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]"
With Vertex AI support:
pip install "axio-transport-anthropic[vertexai]"
Usage¶
import asyncio
import aiohttp
from axio 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))
asyncio.run(main())
Set the API key via environment variable instead of passing it directly:
export ANTHROPIC_API_KEY="sk-ant-..."
Vertex AI¶
transport = AnthropicTransport(
vertexai=True,
project="my-gcp-project",
location="us-east5",
session=session,
)
# Uses Application Default Credentials (gcloud auth application-default login)
Models¶
Model ID |
Context |
Max output |
Notes |
|---|---|---|---|
|
1 M |
128 k |
Most capable |
|
1 M |
64 k |
Balanced (default) |
|
200 k |
64 k |
Fastest / cheapest |
|
200 k |
64 k |
— |
|
200 k |
64 k |
— |
Configuration¶
Parameter |
Default |
Description |
|---|---|---|
|
|
Anthropic API key |
|
|
Active model |
|
|
API base URL |
|
|
Use Vertex AI backend |
|
|
GCP project ID (Vertex AI) |
|
|
GCP region, e.g. |
|
|
Max retry attempts on 429/529 |
|
|
Base delay (seconds) for exponential backoff |
License¶
MIT
Vertex entry point¶
Install axio-transport-anthropic[vertexai] to use Claude through Vertex without
the Google transport package. Select --transport anthropic-vertex in REPL, or
Anthropic Vertex AI in TUI. Set GOOGLE_CLOUD_PROJECT and optionally
GOOGLE_CLOUD_LOCATION, or enter project and location in TUI settings.
axio_transport_anthropic.VertexAITransport also accepts these fields directly.
This entry point requires explicit selection and uses Google ADC.
When migrating from Google Vertex, remove anthropic/ from the model ID and
copy project and location. Existing Google settings remain unchanged.