SOLWYN
Providers

Anthropic

Use Solwyn with Anthropic — sync and async examples, cache normalization, model support

import os
from anthropic import Anthropic
from solwyn import Solwyn

client = Solwyn(
    Anthropic(),
    api_key=os.environ["SOLWYN_API_KEY"],
)

response = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Explain how a CPU works in two sentences."}],
)

print(response.content[0].text)
client.close()

Sync usage

Pass an anthropic.Anthropic client to Solwyn(). Calls use client.messages.create(), exactly like the standard Anthropic SDK:

import os
from anthropic import Anthropic
from solwyn import Solwyn

with Solwyn(
    Anthropic(),
    api_key=os.environ["SOLWYN_API_KEY"],
) as client:
    response = client.messages.create(
        model="claude-sonnet-4-5",
        max_tokens=1024,
        messages=[
            {"role": "user", "content": "Explain how a CPU works in two sentences."},
        ],
        system="You are a helpful assistant.",
    )
    print(response.content[0].text)

Async usage

Pass an anthropic.AsyncAnthropic client to AsyncSolwyn():

import asyncio
import os
from anthropic import AsyncAnthropic
from solwyn import AsyncSolwyn

async def main():
    async with AsyncSolwyn(
        AsyncAnthropic(),
        api_key=os.environ["SOLWYN_API_KEY"],
    ) as client:
        response = await client.messages.create(
            model="claude-sonnet-4-5",
            max_tokens=1024,
            messages=[
                {"role": "user", "content": "Explain how a CPU works in two sentences."},
            ],
            system="You are a helpful assistant.",
        )
        print(response.content[0].text)

asyncio.run(main())

Supported models

The SDK recognizes Anthropic models by the claude-* prefix:

PrefixExamples
claude-*claude-sonnet-4-5, claude-opus-4-5, claude-haiku-4-5

Anthropic is priced for text only — chat through messages.create. A media surface requested from a wrapped Anthropic client (embeddings, for instance) fails loud with UnsupportedSurfaceError rather than running untracked. See the provider × modality matrix.

Cache normalization

Anthropic reports prompt cache tokens as separate additive fields -- the base input_tokens does not include cache tokens. Solwyn normalizes these into a single input_tokens total:

normalized input_tokens = base input_tokens
                        + cache_read_input_tokens
                        + cache_creation_input_tokens
Normalized fieldAnthropic API source
input_tokensusage.input_tokens + usage.cache_read_input_tokens + usage.cache_creation_input_tokens
output_tokensusage.output_tokens
cached_input_tokensusage.cache_read_input_tokens
cache_creation_5m_tokensusage.cache_creation.ephemeral_5m_input_tokens
cache_creation_1h_tokensusage.cache_creation.ephemeral_1h_input_tokens

Cache-creation TTL split

Anthropic prices cache writes differently by time-to-live: the 5-minute TTL is billed at 1.25× the base input rate, the 1-hour TTL at 2×. Solwyn captures the two separately so the Cloud API can price each correctly:

  • cache_creation_5m_tokens — written with 5-minute TTL (1.25× rate)
  • cache_creation_1h_tokens — written with 1-hour TTL (2× rate)

Older or non-beta responses expose only an aggregate usage.cache_creation_input_tokens without the per-TTL cache_creation sub-object. When only the aggregate is present, Solwyn attributes it to cache_creation_5m_tokens. All cache fields may be absent on older API responses and default to 0.

Reasoning tokens limitation

Anthropic folds extended thinking tokens into output_tokens and does not report them as a separate field. As a result, reasoning_tokens is always 0 for Anthropic responses. This is a known limitation of the Anthropic API, not the Solwyn SDK.

The Solwyn Cloud API accounts for this when computing costs -- extended thinking output tokens are priced correctly using the total output_tokens count.

Passthrough attributes

Any attribute not intercepted by Solwyn is passed through to the underlying anthropic.Anthropic client. You can still access any Anthropic API method directly.

On this page